Answers:
感谢路易斯,节省了一个字节。我一直忘了,这&
是复制和移调的快捷方式。
10:&*11\10\
使用@Martin的算法: x*y % 11 % 10
说明:
10 % Pust 10 to the stack. Stack: 1
: % 1-based range. Stack: [1 2 3 ... 10]
& % Duplicate range. Stack: [1 2 3 ... 10],[1 2 3 ... 10]
% Transpose last range. Stack [1 2 3 ... 10],[1;2;3 ...10]
* % Multiply with broadcasting. Stack: [1 2 3 ...;2 4 6...] (10-by-10 array)
11 % Push 11 to the stack. Stack [1 2 3 ...;2 4 6 ...], 11
\ % Modulus.
10 % Push 10 to the stack.
\ % Modulus
% Implicit display
相同的字节数:
10t:&*11\w\
t!*
用&*
10|11|∘.×⍨⍳10
的口我的数学答案。
∘.×⍨ ⍝ Multiplication table of...
⍳10 ⍝ The list from 1 to 10.
11| ⍝ mod 11.
10| ⍝ mod 10.
字节数假定为ISO 8859-1编码。
10$*
1
,1$`
,1+
$_¶
(?<=(¶?.+)+)1
$#1$*
1{10}1?
,(1*)
$.1
...%11%10算法的另一种实现。使用正则表达式进行操作的有趣之处在于,我们可以同时处理两种模运算。
10$*
将字符串初始化为十秒1
。
1
,1$`
用逗号,一个和前面的前缀替换每个。这给出,1,11,...,1111111111
,即一元范围。
,1+
$_¶
现在,用整个字符串和换行符替换每个范围元素。这使我们得到一个10x10的一元网格,表示当前列。
(?<=(¶?.+)+)1
$#1$*
匹配每个1
并通过重复一组多次来确定它在哪一行。1
用那么多替换1
。这会将每行中的值乘以该行基于1的索引。
1{10}1?
现在让我们一步一步完成mod 11,mod 10。做mod 11,我们通常只是1{11}
从字符串中删除所有剩下的部分。然后我们将其删除1{10}
。但是,如果我们只删除1
10s加上另一个(如果可能的话),那么正则表达式引擎的贪婪将尽可能长时间地为我们执行mod 11,否则,它将至少尝试mod 10。
,(1*)
$.1
最后,我们只需将每个数字替换为其长度即可将其转换为十进制。
_=>[...1e9+''].map((_,a,b)=>b.map((_,c)=>-~a*++c%11%10))
感谢Shaggy节省了4个字节,感谢Arnauld节省了8个字节。
_=>[...a=Array(10)].map((_,x)=>[...a].map((_,y)=>(x+1)*++y%11%10))
。您为我节省了4个字节,为我节省了4个字节:)
map()
字节中使用回调的第3个参数来节省5个字节,1e9+''
而使用代替则可以再保存3个字节Array(10)
。导致_=>[...1e9+''].map((_,x,a)=>a.map((_,y)=>-~x*++y%11%10))
。
1e9
把戏。我不知道那个。我确实考虑过使用第三个参数,但是由于某种原因我没有使用它。
原来这是我的200个(未删除)答案:)
看起来这与马丁发现的公式相同。
Aõ
£®*X%B%A
测试它(-R
仅用于可视化的标志)
Aõ :Generate an array of integers from 1 to 10, inclusive.
£ :Map over each element in the array, returning...
® :Another map of the same array, which...
*X :Multiplies the current element of the inner function by the current element of the outer function...
%B :Modulus 11...
%A :Modulus 10.
:Implicit output of resulting 2D array
-R
标志
o->{String r="";for(int x=0,y;++x<11;r+="\n")for(y=0;++y<11;r+=x*y%11%10);return r;}
使用与@MartinEnder的Mathematica答案相同的算法:1索引x*y%11%10
。
说明:
o->{ // Unused Object parameter and String return-type
String r=""; // Result-String
for(int x=0,y;++x<11; // Loop (1) from 1 to 11 (exclusive)
r+="\n") // And append a new-line after every iteration
for(y=0;++y<11; // Inner loop (2) from 1 to 11 (exclusive)
r+=x*y%11%10 // And append the result-String with `x*y%11%10`
); // End of inner loop (2)
// End of loop (1) (implicit / single-line body)
return r; // Return result-String
} // End of method
-6个字节,感谢offcialaimm。
使用Martin的算法,我不了解他是如何这么快提出的。00
r=range(1,11)
print[[x*y%11%10for y in r]for x in r]
r=range(1,11)
节省6个字节
1:10%o%1:10%%11%%10
我写过的R代码中看起来至少“ R”的位。使用与Martin Ender的答案相同的算法(以及几乎所有其他答案)。x %o% y
与相同outer(x, y)
。
Fχ«FχI﹪﹪×⁺¹ι⁺¹κ¹¹χ⸿
Uses Martin's formula.
»
s and while you can use ω
instead of ””
you can save a whole bunch of bytes by using ⸿
as this then becomes Fχ«FχI﹪﹪×⁺¹ι⁺¹κ¹¹χ⸿
. (Before I knew about ⸿
I would have suggested J⁰ι
which would still have saved a number of bytes.)
⸿
is the reverse operator, what does it do at the end of your code without arguments? Is it documented?
⮌
is the Reverse operator, ⸿
is the move cursor to start of next line
character (like ¶
but can be in a separate string).
f(x,y){for(x=0;x++<10;puts(""))for(y=0;y++<10;putchar(x*y%11%10+48));}
[|?[|?a*b%11%z';
This, of course, uses Martin's Method. It translates to this QBasic code.
[| FOR A = 1 to 10 ([ starts a FOR loop, | delimits the list of arguments;
a FOR loop with 0 args loops from 1 to 10 by default with increment 1.
? PRINT a newline
[| Start a second FOR loop from 1-10, iterator b
? PRINT
a*b%11%z the result of Martin's formula.
'; and suppress newlines/tabs/spaces
_=>{var r="";for(int x=0,y;++x<11;r+="\n")for(y=0;++y<11;r+=x*y%11%10);return r;}
Same algorithm as most of the other answers and essentially the C# port of @Kevins Java answer.
12345678902468013579369147025848159260375049382716
.*
$&$&
O$^50>`.
.{10}
$&¶
10,{){\)*11%10%}+10,%}%`
-13 thanks to a clever trick Martin Ender suggested.
{
--> ;
, }
--> `
), you can at least drop the first [
.
{){\)*11%10%}+10,/n}10,/
/
. ;)
int blk +
-> {int space contents-of-blk}
.
+
trick...although I altered your code a bit
10$*T
M!&`T+
m`$
;110$*T10$*
1
09876543210
m`(?<=^\1;\1{0,9}(T+))T
C
(?<!C.{108})\S
TS F~u0+*i>i%
TS - [1, 2, 3, 4, 5, 6, 7, 8, 9]
F~u0+*i>i% - for i in ^:
~u0+ - "01234567890"
* - ^ * i
i> - ^[i:]
i% - ^[::i]
for(;9>=$y++||9>=$x+=$y=print"
";)echo($x+1)*$y%11%10;
for(;$x++<=9;print"
")for($y=0;$y++<=9;)echo$x*$y%11%10;
()
.
for(;<0>$y++||10>$x+=$y=print"\n";)echo($x+1)*$y%11%10;
for($x=1;11>++$y||11>$x+=$y=print"\n";)echo$x*$y%11%10;
1":(10|11|*&>:)"0/~@(i.@9:)
Uses the same trick as in Martin Ender's Mathematica answer.
1un@i/
/10<@i/01234567890/jl10<qnc0a^t>jtl%n>
A (fairly) straightforward implementation of Rod's Python answer.
1un !initialize register n to 1!
@i/<nl>/ !insert a newline!
10< !loop for 10 rows!
@i/01234567890/ !insert the mysterious string of digits!
j !move point to start of buffer!
l !move forward past the newline!
10< !loop for 10 digits on a line!
qnc !move point forward by n characters!
0a^t !print the character at point!
> !end inner loop!
j !move point to start of buffer!
t !print (empty) line!
l !move to start of digit string!
%n !increment register n (for next line)!
> !end outer loop!
Using <ESC>-terminated inserts and a control character for the ^T command would save another three five bytes, at the expense of readability.
Using Martin's mod-11/mod-10 formula actually makes it longer at 43 bytes using controls for ^A and ^T, mostly because TECO doesn't have a mod operator.
0ur10<%run10<qn-10"g-11%n'qn\r0a^Tqr%n>^a
^A>
Mod 11 is done in an ongoing fashion by incrementing the number in qn by -11 whenever it exceeds 10. The qn\r0a^T
sequence inserts the number in the editing buffer as decimal digits, reverses past the last digit, retrieves it from the buffer and types it, essentially doing mod-10.
I expected it to be shorter. Oh, well.