月相を教えてください!


10

チャレンジ

月の画像を入力として、月の位相を出力します。

月の満ち欠け

プログラムには、これらの画像のいずれかがpng形式で提供され、指定されたとおりにフェーズを出力する必要があります。

new moon

16進ダンプ

waxing crescent

16進ダンプ

first quarter

16進ダンプ

waxing gibbous

16進ダンプ

full moon

16進ダンプ

waning gibbous

16進ダンプ

third quarter

16進ダンプ

waning crescent

16進ダンプ

入力

入力は、240 px x 240 pxのpngファイルへのパスであり、上の画像の1つになります。

画像バイトは同じであることが保証されています。

勝利

最短コードの勝利


1
ボーナスとして、このクールのGIFチェックアウト:upload.wikimedia.org/wikipedia/commons/b/ba/...を
ベータ崩壊

回答:


9

Node.js、145バイト

p=>'third/waning/first/full/waxing/new'.split`/`[(s=require('fs').statSync(p).size)%418%6]+' '+'quarter/crescent/gibbous/moon'.split`/`[s%12%9%4]

オンラインでお試しください!(同じサイズのダミーファイルを生成します)

どうやって?

ファイルのサイズを確認し、2つのルックアップテーブルのインデックスに変換するだけです。

最初の部分:

 phase | file size | mod 418 | mod 6 | mapped to
-------+-----------+---------+-------+-----------
   0   |    3451   |    107  |    5  | new
   1   |    6430   |    160  |    4  | waxing
   2   |    5144   |    128  |    2  | first
   3   |    7070   |    382  |    4  | waxing
   4   |    5283   |    267  |    3  | full
   5   |    7067   |    379  |    1  | waning
   6   |    4976   |    378  |    0  | third
   7   |    6337   |     67  |    1  | waning

後編:

 phase | file size | mod 12 |  mod 9 |  mod 4 | mapped to
-------+-----------+--------+--------+--------+-----------
   0   |    3451   |     7  |     7  |    3   | moon
   1   |    6430   |    10  |     1  |    1   | crescent
   2   |    5144   |     8  |     8  |    0   | quarter
   3   |    7070   |     2  |     2  |    2   | gibbous
   4   |    5283   |     3  |     3  |    3   | moon
   5   |    7067   |    11  |     2  |    2   | gibbous
   6   |    4976   |     8  |     8  |    0   | quarter
   7   |    6337   |     1  |     1  |    1   | crescent

7

パイソン2223の 222バイト

OMのおかげで-1バイト

lambda p:'new moonzzfull moonzzfirst quarterzzwaxing crescentzzwaning gibbouszzwaxing gibbouszthird quarterzwaning crescent'.split('z')[sum(n*Image.open(p).getpixel((n*48,99))[2]for n in[1,2,3,4])%13]
from PIL import Image

getpixel((x,y))-RGBAピクセルx,y
getpixel((n*48,99))[2]for n in[1,2,3,4]を返しn*48 ... for n in 1,2,3,4ます
n*getpixel(...)- 太陽光線がカバーする可能性のある4点である中央の線の青いチャネルを返します
sum(...)%13- 各列に異なる値を生成します-これらの値が加算%13され、一意を取得するために使用されます各フェーズの値。フェーズリスト
のインデックスとして使用されます。ピクセルはおおよそ赤い円の内側にあります。
ピクセルが強調表示された月の画像


5

Ruby、131バイト

->f{f=open(f,'rb').read;%w[first third waxing new full waning][f[699].ord%7]+' '+%w[x moon gibbous quarter crescent][f[998].ord%5]}

ブルートフォースによって検出されたバイトオフセット-たとえば、ファイルの699番目のバイトを7を法として取ると、最初のルックアップテーブルにインデックスが付けられます。



1

PHP(> = 5.4)、199 197バイト

(さらにゴルフで2バイト)

<?$s=strlen(file_get_contents($argv[1])).'';echo strtr([waning_crescent,waning_gibbous,new_moon,0,waxing_crescent,waxing_gibbous,full_moon,first_quarter,third_quarter][($s[0]+$s[3])%11-2],'_',' ');

実行するには:

php -d error_reporting=0 -d short_open_tag=1 <filename> <image_path>

例:

php -d error_reporting=0 -d short_open_tag=1 lunar_phase.php https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Moon_phase_6.svg/240px-Moon_phase_6.svg.png

ノート:

  • この-d error_reporting=0オプションは、通知/警告を出力しないために使用されます。
  • -d short_open_tag=1短いタグを許可するために必要とされます。
  • https上記の例のようなURL を使用している場合は、OpenSSLも有効にする必要があります。

どうやって?

次の式でファイルサイズ(バイト)を取得し、その固有の数値を作成します。

((<first_bytes_digit> + <fourth_bytes_digit>) % 11) - 2

この数式は、0から8までの数を生成し、3だけを欠落させます。

┌─────────────────┬───────┬─────────┬─────┬────────────────────────┐
│      Phase      │ Bytes │ 1st+4th │ %11 │ -2 (position in array) │
├─────────────────┼───────┼─────────┼─────┼────────────────────────┤
│ new moon        │  3451 │ 3+1=4   │   4 │                      2 │
│ waxing crescent │  6430 │ 6+0=6   │   6 │                      4 │
│ first quarter   │  5144 │ 5+4=9   │   9 │                      7 │
│ waxing gibbous  │  7070 │ 7+0=7   │   7 │                      5 │
│ full moon       │  5283 │ 5+3=8   │   8 │                      6 │
│ waning gibbous  │  7067 │ 7+7=14  │   3 │                      1 │
│ third quarter   │  4976 │ 4+6=10  │  10 │                      8 │
│ waning crescent │  6337 │ 6+7=13  │   2 │                      0 │
└─────────────────┴───────┴─────────┴─────┴────────────────────────┘

以前のアプローチ:

PHP(> = 5.4)、251バイト

<?foreach([4,8,16,20]as$w){$a+=imagecolorat(imagecreatefrompng($argv[1]),$w*10,120)>1e7;$a&&$w<5?$b=-2:0;}$x=explode('_','full moon_waning gibbous_third quarter_waning crescent_new moon_waxing crescent_first quarter_waxing gibbous');echo$x[$a*++$b+4];

実行するには:

php -d error_reporting=0 -d short_open_tag=1 <filename> <image_path>

例:

php -d error_reporting=0 -d short_open_tag=1 lunar_phase.php https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Moon_phase_6.svg/240px-Moon_phase_6.svg.png

ノート:

  • この-d error_reporting=0オプションは、通知/警告を出力しないために使用されます。
  • -d short_open_tag=1短いタグを許可するために必要とされます。
  • PHPにはGDが必要であり、有効にする必要があります。
  • https上記の例のようなURL を使用している場合は、OpenSSLも有効にする必要があります。

どうやって?

画像における4つの画素の色をチェックし40,12080,120160,120および200,120それらの色からムーン位相を決定します。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.