Rename pointer to cursor
This commit is contained in:
parent
c0fbc2db0b
commit
dc9f85c779
20
ocaml/6.ml
20
ocaml/6.ml
|
@ -1,30 +1,30 @@
|
|||
#use "lib/utils.ml" ;;
|
||||
|
||||
type pointer = {ring: char List.t; pos: int} ;;
|
||||
type cursor = {ring: char List.t; pos: int} ;;
|
||||
|
||||
let find_marker seq width =
|
||||
let find_marker' ptr i c =
|
||||
if ptr.pos > 0 then ptr
|
||||
let find_marker' cur i c =
|
||||
if cur.pos > 0 then cur
|
||||
else
|
||||
let rec chars_repeat = function
|
||||
| [] -> false
|
||||
| hd :: tl -> List.exists ((=) hd) tl || chars_repeat tl
|
||||
in
|
||||
let ring =
|
||||
if List.length ptr.ring = width
|
||||
then List.tl ptr.ring @ [c]
|
||||
else ptr.ring @ [c]
|
||||
if List.length cur.ring = width
|
||||
then List.tl cur.ring @ [c]
|
||||
else cur.ring @ [c]
|
||||
in
|
||||
let pos =
|
||||
if List.length ptr.ring = width && not(chars_repeat ptr.ring)
|
||||
if List.length cur.ring = width && not(chars_repeat cur.ring)
|
||||
then i + 1
|
||||
else 0
|
||||
in
|
||||
{ring = ring; pos = pos}
|
||||
in
|
||||
let ptr = {ring = []; pos = 0} in
|
||||
let ptr = Seq.fold_lefti find_marker' ptr seq in
|
||||
ptr.pos
|
||||
let cur = {ring = []; pos = 0} in
|
||||
let cur = Seq.fold_lefti find_marker' cur seq in
|
||||
cur.pos
|
||||
in
|
||||
|
||||
let contents = read_file "inputs/6.txt" in
|
||||
|
|
Loading…
Reference in New Issue