module _13 open System open System.IO let getSum = let numbers = File.ReadAllLines(@"13.txt") let add i carry = let sum = carry + (Seq.sum (seq { for string in numbers do yield System.Int32.Parse(string.Substring(string.Length - i, 1)) } ) ) (sum % 10, int(sum / 10)) let unfold (i, carry) = if i = 51 then None else let (digit, nextCarry) = add i carry if i <> 50 then Some(digit.ToString(), (i+1, nextCarry)) else Some(nextCarry.ToString() + digit.ToString(), (i+1, nextCarry)) let number_string = Seq.unfold unfold (1, 0) |> Seq.reduce (fun current next -> next + current) let hard = number_string.Substring(0, 10) hard