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,120
, 80,120
, 160,120
และ200,120
และตัดสินใจในระยะดวงจันทร์จากสีเหล่านั้น