Skip to main content
deleted 12 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

Brachylog, 19 16 bytes

-3 thanks to @Unrelated String

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<
Ḋ                if n is in 0…9, return n
 |               otherwise
  ⟨f    h   g⟩   [f(n), g(n)] h
   ℕ        l    [n, digits] and n is a natural number
    {√₎|/|-}     try (root, divide, subtract) one after the other
                 (results that are not natural numbers will
                  get filtered in the next step with ℕ)
              ↰  recurse
               < get a number that is strictly larger, thus +1

Brachylog, 16 bytes

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<
Ḋ                if n is in 0…9, return n
 |               otherwise
  ⟨f    h   g⟩   [f(n), g(n)] h
   ℕ        l    [n, digits] and n is a natural number
    {√₎|/|-}     try (root, divide, subtract) one after the other
                 (results that are not natural numbers will
                  get filtered in the next step with ℕ)
              ↰  recurse
               < get a number that is strictly larger, thus +1

Brachylog, 19 16 bytes

-3 thanks to @Unrelated String

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<
Ḋ                if n is in 0…9, return n
 |               otherwise
  ⟨f    h   g⟩   [f(n), g(n)] h
   ℕ        l    [n, digits] and n is a natural number
    {√₎|/|-}     try (root, divide, subtract) one after the other
                 (results that are not natural numbers will
                  get filtered in the next step with ℕ)
              ↰  recurse
               < get a number that is strictly larger, thus +1
deleted 12 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

Brachylog, 1916 bytes

lℕ₂;?↔Ḋ|⟨ℕ{√₎|/|-}ℕ↰+₁|l⟩↰<

Try it online!Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

lℕ₂;?↔Ḋ|⟨ℕ{√₎|/|-}ℕ↰+₁|l⟩↰<
l                   number of digits
if ℕ₂n is in 0…9, return n
 |           must be at least 2otherwise
          ⟨f    h   g⟩ | otherwise [f(n ≤ 10) just return, g(n
  )] ;?h
           l    [digits[n, n]
     ↔         digits] and n is a [n,natural digits]number
      {√₎|/|-}      try (root, divide, subtract) one after the other:
                  (results that are not nnatural (root|division|subtraction)numbers digitswill
                  get thefiltered resultin mustthe benext astep naturalwith numberℕ)
    recurse
 call itself
             < get a +₁number that addis onestrictly tolarger, thethus steps+1

Brachylog, 19 bytes

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|
l                   number of digits
 ℕ₂                 must be at least 2
                  | otherwise (n ≤ 10) just return n
   ;?               [digits, n]
     ↔              [n, digits]
      {√₎|/|-}      try one after the other:
                      n (root|division|subtraction) digits
                   the result must be a natural number
     call itself
                +₁  add one to the steps

Brachylog, 16 bytes

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

Ḋ|⟨ℕ{√₎|/|-}l⟩↰<
                if n is in 0…9, return n
 |               otherwise
  ⟨f    h   g⟩   [f(n), g(n)] h
           l    [n, digits] and n is a natural number
    {√₎|/|-}     try (root, divide, subtract) one after the other
                 (results that are not natural numbers will
                  get filtered in the next step with ℕ)recurse
               < get a number that is strictly larger, thus +1
added 627 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

Brachylog, 19 bytes

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|
l                   number of digits
 ℕ₂                 must be at least 2
                  | otherwise (n ≤ 10) just return n
   ;?               [digits, n]
     ↔              [n, digits]
      {√₎|/|-}      try one after the other:
                      n (root|division|subtraction) digits
              ℕ     the result must be a natural number
               ↰    call itself
                +₁  add one to the steps

Brachylog, 19 bytes

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|

Try it online!

Brachylog, 19 bytes

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|

Try it online!

A recursive function. If n ≥ 10, the three operations are tried. For n < 10 we need n steps to 0. With this we don't have to check that step(n) ≠ n, as it only occurs when there is one digit.

lℕ₂;?↔{√₎|/|-}ℕ↰+₁|
l                   number of digits
 ℕ₂                 must be at least 2
                  | otherwise (n ≤ 10) just return n
   ;?               [digits, n]
     ↔              [n, digits]
      {√₎|/|-}      try one after the other:
                      n (root|division|subtraction) digits
              ℕ     the result must be a natural number
               ↰    call itself
                +₁  add one to the steps
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39
Loading