数字块


18

输出/打印此文本块:

1234567890
2468013579
3691470258
4815926037
5049382716
6172839405
7306295184
8520741963
9753108642
0987654321

可接受的格式包括:

  • 尾随换行符/空格
  • 字符串清单
  • 字符列表
  • 整数列表清单

但是,整数列表是不可接受的,因为最后一行不是整数。

这是。以字节为单位的最短答案将获胜。有标准漏洞

Answers:


20

Mathematica,33个字节

Mod[1##,11]~Mod~10&~Array~{10,10}

在线尝试!(使用数学。)

基于1的索引的单元格(x,y)具有值((x*y) % 11) % 10





5

MATL12 11字节

感谢路易斯,节省了一个字节。我一直忘了,这&是复制和移调的快捷方式。

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!*&*
路易斯Mendo

1
@LuisMendo双反引号,如果注释中的代码片段末尾有反斜杠。
Martin Ender

@MartinEnder谢谢!我不记得它是如何工作的,所以我选择了简单的方法:-)
Luis Mendo

@LuisMendo是的,使用不同语法的帖子和评论有点令人困惑。
Martin Ender

谢谢@LuisMendo!那不是在文档中吗?
Stewie Griffin



2

视网膜,59字节

字节数假定为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}。但是,如果我们只删除110s加上另一个(如果可能的话),那么正则表达式引擎的贪婪将尽可能长时间地为我们执行mod 11,否则,它将至少尝试mod 10

,(1*)
$.1

最后,我们只需将每个数字替换为其长度即可将其转换为十进制。




2

Javascript(ES6),70 64 56字节

_=>[...1e9+''].map((_,a,b)=>b.map((_,c)=>-~a*++c%1‌​1%10))

感谢Shaggy节省了4个字节,感谢Arnauld节省了8个字节。


1
66个字节:_=>[...a=Array(10)].map((_,x)=>[...a].map((_,y)=>(x+1)*++y%11%10))。您为我节省了4个字节,为我节省了4个字节:)
Shaggy

非常感谢。您还修复了一个错误,所以我为您的解决方案再剃了2个字节;-)
路加福音

1
您可以在第一个map()字节中使用回调的第3个参数来节省5个字节,1e9+''而使用代替则可以再保存3个字节Array(10)。导致_=>[...1e9+''].map((_,x,a)=>a.map((_,y)=>-~x*++y%11%10))
Arnauld

@ Arnauld:谢谢你的1e9把戏。我不知道那个。我确实考虑过使用第三个参数,但是由于某种原因我没有使用它。
路加福音

我最近在这里整理了类似技巧的清单。
Arnauld

2

Japt16 12 11字节

原来这是我的200个(未删除)答案:)

看起来这与马丁发现的公式相同。

Aõ
£®*X%B%A

测试它-R仅用于可视化的标志)

  • 由于Luke指出允许返回数组,所以节省了4个字节。

说明

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标志
路加福音

1
更好的是删除最后四个字符。看来这是允许的……
路加福音

是的,看起来你是对的,谢谢@Luke :)
Shaggy

1

Java 8,84字节

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




1

Charcoal, 30 29 19 bytes

Fχ«FχI﹪﹪×⁺¹ι⁺¹κ¹¹χ⸿

Try it online!

Uses Martin's formula.

  • 10 bytes saved thanks to Neil, proving once more that I have still so much to learn...

You don't need trailing »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.)
Neil

@Neil The ⸿ is the reverse operator, what does it do at the end of your code without arguments? Is it documented?
Charlie

1
No, is the Reverse operator, ⸿ is the move cursor to start of next line character (like but can be in a separate string).
Neil


0

QBIC, 17 bytes

[|?[|?a*b%11%z';

This, of course, uses Martin's Method. It translates to this QBasic code.

Explanation

[|               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

0

C#, 81 bytes

_=>{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.



0

GolfScript, 37 24 bytes

10,{){\)*11%10%}+10,%}%`

Try it online!

-13 thanks to a clever trick Martin Ender suggested.


if you turn it into a full program ({ --> ;, } --> `), you can at least drop the first [.
Martin Ender

It's a lot shorter to use a simple nested loop instead of the zip technique though: {){\)*11%10%}+10,/n}10,/
Martin Ender

@MartinEnder Umm...you seem to be overusing /. ;)
Erik the Outgolfer

@MartinEnder Oh I see what you did...you used int blk + -> {int space contents-of-blk}.
Erik the Outgolfer

@MartinEnder ok I've implemented your + trick...although I altered your code a bit
Erik the Outgolfer




0

Pyke, 13 bytes

TS F~u0+*i>i%

Try it here!

TS            -  [1, 2, 3, 4, 5, 6, 7, 8, 9]
   F~u0+*i>i% - for i in ^:
    ~u0+      -     "01234567890"
        *     -    ^ * i
         i>   -   ^[i:]
           i% -  ^[::i]



0

TECO, 45 bytes

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.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.