Created
January 17, 2023 11:38
-
-
Save frobs/278190b8090bc817c6ff524dc33de830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyTestScript do | |
@h 7 | |
@fixed_value 37 | |
def decode(num) do | |
decode_internal(num, "") | |
end | |
defp decode_internal(num, accum) when num == @h do | |
String.reverse(accum) | |
end | |
defp decode_internal(num, accum) do | |
conversion_table = %{3 => "e", 1 => "c", 6 => "i", 9 => "n"} | |
value = rem(num, @fixed_value) | |
next_num = get_next_num(num, value) | |
decode_internal(next_num, accum <> Map.get(conversion_table, value)) | |
end | |
defp get_next_num(num, subtraction) do | |
trunc((num - subtraction) / @fixed_value) | |
end | |
end | |
IO.puts(MyTestScript.decode(13583258)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment