发布于 2018-07-20 17:11:49
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]
在网上试试! (生成大小相同的虚拟文件)
我们只需查看文件的大小并将其转换为两个查找表中的索引。
第一部分:
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
发布于 2018-07-20 17:31:52
->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]}
通过蛮力发现的字节偏移--例如,以文件模块化7的699字节为例,给出了第一个查找表的索引。
https://codegolf.stackexchange.com/questions/168947
复制相似问题