na ez mit csinál
Code
// v6
let WunderCode (a: int[]) (A: int[]) (tops: int[]) =
if a.Length <> A.Length then failwith "InvalidArgumentExceptionYouIdiot"
if a |> Array.exists(fun item -> item < 0) then failwith "AreYouEvenSweden?"
let add n m top =
match n + m with
| v when v % top + 1 > 0 -> (v / top, v % top)
| _ -> (0, n+m)
let rec ursion d =
match d with
| v when v = a.Length-1 ->
[ add a.[d] A.[d] tops.[d] ]
| v ->
let dv = ursion (d+1)
let f = fst dv.[dv.Length - 1]
let (cr, cv) = add (f + a.[d]) A.[d] tops.[d]
[(cr, cv)] |> List.append dv
let data = ursion 0 |> List.rev
List.choose (fun elem ->
match elem with
| v -> Some(snd elem)
) data |> List.append [fst data.[0]]