Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 170 characters in body
Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, (削除) 66 64 (削除ここまで) 61 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a|[q=a.sum,a[~q%2]]}}

Try it online!

How it works:

First, create the set of coordinates from the cartesian product of X and Y, then sort by sum and then by ascending or descending X alternatively.

Ruby, (削除) 66 64 (削除ここまで) 61 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a|[q=a.sum,a[~q%2]]}}

Try it online!

Ruby, (削除) 66 64 (削除ここまで) 61 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a|[q=a.sum,a[~q%2]]}}

Try it online!

How it works:

First, create the set of coordinates from the cartesian product of X and Y, then sort by sum and then by ascending or descending X alternatively.

added 6 characters in body
Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, 64(削除) 66 64 (削除ここまで) 61 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a,b|[q=a+b,[b|a|[q=a.sum,a][q%2]]a[~q%2]]}}

Try it online! Try it online!

Ruby, 64 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a,b|[q=a+b,[b,a][q%2]]}}

Try it online!

Ruby, (削除) 66 64 (削除ここまで) 61 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a|[q=a.sum,a[~q%2]]}}

Try it online!

Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, 64 bytes

->w,h{[*1..w].product([*1..h]).sort_by{|a,b|[q=a+b,[b,a][q%2]]}}

Try it online!

AltStyle によって変換されたページ (->オリジナル) /