package knights_tour

  1. Overview
  2. Docs
Solves the 'Knights Tour' and various 'Poyomino' puzzles

Install

Dune Dependency

Authors

Maintainers

Sources

knights_tour-0.0.4.tbz
sha256=dbaafd55fab8dd6a693878310c645c402d7c91e05d62819ae7913908ac17cdf1
sha512=e33e38572ba2e42b876915a74f8e9688a84666d61bc94fa2035d16f2fc6d5bf79d6cc5a2ac1a88d1aa28d8878ec035836df2d7919d2fe9dcd133e1259943ecef

doc/src/knights_tour/Lines.ml.html

Source file Lines.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
type t = string Seq.t

type 'a loader = string -> t -> 'a

let rec of_channel input () = 
  try (
    let line = input_line input in
    Seq.Cons(line, (of_channel input))
  ) 
  with End_of_file -> Seq.Nil
  
let rec load_list terminator item_loader first_line input =
  if first_line=terminator then
    []
  else
    let first = item_loader first_line input in
    match Seq.uncons input with
    | None -> failwith "Unexpected end of input"
    | Some (first_line, input) ->
        first :: load_list terminator item_loader first_line input

let load_line first_line _input = first_line
  
let of_string s = 
  let elements = ref (String.split_on_char '\n' s) in
  Seq.of_dispenser (fun () ->
    match !elements with
    | [] -> None
    | x::xs -> elements := xs; Some x 
  )

let load loader lines = 
  match Seq.uncons lines with
  | None -> failwith "Unexpected end of input"
  | Some (first_line, lines) -> loader first_line lines
OCaml

Innovation. Community. Security.