Block of digits

18

1

Output/print this block of text:

1234567890
2468013579
3691470258
4815926037
5049382716
6172839405
7306295184
8520741963
9753108642
0987654321

Acceptable formats include:

  • Trailing newlines/whitespace
  • List of strings
  • List of lists of characters
  • List of lists of integers

However, list of integers is not acceptable because the last line is not an integer.

This is . Shortest answer in bytes wins. Standard loopholes apply.

Leaky Nun

Posted 2017-06-26T09:25:35.027

Reputation: 45 011

Answers

20

Mathematica, 33 bytes

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

Try it online! (Using Mathics.)

The cell at 1-based index (x,y) has value ((x*y) % 11) % 10

Martin Ender

Posted 2017-06-26T09:25:35.027

Reputation: 184 808

11

Python 2, 48 46 bytes

n=10
while n:print('00987654321'*n)[n::n];n-=1

Try it online!

mdahmoune

Posted 2017-06-26T09:25:35.027

Reputation: 2 605

6Welcome to PPCG, and amazing first answer! We hope you'll stick around and contribute more :-) – ETHproductions – 2017-06-26T21:50:47.033

@ETHproductions thanx :))) – mdahmoune – 2017-07-06T12:03:05.247

9

Python 2, 49 47 bytes

n=1
exec"print('01234567890'*n)[n::n];n+=1;"*10

Try it online!

Rod

Posted 2017-06-26T09:25:35.027

Reputation: 17 588

nice exec use.. – mdahmoune – 2017-06-29T16:55:16.097

7

Jelly, 7 bytes

⁵×þ`%‘%

Try it online!

Uses Martin's algorithm.

Erik the Outgolfer

Posted 2017-06-26T09:25:35.027

Reputation: 38 134

5

MATL, 12 11 bytes

Saved a byte thanks to Luis. I keep forgetting the & is a shortcut for duplicating and transposing.

10:&*11\10\

Try it online!

Using @Martin's algorithm: x*y % 11 % 10

Explanation:

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 

Same bytecount:

10t:&*11\w\

Stewie Griffin

Posted 2017-06-26T09:25:35.027

Reputation: 43 471

You can save a byte replacing t!* by&* – Luis Mendo – 2017-06-26T10:13:19.323

1@LuisMendo double backticks if you have a backslash at the end of code snippet in comments. – Martin Ender – 2017-06-26T10:14:01.343

@MartinEnder Thanks! I never remember how that works, so I went for the easy way :-) – Luis Mendo – 2017-06-26T10:14:33.227

@LuisMendo yeah it's a bit confusing with posts and comments using different syntax. – Martin Ender – 2017-06-26T10:16:53.980

Thanks @LuisMendo! That's not in the docs is it? – Stewie Griffin – 2017-06-26T10:21:48.477

It is. The help for * says If 1 input: a second input is used given by the first transposed. And the notation 1-- (2 / 1); 1 for * means that & specifies 1 input (see here for explanation of this notation). Note that the meaning of & is function-specific

– Luis Mendo – 2017-06-26T10:26:52.983

4

APL (Dyalog), 13 bytes

10|11|∘.×⍨⍳10

Try it online!

A port of my Mathematica answer.

      ∘.×⍨      ⍝ Multiplication table of...
          ⍳10   ⍝ The list from 1 to 10.
   11|          ⍝ mod 11.
10|             ⍝ mod 10.

Martin Ender

Posted 2017-06-26T09:25:35.027

Reputation: 184 808

3

CJam (17 bytes)

A,:)_f{f*Bf%Af%N}

Online demo

Peter Taylor

Posted 2017-06-26T09:25:35.027

Reputation: 41 901

2

Japt, 16 12 11 bytes

Turns out this was my 200 (undeleted) answer here :)

Looks like this is the same formula Martin spotted.

Aõ
£®*X%B%A

Test it (-R flag for visualisation purposes only)

  • 4 bytes saved thanks to Luke pointing out that returning an array of arrays was permissible.

Explanation

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

Shaggy

Posted 2017-06-26T09:25:35.027

Reputation: 24 623

Beat me to it... You can drop the last two characters, and instead use the -R flag – Luke – 2017-06-26T09:53:27.857

1Even better, drop the last four characters. It seems that's allowed... – Luke – 2017-06-26T09:57:46.080

Yup, looks like you're right, thanks, @Luke :) – Shaggy – 2017-06-26T09:58:47.300

2

Javascript (ES6), 70 64 56 bytes

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

Saved 4 bytes thanks to Shaggy and 8 bytes thanks to Arnauld.

Luke

Posted 2017-06-26T09:25:35.027

Reputation: 4 675

166 bytes: _=>[...a=Array(10)].map((_,x)=>[...a].map((_,y)=>(x+1)*++y%11%10)). You save me 4 bytes, I save you 4 bytes :) – Shaggy – 2017-06-26T10:05:20.030

Thanks a lot. You also fixed a bug, so I shaved another 2 bytes of your solution ;-) – Luke – 2017-06-26T10:11:05.037

1You can save 5 bytes by using the 3rd parameter of the callback in the first map() and 3 more bytes by using 1e9+'' instead of Array(10). That leads to _=>[...1e9+''].map((_,x,a)=>a.map((_,y)=>-~x*++y%11%10)). – Arnauld – 2017-06-26T11:20:44.197

@Arnauld: Thanks for the 1e9 trick. I didn't know that one. I did think about using the third argument, but for some reason I didn't use it. – Luke – 2017-06-27T11:40:47.497

I've recently compiled a list of similar tricks here.

– Arnauld – 2017-06-27T11:51:50.057

2

Retina, 59 bytes

Byte count assumes ISO 8859-1 encoding.


10$*
1
,1$`
,1+
$_¶
(?<=(¶?.+)+)1
$#1$*
1{10}1?

,(1*)
$.1

Try it online!

Explanation

Another implementation of the ... % 11 % 10 algorithm. The fun part of doing it with a regex is that we can take care of both modulo computations at once.


10$*

Initialise the string to ten 1s.

1
,1$`

Replace each of those with a comma, a one, and the prefix in front of that one. This gives ,1,11,...,1111111111, i.e. a unary range.

,1+
$_¶

Now replace each of the range elements with the entire string followed by a linefeed. This gives us a 10x10 grid of unary numbers indicating the current column.

(?<=(¶?.+)+)1
$#1$*

Match each 1 and determine which row it's on by repeating group one that many times. Replace the 1 with that many 1s. This multiplies the values in each row by the row's 1-based index.

1{10}1?

Now let's do mod 11, mod 10 in one step. To do mod 11, we'd normally just remove all 1{11} from the string to be left with the remainders. And then we'd remove 1{10} after that. But if we just remove ten 1s plus another if possible, the regex engine's greediness will do mod 11 for us as long as possible, and if not, then it'll try at least mod 10.

,(1*)
$.1

Finally, we just convert each number to decimal by replacing it with its length.

Martin Ender

Posted 2017-06-26T09:25:35.027

Reputation: 184 808

2

05AB1E, 14 bytes

11GTLN*11%T%})

Try it online!

Uses Martin's algorithm, as usual.

Erik the Outgolfer

Posted 2017-06-26T09:25:35.027

Reputation: 38 134

Oh, there's an algorithm for that pattern. That explains why I'm 30 bytes above the average answer. – Magic Octopus Urn – 2017-06-30T13:47:22.763

2

Haskell, 43 bytes

l=[1..10]
f=[[x*i`mod`11`mod`10|i<-l]|x<-l]

siracusa

Posted 2017-06-26T09:25:35.027

Reputation: 623

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

Charlie

Posted 2017-06-26T09:25:35.027

Reputation: 11 448

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 – 2017-06-29T09:49:45.303

@Neil The ⸿ is the reverse operator, what does it do at the end of your code without arguments? Is it documented? – Charlie – 2017-06-29T09:57:00.700

1No, is the Reverse operator, ⸿ is the move cursor to start of next line character (like but can be in a separate string). – Neil – 2017-06-29T10:17:16.833

1

Java 8, 84 bytes

o->{String r="";for(int x=0,y;++x<11;r+="\n")for(y=0;++y<11;r+=x*y%11%10);return r;}

Uses the same algorithm as @MartinEnder's Mathematica answer: 1-indexed x*y%11%10.

Explanation:

Try it here.

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

Kevin Cruijssen

Posted 2017-06-26T09:25:35.027

Reputation: 67 575

1

Python 2, 58 52 bytes

-6 bytes thanks to offcialaimm.

Uses Martin's algorithm which I have no understanding of how he came up with it so fast. o0

r=range(1,11)
print[[x*y%11%10for y in r]for x in r]

Try it online!

totallyhuman

Posted 2017-06-26T09:25:35.027

Reputation: 15 378

1Shorthand r=range(1,11) saves 6 bytes – officialaimm – 2017-06-26T11:16:03.667

2

Part of the reason I spotted the formula so quickly is this math.SE question of mine and orlp's comment there.

– Martin Ender – 2017-06-26T13:02:58.250

1

Pyth, 13 bytes

mme%*kd11STST

Try it here

-1 thanks to KarlKastor.

Let's duuuuuuupe!

Erik the Outgolfer

Posted 2017-06-26T09:25:35.027

Reputation: 38 134

Save one byte if you use e instead of % T – KarlKastor – 2017-06-26T12:11:39.520

@KarlKastor ...and I was remembering it ._. – Erik the Outgolfer – 2017-06-26T12:12:00.453

1

R, 19 bytes

1:10%o%1:10%%11%%10

Try it online!

The least "R"-looking bit of R code I have ever written. Uses the same algorithm as Martin Ender's answer (and almost all the other answers as well). x %o% y is the same as outer(x, y).

user2390246

Posted 2017-06-26T09:25:35.027

Reputation: 1 391

0

C (gcc), 70 bytes

f(x,y){for(x=0;x++<10;puts(""))for(y=0;y++<10;putchar(x*y%11%10+48));}

Try it online!

Giacomo Garabello

Posted 2017-06-26T09:25:35.027

Reputation: 1 419

0

Retina, 93 85 bytes


10$*T
M!&`T+
m`$
;110$*T10$*
1
09876543210
m`(?<=^\1;\1{0,9}(T+))T
C
(?<!C.{108})\S

Try it online!

Leaky Nun

Posted 2017-06-26T09:25:35.027

Reputation: 45 011

71 bytes: Try it online! No idea where the magic number of 109 derives from through.

– Neil – 2017-06-29T10:09:33.707

0

PHP, 54 bytes

for(;9>=$y++||9>=$x+=$y=print"
";)echo($x+1)*$y%11%10;

Try it online!

PHP, 56 bytes

for(;$x++<=9;print"
")for($y=0;$y++<=9;)echo$x*$y%11%10;

Try it online!

Jörg Hülsermann

Posted 2017-06-26T09:25:35.027

Reputation: 13 026

1You can drop the brackets (). – Christoph – 2017-06-26T10:53:49.683

-2 bytes: for(;<0>$y++||10>$x+=$y=print"\n";)echo($x+1)*$y%11%10; – Titus – 2017-06-27T17:07:58.707

... or for($x=1;11>++$y||11>$x+=$y=print"\n";)echo$x*$y%11%10; – Titus – 2017-06-27T17:15:22.930

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

steenbergh

Posted 2017-06-26T09:25:35.027

Reputation: 7 772

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.

TheLethalCoder

Posted 2017-06-26T09:25:35.027

Reputation: 6 930

0

Retina, 79 bytes


12345678902468013579369147025848159260375049382716
.*
$&$&
O$^50>`.

.{10}
$&¶

Try it online!

ovs

Posted 2017-06-26T09:25:35.027

Reputation: 21 408

0

GolfScript, 37 24 bytes

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

Try it online!

-13 thanks to a clever trick Martin Ender suggested.

Erik the Outgolfer

Posted 2017-06-26T09:25:35.027

Reputation: 38 134

if you turn it into a full program ({ --> ;, } --> \``), you can at least drop the first[`. – Martin Ender – 2017-06-26T16:28:37.320

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

@MartinEnder Umm...you seem to be overusing /. ;) – Erik the Outgolfer – 2017-06-26T16:35:17.133

@MartinEnder Oh I see what you did...you used int blk + -> {int space contents-of-blk}. – Erik the Outgolfer – 2017-06-26T16:36:28.097

@MartinEnder ok I've implemented your + trick...although I altered your code a bit – Erik the Outgolfer – 2017-06-26T16:43:34.473

0

C (gcc), 59 bytes

f(n,t){for(n=11;++n<121;putchar(t?t%10+48:10))t=n/11*n%11;}

Try it online!

Dennis

Posted 2017-06-26T09:25:35.027

Reputation: 196 637

0

Pyke, 15 bytes

TD]UMha*11%`e)P

Try it here!

Blue

Posted 2017-06-26T09:25:35.027

Reputation: 26 661

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]

Blue

Posted 2017-06-26T09:25:35.027

Reputation: 26 661

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.

JoeT

Posted 2017-06-26T09:25:35.027

Reputation: 1

0

J, 27 bytes

1":(10|11|*&>:)"0/~@(i.@9:)

Try it online!

Uses the same trick as in Martin Ender's Mathematica answer.

Conor O'Brien

Posted 2017-06-26T09:25:35.027

Reputation: 36 228