initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
module _33
|
||||
|
||||
open common
|
||||
|
||||
let cancelling =
|
||||
let nds = seq {
|
||||
for d in 11..99 do
|
||||
if d % 10 <> 0 then
|
||||
for n in 11..(d-1) do
|
||||
if n % 10 <> 0 then
|
||||
yield (n,d)
|
||||
}
|
||||
|
||||
let cancelCommonDigits (n,d) =
|
||||
let nd = numDigits n
|
||||
let dd = numDigits d
|
||||
seq {
|
||||
for ndi in nd do
|
||||
for ddi in dd do
|
||||
if ndi = ddi then
|
||||
let ndmi = Array.filter ((<>) ndi) nd
|
||||
let ddmi = Array.filter ((<>) ddi) dd
|
||||
if (ndmi.Length > 0 && ddmi.Length > 0) then
|
||||
yield (digitsNum ndmi, digitsNum ddmi)
|
||||
}
|
||||
|
||||
nds
|
||||
|> Seq.collect (fun (n,d) ->
|
||||
let f = float n/float d
|
||||
cancelCommonDigits (n,d)
|
||||
|> Seq.map (fun (cn,cd) -> (float cn/float cd,cn,cd,n,d))
|
||||
|> Seq.filter (fun (cf,_,_,_,_) -> cf = f)
|
||||
)
|
||||
|> Seq.fold (fun (pn, pd) (_,n,d,_,_) -> (pn * n, pd * d)) (1,1)
|
||||
|> Fraction.reduce
|
||||
|> snd
|
||||
|
||||
Reference in New Issue
Block a user