(来自codingame.com的多人游戏(代码冲突)的挑战)
挑战
查找以下序列的第n项:1, 1, 2, 1, 2, 3, 1, 2, 3, 4...,或者更明显的是{1}, {1,2}, {1,2,3}, {1,2,3,4}...
序列由连接范围从1到x组成,从1开始,一直到无穷远。
输入和输出可以是任何格式,只要它是可区分的。输入可以从任何适当的来源: STDIN,文件等.
输入可以是0-或1-索引,所选的索引必须在文章中提及。
您必须至少处理255个包含的结果(这意味着0索引的最大输入为32640)。如果你的语言支持的话,任何事情都必须处理。
这是code-golf,所以最短的字节计数获胜!
0 -> 1
1 -> 1
5 -> 3
10 -> 1
59 -> 5
100 -> 10
1001 -> 12发布于 2017-01-22 14:55:50
发布于 2017-01-22 15:29:29
RRF³ị解释:
(Assume N = 4 for the examples)
R Generate a list of 1 to N [1, 2, 3, 4]
R Generate new lists for each item on the previous list, with that item as N
[[1], [1,2], ...]
F Flatten that list [1, 1, 2, 1, 2, 3 ...]
³ị Use the input number (³) as index (ị) on the list.
This is one-based: [1, 1, 2, 1, 2, 3 ...]
^https://codegolf.stackexchange.com/questions/107676
复制相似问题