Skip to main content
edited body
Source Link
mousetail 'he-him'
  • 13.5k
  • 1
  • 39
  • 85

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))+(a>=0))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8a>=0 to add 1 to negative numbers then abs merges both halves of the triangle.

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))+(a>=0))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8 to add 1 to negative numbers then abs merges both halves of the triangle.

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))+(a>=0))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>=0 to add 1 to negative numbers then abs merges both halves of the triangle.

edited body
Source Link
mousetail 'he-him'
  • 13.5k
  • 1
  • 39
  • 85

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))-+(a>>8a>=0))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8 to add 1 to negative numbers then abs merges both halves of the triangle.

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))-(a>>8))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8 to add 1 to negative numbers then abs merges both halves of the triangle.

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))+(a>=0))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8 to add 1 to negative numbers then abs merges both halves of the triangle.

Source Link
mousetail 'he-him'
  • 13.5k
  • 1
  • 39
  • 85

Python, 71 bytes

lambda x:x-abs((a:=r(x)-r(x+1))-(a>>8))
from random import*
r=randrange

Attempt This Online!

Surprisingly tricky. Uses the fact that the sum of 2 numbers form a rectangle, then using a>>8 to add 1 to negative numbers then abs merges both halves of the triangle.