123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- (* open IntInf; *)
- val newline_tokenizer = String.tokens (fn c => c = #"\n");
- val points_tokenizer = StringExtra.split " -> ";
- val comma_tokenizer = String.tokens (fn c => c = #",");
- val str = FileExtra.read "input";
- val lines = newline_tokenizer str;
- val points_as_str = map points_tokenizer lines;
- fun string_to_point str =
- let
- val parts = comma_tokenizer str;
- in
- if (length parts) = 2
- then
- let
- val a = hd parts;
- val b = hd (tl parts);
- val x = case Int.fromString a of
- SOME num => num
- | NONE => raise Fail "should not happen";
- val y = case Int.fromString b of
- SOME num => num
- | NONE => raise Fail "should not happen";
- in
- (x,y) : LineSegment.point
- end
- else
- raise Fail "not a point"
- end;
- fun make_segments nil = []
- | make_segments (points_as_str as (ps_as_strs::rest)) =
- let
- val (p1_str :: p2_str :: nil) = ps_as_strs;
- val p1 = string_to_point p1_str;
- val p2 = string_to_point p2_str;
- in
- LineSegment (p1, p2) :: (make_segments rest)
- end;
- val line_segments = make_segments points_as_str;
|