Skip to content

Instantly share code, notes, and snippets.

@hovsater
Created June 12, 2022 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovsater/16fd374b8e92a2eeca08c112b01e3afe to your computer and use it in GitHub Desktop.
Save hovsater/16fd374b8e92a2eeca08c112b01e3afe to your computer and use it in GitHub Desktop.
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