Created
June 12, 2022 13:26
-
-
Save hovsater/16fd374b8e92a2eeca08c112b01e3afe 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
module Kata exposing (fromNb2Str) | |
fromNb2Str n modsys = | |
let | |
gcd : Int -> Int -> Int | |
gcd a b = | |
if b == 0 then | |
a | |
else | |
gcd b (modBy b a) | |
lcm : Int -> Int -> Int | |
lcm a b = | |
(a * b) // gcd a b | |
isPairwiseCoprime : Int -> List Int -> Bool | |
isPairwiseCoprime prod xs = | |
List.foldl (\acc x -> lcm x acc) 1 xs == prod | |
product : Int | |
product = | |
List.product modsys | |
in | |
if isPairwiseCoprime product modsys && product > n then | |
"-" ++ (modsys |> List.map (\m -> modBy m n |> String.fromInt) |> String.join "--") ++ "-" | |
else | |
"Not applicable" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment