Skip to main content
Commonmark migration
Source Link

Brachylog, 8 bytes

ẉ?ℕ₁-₁ṙ↰

Try it online!

###Explanation

Explanation

ẉ          Write the input followed by a linebreak
 ?ℕ₁       The input must be in [1, …, +∞)
    -₁ṙ    Generate an integer in [0, …, input - 1] uniformly at random
       ↰   Recursive call with that random integer as the new input

The recursion will stop once ?ℕ₁ fails, that is, when the input is 0.

Brachylog, 8 bytes

ẉ?ℕ₁-₁ṙ↰

Try it online!

###Explanation

ẉ          Write the input followed by a linebreak
 ?ℕ₁       The input must be in [1, …, +∞)
    -₁ṙ    Generate an integer in [0, …, input - 1] uniformly at random
       ↰   Recursive call with that random integer as the new input

The recursion will stop once ?ℕ₁ fails, that is, when the input is 0.

Brachylog, 8 bytes

ẉ?ℕ₁-₁ṙ↰

Try it online!

Explanation

ẉ          Write the input followed by a linebreak
 ?ℕ₁       The input must be in [1, …, +∞)
    -₁ṙ    Generate an integer in [0, …, input - 1] uniformly at random
       ↰   Recursive call with that random integer as the new input

The recursion will stop once ?ℕ₁ fails, that is, when the input is 0.

Source Link
Fatalize
  • 39.3k
  • 5
  • 70
  • 162

Brachylog, 8 bytes

ẉ?ℕ₁-₁ṙ↰

Try it online!

###Explanation

ẉ          Write the input followed by a linebreak
 ?ℕ₁       The input must be in [1, …, +∞)
    -₁ṙ    Generate an integer in [0, …, input - 1] uniformly at random
       ↰   Recursive call with that random integer as the new input

The recursion will stop once ?ℕ₁ fails, that is, when the input is 0.