18
\$\begingroup\$

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.

\$\endgroup\$

29 Answers 29

20
\$\begingroup\$

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

\$\endgroup\$
11
\$\begingroup\$

Python 2, 48 46 bytes

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

Try it online!

\$\endgroup\$
  • 6
    \$\begingroup\$ Welcome to PPCG, and amazing first answer! We hope you'll stick around and contribute more :-) \$\endgroup\$ – ETHproductions Jun 26 '17 at 21:50
  • \$\begingroup\$ @ETHproductions thanx :))) \$\endgroup\$ – mdahmoune Jul 6 '17 at 12:03
9
\$\begingroup\$

Python 2, 49 47 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ nice exec use.. \$\endgroup\$ – mdahmoune Jun 29 '17 at 16:55
7
\$\begingroup\$

Jelly, 7 bytes

⁵×þ`%‘%

Try it online!

Uses Martin's algorithm.

\$\endgroup\$
5
\$\begingroup\$

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\
\$\endgroup\$
  • \$\begingroup\$ You can save a byte replacing t!* by&* \$\endgroup\$ – Luis Mendo Jun 26 '17 at 10:13
  • 1
    \$\begingroup\$ @LuisMendo double backticks if you have a backslash at the end of code snippet in comments. \$\endgroup\$ – Martin Ender Jun 26 '17 at 10:14
  • \$\begingroup\$ @MartinEnder Thanks! I never remember how that works, so I went for the easy way :-) \$\endgroup\$ – Luis Mendo Jun 26 '17 at 10:14
  • \$\begingroup\$ @LuisMendo yeah it's a bit confusing with posts and comments using different syntax. \$\endgroup\$ – Martin Ender Jun 26 '17 at 10:16
  • \$\begingroup\$ Thanks @LuisMendo! That's not in the docs is it? \$\endgroup\$ – Stewie Griffin Jun 26 '17 at 10:21
4
\$\begingroup\$

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.
\$\endgroup\$
3
\$\begingroup\$

CJam (17 bytes)

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

Online demo

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 14 bytes

11GTLN*11%T%})

Try it online!

Uses Martin's algorithm, as usual.

\$\endgroup\$
  • \$\begingroup\$ Oh, there's an algorithm for that pattern. That explains why I'm 30 bytes above the average answer. \$\endgroup\$ – Magic Octopus Urn Jun 30 '17 at 13:47
2
\$\begingroup\$

Haskell, 43 bytes

l=[1..10]
f=[[x*i`mod`11`mod`10|i<-l]|x<-l]
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 66 bytes: _=>[...a=Array(10)].map((_,x)=>[...a].map((_,y)=>(x+1)*++y%11%10)). You save me 4 bytes, I save you 4 bytes :) \$\endgroup\$ – Shaggy Jun 26 '17 at 10:05
  • \$\begingroup\$ Thanks a lot. You also fixed a bug, so I shaved another 2 bytes of your solution ;-) \$\endgroup\$ – Luke Jun 26 '17 at 10:11
  • 1
    \$\begingroup\$ You 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)). \$\endgroup\$ – Arnauld Jun 26 '17 at 11:20
  • \$\begingroup\$ @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. \$\endgroup\$ – Luke Jun 27 '17 at 11:40
  • \$\begingroup\$ I've recently compiled a list of similar tricks here. \$\endgroup\$ – Arnauld Jun 27 '17 at 11:51
2
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Beat me to it... You can drop the last two characters, and instead use the -R flag \$\endgroup\$ – Luke Jun 26 '17 at 9:53
  • 1
    \$\begingroup\$ Even better, drop the last four characters. It seems that's allowed... \$\endgroup\$ – Luke Jun 26 '17 at 9:57
  • \$\begingroup\$ Yup, looks like you're right, thanks, @Luke :) \$\endgroup\$ – Shaggy Jun 26 '17 at 9:58
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 13 bytes

mme%*kd11STST

Try it here

-1 thanks to KarlKastor.

Let's duuuuuuupe!

\$\endgroup\$
  • \$\begingroup\$ Save one byte if you use e instead of % T \$\endgroup\$ – KarlKastor Jun 26 '17 at 12:11
  • \$\begingroup\$ @KarlKastor ...and I was remembering it ._. \$\endgroup\$ – Erik the Outgolfer Jun 26 '17 at 12:12
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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...
\$\endgroup\$
  • \$\begingroup\$ 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.) \$\endgroup\$ – Neil Jun 29 '17 at 9:49
  • \$\begingroup\$ @Neil The ⸿ is the reverse operator, what does it do at the end of your code without arguments? Is it documented? \$\endgroup\$ – Charlie Jun 29 '17 at 9:57
  • 1
    \$\begingroup\$ No, is the Reverse operator, ⸿ is the move cursor to start of next line character (like but can be in a separate string). \$\endgroup\$ – Neil Jun 29 '17 at 10:17
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Retina, 79 bytes


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

.{10}
$&¶

Try it online!

\$\endgroup\$
0
\$\begingroup\$

GolfScript, 37 24 bytes

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

Try it online!

-13 thanks to a clever trick Martin Ender suggested.

\$\endgroup\$
  • \$\begingroup\$ if you turn it into a full program ({ --> ;, } --> `), you can at least drop the first [. \$\endgroup\$ – Martin Ender Jun 26 '17 at 16:28
  • \$\begingroup\$ It's a lot shorter to use a simple nested loop instead of the zip technique though: {){\)*11%10%}+10,/n}10,/ \$\endgroup\$ – Martin Ender Jun 26 '17 at 16:32
  • \$\begingroup\$ @MartinEnder Umm...you seem to be overusing /. ;) \$\endgroup\$ – Erik the Outgolfer Jun 26 '17 at 16:35
  • \$\begingroup\$ @MartinEnder Oh I see what you did...you used int blk + -> {int space contents-of-blk}. \$\endgroup\$ – Erik the Outgolfer Jun 26 '17 at 16:36
  • \$\begingroup\$ @MartinEnder ok I've implemented your + trick...although I altered your code a bit \$\endgroup\$ – Erik the Outgolfer Jun 26 '17 at 16:43
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ 71 bytes: Try it online! No idea where the magic number of 109 derives from through. \$\endgroup\$ – Neil Jun 29 '17 at 10:09
0
\$\begingroup\$

Pyke, 15 bytes

TD]UMha*11%`e)P

Try it here!

\$\endgroup\$
0
\$\begingroup\$

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]
\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
  • 1
    \$\begingroup\$ You can drop the brackets (). \$\endgroup\$ – Christoph Jun 26 '17 at 10:53
  • \$\begingroup\$ -2 bytes: for(;<0>$y++||10>$x+=$y=print"\n";)echo($x+1)*$y%11%10; \$\endgroup\$ – Titus Jun 27 '17 at 17:07
  • \$\begingroup\$ ... or for($x=1;11>++$y||11>$x+=$y=print"\n";)echo$x*$y%11%10; \$\endgroup\$ – Titus Jun 27 '17 at 17:15
0
\$\begingroup\$

J, 27 bytes

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

Try it online!

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.