1
0
Fork 0

Rename pointer to cursor

This commit is contained in:
Gregory Eremin 2023-01-19 21:13:01 +01:00
parent c0fbc2db0b
commit dc9f85c779
1 changed files with 10 additions and 10 deletions

View File

@ -1,30 +1,30 @@
#use "lib/utils.ml" ;; #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 seq width =
let find_marker' ptr i c = let find_marker' cur i c =
if ptr.pos > 0 then ptr if cur.pos > 0 then cur
else else
let rec chars_repeat = function let rec chars_repeat = function
| [] -> false | [] -> false
| hd :: tl -> List.exists ((=) hd) tl || chars_repeat tl | hd :: tl -> List.exists ((=) hd) tl || chars_repeat tl
in in
let ring = let ring =
if List.length ptr.ring = width if List.length cur.ring = width
then List.tl ptr.ring @ [c] then List.tl cur.ring @ [c]
else ptr.ring @ [c] else cur.ring @ [c]
in in
let pos = 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 then i + 1
else 0 else 0
in in
{ring = ring; pos = pos} {ring = ring; pos = pos}
in in
let ptr = {ring = []; pos = 0} in let cur = {ring = []; pos = 0} in
let ptr = Seq.fold_lefti find_marker' ptr seq in let cur = Seq.fold_lefti find_marker' cur seq in
ptr.pos cur.pos
in in
let contents = read_file "inputs/6.txt" in let contents = read_file "inputs/6.txt" in