Download examples/contestants/alice/hasher.ex from Snapkitty/forge-code: direct link, hf CLI and curl.
- Browser
- Download file 821 Bytes
-
https://huggingface.co/datasets/Snapkitty/forge-code/resolve/main/examples/contestants/alice/hasher.ex
- Command line
-
hf download hf://datasets/Snapkitty/forge-code/examples/contestants/alice/hasher.ex
-
curl -L -o hasher.ex https://huggingface.co/datasets/Snapkitty/forge-code/resolve/main/examples/contestants/alice/hasher.ex
821 Bytes
| defmodule Alice.Hasher do | |
| @moduledoc """ | |
| Alice's implementation of the integer hashing challenge. | |
| Uses built-in crypto functions for SHA-256. | |
| """ | |
| @doc """ | |
| Computes SHA-256 hash of a string. | |
| """ | |
| def sha256(input) do | |
| input | |
| |> :crypto.hash(:sha256) | |
| |> Base.encode16(case: :lower) | |
| end | |
| @doc """ | |
| Sums a list of integers. | |
| """ | |
| def sum_list(list) do | |
| Enum.reduce(list, 0, &(&1 + &2)) | |
| end | |
| @doc """ | |
| Computes factorial recursively. | |
| """ | |
| def factorial(0), do: 1 | |
| def factorial(n), do: n * factorial(n - 1) | |
| @doc """ | |
| Main entry point that routes to the appropriate function. | |
| """ | |
| def solve(:sha256, input), do: sha256(input) | |
| def solve(:sum_list, input), do: sum_list(input) | |
| def solve(:factorial, input), do: factorial(input) | |
| def solve(_challenge, _input), do: nil | |
| end | |