- Reto #8
- Fecha publicación enunciado: 18/02/22
- Dificultad: FÁCIL
- Origen: https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge8.kt
Crea un programa se encargue de transformar un número decimal a binario sin utilizar funciones propias del lenguaje que lo hagan directamente.
# See https://www.geeksforgeeks.org/decimal-binary-number-using-recursion/
defmodule Convert do
def binary(dec) when dec == 0 do
0
end
def binary(dec) do
rem(dec, 2) + 10 * binary(div(dec, 2))
end
end
{:module, Convert, <<70, 79, 82, 49, 0, 0, 6, ...>>, {:binary, 1}}
defmodule Solution do
def run(number) do
Convert.binary(number)
end
end
{:module, Solution, <<70, 79, 82, 49, 0, 0, 6, ...>>, {:run, 1}}
Solution.run(420) == 110_100_100
true