Guest User

Untitled

a guest
Dec 11th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. let input = @"1364|461|1438|1456|818|999|105|1065|314|99|1353|148|837|590|404|123
  2. 204|99|235|2281|2848|3307|1447|3848|3681|963|3525|525|288|278|3059|821
  3. 280|311|100|287|265|383|204|380|90|377|398|99|194|297|399|87
  4. 7698|2334|7693|218|7344|3887|3423|7287|7700|2447|7412|6147|231|1066|248|208
  5. 3740|837|4144|123|155|2494|1706|4150|183|4198|1221|4061|95|148|3460|550
  6. 1376|1462|73|968|95|1721|544|982|829|1868|1683|618|82|1660|83|1778
  7. 197|2295|5475|2886|2646|186|5925|237|3034|5897|1477|196|1778|3496|5041|3314
  8. 179|2949|3197|2745|1341|3128|1580|184|1026|147|2692|212|2487|2947|3547|1120
  9. 460|73|52|373|41|133|671|61|634|62|715|644|182|524|648|320
  10. 169|207|5529|4820|248|6210|255|6342|4366|5775|5472|3954|3791|1311|7074|5729
  11. 5965|7445|2317|196|1886|3638|266|6068|6179|6333|229|230|1791|6900|3108|5827
  12. 212|249|226|129|196|245|187|332|111|126|184|99|276|93|222|56
  13. 51|592|426|66|594|406|577|25|265|578|522|57|547|65|564|622
  14. 215|2092|1603|1001|940|2054|245|2685|206|1043|2808|208|194|2339|2028|2580
  15. 378|171|155|1100|184|937|792|1436|1734|179|1611|1349|647|1778|1723|1709
  16. 4463|4757|201|186|3812|2413|2085|4685|5294|5755|2898|200|5536|5226|1028|180"
  17.  
  18. let splitBy (sep:string) (raw:string)= raw.Split(sep.ToCharArray())
  19. let newlineWithReturn = "\r\n"
  20. let tab = "|"
  21. let diff s = Seq.max s - Seq.min s
  22. let quo s =
  23. let l = s |> List.ofSeq
  24. let rec d e q l =
  25. match l with
  26. | [] -> q
  27. | h :: t ->
  28. match h with
  29. | _ when e <> h && e % h = 0 -> e / h
  30. | _ -> d e q t
  31. l |> List.filter (fun e -> d e 0 l <> 0) |> List.head
  32.  
  33. let answer1 =
  34. input |> splitBy newlineWithReturn
  35. |> Array.sumBy (fun line -> line |> splitBy tab |> Seq.map int |> diff)
  36.  
  37. let answer2 =
  38. input |> splitBy newlineWithReturn
  39. |> Array.sumBy (fun line -> line |> splitBy tab |> Seq.map int |> quo)
Add Comment
Please, Sign In to add comment