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 567 characters in body
Source Link
dfeuer
  • 1.2k
  • 14
  • 16

Haskell, (削除) 77 (削除ここまで) 76 bytes

import System.Random
f x=randomRIO(1,x)>>=(x!)
x!y|y<x=pure y|0<1=(y+)<$>f x

Try it online!

Thanks to killmous for one byte.

If <|> were in the prelude, we could do better with MonadComprehensions:

Haskell , non-competing, 66 bytes

import System.Random
f x=do y<-randomRIO(1,x);[y|y<x]<|>(y+)<$>f x

Try it online!

Haskell, (削除) 77 (削除ここまで) 76 bytes

import System.Random
f x=randomRIO(1,x)>>=(x!)
x!y|y<x=pure y|0<1=(y+)<$>f x

Try it online!

Thanks to killmous for one byte.

Haskell, (削除) 77 (削除ここまで) 76 bytes

import System.Random
f x=randomRIO(1,x)>>=(x!)
x!y|y<x=pure y|0<1=(y+)<$>f x

Try it online!

Thanks to killmous for one byte.

If <|> were in the prelude, we could do better with MonadComprehensions:

Haskell , non-competing, 66 bytes

import System.Random
f x=do y<-randomRIO(1,x);[y|y<x]<|>(y+)<$>f x

Try it online!

added 58 characters in body
Source Link
dfeuer
  • 1.2k
  • 14
  • 16

Haskell, 77(削除) 77 (削除ここまで) 76 bytes

import System.Random
f x=randomRIO(1,x)>>=g >>=(x!)
g x!y|y<x=pure y|0<1=(y+)<$>f x

Try it online! Try it online!

Thanks to killmous for one byte.

Haskell, 77 bytes

import System.Random
f x=randomRIO(1,x)>>=g x
g xy|y<x=pure y|0<1=(y+)<$>f x

Try it online!

Haskell, (削除) 77 (削除ここまで) 76 bytes

import System.Random
f x=randomRIO(1,x)>>=(x!)
x!y|y<x=pure y|0<1=(y+)<$>f x

Try it online!

Thanks to killmous for one byte.

Source Link
dfeuer
  • 1.2k
  • 14
  • 16

Haskell, 77 bytes

import System.Random
f x=randomRIO(1,x)>>=g x
g x y|y<x=pure y|0<1=(y+)<$>f x

Try it online!

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