(原张贴(并删除)@Tlink,最有可能是受这个StackOverflow问题的启发。
因为很遗憾它被删除了,因为它似乎是一个很好的挑战,所以我想我应该用适当的格式和规则重新发布它。(我试着联系@Tlink,并得到他/她的许可,但是(S)他不再回复了,这就是为什么我现在决定自己发。)
输入:六位数。
输出:24小时格式的第一个或最后一个有效时间(00:00:00到23:59:59)。(您可以选择自己是输出第一个有效时间还是最后一个有效时间。)
当输入为1,8,3,2,6,4时,可以创建以下时间:
12:36:48 12:38:46 12:46:38 12:48:36
13:26:48 13:28:46 13:46:28 13:48:26
14:26:38 14:28:36 14:36:28 14:38:26
16:23:48 16:24:38 16:28:34 16:28:43
16:32:48 16:34:28 16:38:24 16:38:42
16:42:38 16:43:28 16:48:23 16:48:32
18:23:46 18:24:36 18:26:34 18:26:43
18:32:46 18:34:26 18:36:24 18:36:42
18:42:36 18:43:26 18:46:23 18:46:32
21:36:48 21:38:46 21:46:38 21:48:36
23:16:48 23:48:16因此,在本例中,我们将输出12:36:48或23:48:16,分别是第一个/最后一个。
HH:mm:ss/HHmmss/HH mm ss;的字符串--用新行分隔符打印的每一个数字;等等。2,5,5,5,5,5)创建有效时间,请以任何您想要的方式清楚地说明这一点。可以返回null/false;"Not possible";带有错误的崩溃;等等(不能输出无效的时间,比如55:55:52,或者其他有效的时间,比如00:00:00)。请说明它如何处理无法为其创建有效时间的输入。24为小时(即24:00:00)或60为分钟/秒(即00:60:60)无效。范围为[00-23] (小时),[00-59] (分钟)和秒(秒)。Input: Earliest output: Latest output:
1,2,3,4,6,8 12:36:48 23:48:16
2,5,5,5,5,5 None possible None possible
0,0,0,1,1,1 00:01:11 11:10:00
1,1,2,2,3,3 11:22:33 23:32:11
9,9,9,9,9,9 None possible None possible
2,3,5,5,9,9 23:59:59 23:59:59
1,2,3,4,5,6 12:34:56 23:56:41
0,0,0,0,0,0 00:00:00 00:00:00
1,5,5,8,8,8 18:58:58 18:58:58
1,5,5,5,8,8 15:58:58 18:58:55
1,1,1,8,8,8 18:18:18 18:18:18发布于 2018-05-09 08:09:29
将输入作为数字字符串并输出第一个有效时间;如果没有有效时间,则无限循环。
á
@øXr':}a@ÐX ¤¯8警告:非常慢--在第二个
X之后添加*1000以加快速度。不要忘记,无效的输入会创建无限循环,并可能导致浏览器崩溃。
:Implicit input of string U
á :Get all permutations of U
\n :Reassign that array to U
}a :Loop until true and then return the argument that was passed
@ :By default that argument is an integer X which increments on each loop so first we'll pass X through a function
ÐX : new Date(X)
¤ : Get the time
¯8 : Slice to the 8th character to get rid of the timezone info
@ :The function that tests for truthiness
Xr': : Remove all colons in X
ø : Does U contain the resulting string?发布于 2018-05-09 10:57:03
https://codegolf.stackexchange.com/questions/164439
复制相似问题