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 378 characters in body
Source Link
bugs
  • 231
  • 1
  • 5

Haskell, (削除) 94 (削除ここまで) 81(削除) 81 (削除ここまで) 78 bytes

import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else;last$((i+)<$>f n):[return i|i<n]

Try it online!


Try it online!Original

Quite similar to @dfeuer's, but using do notation.

Saved 13 bytes by removing whitespace, thanks to @dfeuer.

  • -13 bytes by removing whitespace, thanks to @dfeuer
  • -3 bytes thanks to this

Haskell, (削除) 94 (削除ここまで) 81 bytes

import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n

Try it online!

Quite similar to @dfeuer's, but using do notation.

Saved 13 bytes by removing whitespace, thanks to @dfeuer.

Haskell, (削除) 94 (削除ここまで) (削除) 81 (削除ここまで) 78 bytes

import System.Random
f n=do i<-randomRIO(1,n);last$((i+)<$>f n):[return i|i<n]

Try it online!


Original

Quite similar to @dfeuer's, but using do notation.

  • -13 bytes by removing whitespace, thanks to @dfeuer
  • -3 bytes thanks to this
added 1 character in body
Source Link
bugs
  • 231
  • 1
  • 5

HaskellHaskell, 94(削除) 94 (削除ここまで) 81 bytes

import System.Random
f n=do
 i<-randomRIO(1,n)
 if i<n
 then return i
 else (i+)<$>f n
import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n

Try it online! Try it online!

Quite similar to @dfeur's@dfeuer's, but using do notation.

Saved 13 bytes by removing whitespace, thanks to @dfeuer.

Haskell, 94 bytes

import System.Random
f n=do
 i<-randomRIO(1,n)
 if i<n
 then return i
 else (i+)<$>f n

Try it online!

Quite similar to @dfeur's, but using do notation.

Haskell, (削除) 94 (削除ここまで) 81 bytes

import System.Random
f n=do i<-randomRIO(1,n);if i<n then return i else(i+)<$>f n

Try it online!

Quite similar to @dfeuer's, but using do notation.

Saved 13 bytes by removing whitespace, thanks to @dfeuer.

added 2 characters in body
Source Link
bugs
  • 231
  • 1
  • 5

Haskell, 94 bytes

import System.Random
f n=do
 i<-randomRIO(1,n)
 if i<n
 then return i
 else (i+)<$>f n

Try it online!

Quite similar to @dfeur's, but using dodo notation.

Haskell, 94 bytes

import System.Random
f n=do
 i<-randomRIO(1,n)
 if i<n
 then return i
 else (i+)<$>f n

Try it online!

Quite similar to @dfeur's, but using do notation.

Haskell, 94 bytes

import System.Random
f n=do
 i<-randomRIO(1,n)
 if i<n
 then return i
 else (i+)<$>f n

Try it online!

Quite similar to @dfeur's, but using do notation.

Source Link
bugs
  • 231
  • 1
  • 5
Loading

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