Skip to content

Instantly share code, notes, and snippets.

@HarryMcCarney
Created January 2, 2023 13:50
Show Gist options
  • Save HarryMcCarney/a78cf620206ce630e68d6f6b691b3a25 to your computer and use it in GitHub Desktop.
Save HarryMcCarney/a78cf620206ce630e68d6f6b691b3a25 to your computer and use it in GitHub Desktop.
////Helper functions////
let getTrianglesAndCoPrimes n =
if n % 2 = 0 then (n*(n+1)/2, (n/2), (n+1))
else (n*(n+1)/2,((n+1)/2), n)
let getDivisors n =
let rec loopAndCheck n i divisors =
if i > n/2 then divisors |> Set.ofArray
elif n % i = 0 then loopAndCheck n (i+1) (Array.append divisors [|i|])
else loopAndCheck n (i+1) divisors
loopAndCheck n 1 [||]
let checkCoPrime n1 n2 =
not (getDivisors n1
|> Set.intersect (getDivisors n2)
|> Set.exists (fun x -> x <> 1))
////Actual calculation////
[|1..100000|]
|> Array.map getTrianglesAndCoPrimes
|> Array.map (fun (x, y, z) -> checkCoPrime y z)
|> Array.filter (fun x -> x = false) // should be an empty array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment