Skip to main content
added 270 characters in body
Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

Ruby, 5555 53 bytes

->n{n.times{|x|x.times{|y|w=*0|y|(w=*0...n;w[x],w[y]=y,x;pn)[w[x]=y]=x;p w}}}

Try it online!Try it online!

0-based solution

The trick here is that the inner loop always "skips" an iteration: the first time it's not executed at all, then only once on the second pass, and so on.

I was happy with 55 bytes until I saw that R could be golfed down to 54, so I had to get it to 53.

Ruby, 55 bytes

->n{n.times{|x|x.times{|y|w=*0...n;w[x],w[y]=y,x;p w}}}

Try it online!

0-based solution

Ruby, 55 53 bytes

->n{n.times{|x|x.times{|y|(w=*0...n)[w[x]=y]=x;p w}}}

Try it online!

0-based solution

The trick here is that the inner loop always "skips" an iteration: the first time it's not executed at all, then only once on the second pass, and so on.

I was happy with 55 bytes until I saw that R could be golfed down to 54, so I had to get it to 53.

Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

Ruby, 55 bytes

->n{n.times{|x|x.times{|y|w=*0...n;w[x],w[y]=y,x;p w}}}

Try it online!

0-based solution