ocaml: phase 5.1 roman.ml baseline + top-level 'let () = expr'
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Side-quest emerged from adding roman.ml baseline (Roman numeral greedy
encoding): top-level 'let () = expr' was unsupported because
ocaml-parse-program's parse-decl-let consumed an ident strictly. Now
parse-decl-let recognises a leading '()' as a unit binding and
synthesises a __unit_NN name (matching how parse-let already handles
inner-let unit patterns).
roman.ml exercises:
* tuple list literal [(int * string); ...]
* recursive pattern match on tuple-cons
* String.length + List.fold_left
* the new top-level let () support (sanity in a comment, even though
the program ends with a bare expression for the test harness)
Bumped lib/ocaml/test.sh server timeout 180->360s — the recent surge in
test count plus a CPU-contended host was crowding out the sole epoch
reaching the deeper smarts.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
"poly_stack.ml": 5,
|
||||
"queens.ml": 2,
|
||||
"quicksort.ml": 44,
|
||||
"roman.ml": 44,
|
||||
"sum_squares.ml": 385,
|
||||
"word_count.ml": 3
|
||||
}
|
||||
|
||||
20
lib/ocaml/baseline/roman.ml
Normal file
20
lib/ocaml/baseline/roman.ml
Normal file
@@ -0,0 +1,20 @@
|
||||
let to_roman n =
|
||||
let pairs = [
|
||||
(1000, "M"); (900, "CM"); (500, "D"); (400, "CD");
|
||||
(100, "C"); (90, "XC"); (50, "L"); (40, "XL");
|
||||
(10, "X"); (9, "IX"); (5, "V"); (4, "IV"); (1, "I")
|
||||
] in
|
||||
let rec aux n pairs acc =
|
||||
match pairs with
|
||||
| [] -> acc
|
||||
| (v, s) :: rest ->
|
||||
if n >= v then aux (n - v) pairs (acc ^ s)
|
||||
else aux n rest acc
|
||||
in
|
||||
aux n pairs ""
|
||||
;;
|
||||
|
||||
List.fold_left
|
||||
(fun acc n -> acc + String.length (to_roman n))
|
||||
0
|
||||
[1; 4; 9; 14; 49; 99; 444; 1994; 3888]
|
||||
@@ -1147,7 +1147,16 @@
|
||||
(when (at-kw? "rec") (begin (advance-tok!) (set! reccy true)))
|
||||
(define parse-one!
|
||||
(fn ()
|
||||
(let ((nm (ocaml-tok-value (consume! "ident" nil)))
|
||||
(let ((nm (cond
|
||||
((and (at-op? "(")
|
||||
(< (+ idx 1) tok-len)
|
||||
(let ((t1 (nth tokens (+ idx 1))))
|
||||
(and (= (ocaml-tok-type t1) "op")
|
||||
(= (ocaml-tok-value t1) ")"))))
|
||||
(begin (advance-tok!) (advance-tok!)
|
||||
(str "__unit_" idx)))
|
||||
(else
|
||||
(ocaml-tok-value (consume! "ident" nil)))))
|
||||
(ps (list)))
|
||||
(begin
|
||||
(define collect-params
|
||||
|
||||
@@ -1196,7 +1196,7 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
|
||||
check() {
|
||||
local epoch="$1" desc="$2" expected="$3"
|
||||
|
||||
Reference in New Issue
Block a user