您应该输出我最近设计的系列,如下所示:升素数的笔画计数:
2, 3, 2, 4, 3, 5, 6, 5, 7, 7, 7, 10, 4, 6, 7, 4, 4, 4, 7, 6, 8...这说明了这个系列是如何形成的,首先,它从序列形式中获取一个素数,所以它使用第一个素数2。它将其转换为2的罗马数字,即II,这里笔画是一条直线,在本例中是2,因此本系列中的第一个元素是2。
解释每一个字母的笔画都会令人费解,而且我们知道所有的罗马数字都只包含I, V, X, L, C, D, M字符,这里已经显示了每个字母的笔画值。
0 C
1 I, L, D
2 V, X
3 [None]
4 M例如,MMMMMMMCMXIX是罗马数字7919,所以您可以将它与上面的字典进行比较,M有4种笔画,等等,它们添加到37笔画中。
可以询问为什么M没有被指定为2笔画,而L没有被分配2次笔画;这是因为它们不是以数字的方式编写的。正如M和L所写的:


在标准罗马数字中,M作4笔笔画,L作1,因为L的另一行太小,不能认为是笔画。
以获得输入号的字节数编写最短的代码,并从输入中输出尽可能多的元素。
5 => 2, 3, 2, 4, 3
10 => 2, 3, 2, 4, 3, 5, 6, 5, 7, 7
15 => 2, 3, 2, 4, 3, 5, 6, 5, 7, 7, 7, 10, 4, 6, 7不要忘记,这是实现笔画数的罗马数字的素数,只有升序!
发布于 2023-04-23 19:14:00
math.primes math.unicode roman,63字节[ nprimes [ >roman [ "c--ildvx----m"index 3 /i ] map Σ ] map ][ ! start quotation (anonymous function)
nprimes ! get a list of the first number of primes indicated by input
[ ! start map
>roman ! convert current prime to roman numerals
[ ! start map
"c--ildvx----m" ! push string to stack
index ! find the index of the current letter in the string
3 /i ! integer divide by 3
] map ! map over each letter in the roman numerals of current prime
Σ ! take sum of results of the letters
] map ! map over the first n primes
] ! end quotation发布于 2023-04-24 07:44:23
Åpε.XÇŽœ
s%5%OJonathanAllan的Vyxal回答港,所以一定要投他一票!
输出没有输入的无限序列的
Žœ
∞<Ø.X€Ç%5%OÅp # Get a list of the first (implicit) input amount of primes
ε # Map over each prime number:
.X # Convert it to a Roman number string
Ç # Convert this string to a list of its codepoint integers
Žœ\n # Push compressed integer 39602
s # Swap so the list of lists of codepoint integers is at the top
% # Modulo the 39602 by each of these codepoints
5% # Modulo-5 that
O # Take the sum of each inner list
# (after which the resulting list is output implicitly)看这个05AB1E我的尖端(部分)如何压缩大整数?)来理解为什么Žœ\n是39602。
发布于 2023-04-25 09:44:47
用所有不相关的东西完整地回答。
f=(k,n=1)=>k?(g=d=>n%d--?g(d):d)(n++)?f(k,n):["2345545673"[n%10]-(g=d=>n/d%10%9<4)(10)-g(100)+11%~(q=-~n/10%5)*2+(q-4?4*!q:6)+(n/1e3+.1<<2),...f(k-1,n)]:[]下面是一个更容易测试的有趣部分:一个函数,它使用整数并返回它的罗马数字表示中笔画的笔画数。
n=>"2345545673"[n%10]-(g=d=>n/d%10%9<4)(10)-g(100)+11%~(q=-~n/10%5)*2+(q-4?4*!q:6)+(n/1e3+.1<<2)n => // n = input
"2345545673" // hard-coded number of straight strokes + 2 in I's
[n % 10] - // and V's, which can be computed modulo 10
( // g is a helper function processing L's and D's,
g = d => // which follow the same logic:
n / d % 10 // divide n by the argument and reduce modulo 10
% 9 // further reduce modulo 9
< 4 // is the result less than 4?
)(10) - // first call to g with d = 10
g(100) + // 2nd call to g with d = 100
11 % // the number of X's can be computed modulo 50
~( // we first evaluate the generic expression:
q = // 11 mod floor(q + 1)
-~n / 10 % 5 // with q = ((n + 1) / 10) mod 5
) * 2 + // and double the result to get the number of strokes
( // we then apply two corrections:
q - 4 ? //
4 * !q // +4 strokes if q = 0, i.e. n = 49 (mod 50)
: //
6 // +6 strokes if q = 4, i.e. n = 39 (mod 50)
) + //
( //
n / 1e3 + .1 // the number of M's is floor(n / 1000 + 1 / 10)
<< 2 // we multiply by 4 to get the number of strokes
) //https://codegolf.stackexchange.com/questions/260393
复制相似问题