Skip to main content
added 462 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484

J, 30 29 bytes

10(|-:@#$]#~@,"0|.)2&|0&,1+i. 

Try it online!

J's reshape $ is so weird that it works in place of take {. when the left is positive singleton (regardless of what comes on the right).


J, 30 bytes

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. 

Try it online!

Yet another case of repeat-bind (dyadic &) winning over other approaches.

How it works

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. NB. input=n 1+i. NB. 1..n 2&|0&, NB. prepend 0, but only if n is odd ( ] "0|.) NB. for each pair (x,y) of the above and above reversed, #~@, NB. concatenate x copies of x and y copies of y -:@#{. NB. take half the rows 10 | NB. modulo 10 to all elements of the array 

J, 30 bytes

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. 

Try it online!

Yet another case of repeat-bind (dyadic &) winning over other approaches.

How it works

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. NB. input=n 1+i. NB. 1..n 2&|0&, NB. prepend 0, but only if n is odd ( ] "0|.) NB. for each pair (x,y) of the above and above reversed, #~@, NB. concatenate x copies of x and y copies of y -:@#{. NB. take half the rows 10 | NB. modulo 10 to all elements of the array 

J, 30 29 bytes

10(|-:@#$]#~@,"0|.)2&|0&,1+i. 

Try it online!

J's reshape $ is so weird that it works in place of take {. when the left is positive singleton (regardless of what comes on the right).


J, 30 bytes

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. 

Try it online!

Yet another case of repeat-bind (dyadic &) winning over other approaches.

How it works

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. NB. input=n 1+i. NB. 1..n 2&|0&, NB. prepend 0, but only if n is odd ( ] "0|.) NB. for each pair (x,y) of the above and above reversed, #~@, NB. concatenate x copies of x and y copies of y -:@#{. NB. take half the rows 10 | NB. modulo 10 to all elements of the array 
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484

J, 30 bytes

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. 

Try it online!

Yet another case of repeat-bind (dyadic &) winning over other approaches.

How it works

10(|-:@#{.]#~@,"0|.)2&|0&,1+i. NB. input=n 1+i. NB. 1..n 2&|0&, NB. prepend 0, but only if n is odd ( ] "0|.) NB. for each pair (x,y) of the above and above reversed, #~@, NB. concatenate x copies of x and y copies of y -:@#{. NB. take half the rows 10 | NB. modulo 10 to all elements of the array