ocaml: phase 5.1 magic_square.ml baseline (5x5 Siamese, diag sum = 65)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Siamese construction for odd-order magic squares:

  - place 1 at (0, n/2)
  - for k = 2..n^2, move up-right with (x-1+n) mod n wrap
  - if the target cell is taken, drop down one row instead

  for n=5, magic constant = n*(n^2+1)/2 = 5*26/2 = 65

Returns the main-diagonal sum (65 by construction).

Tests 2D array via Array.init + Array.make, mod arithmetic with
the (x-1+n) mod n idiom for negative-safe wrap, nested begin/end
branches inside for-loop body.

166 baseline programs total.
This commit is contained in:
2026-05-10 23:28:29 +00:00
parent 689438d12e
commit 3fe3b7b66f
3 changed files with 37 additions and 0 deletions

View File

@@ -407,6 +407,15 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-10 Phase 5.1 — magic_square.ml baseline (5×5 Siamese
construction → main-diagonal sum 65, the magic constant for n=5).
Place k=1 at (0, n/2); for each next k, move up-right with wrap-
around; if that cell is taken, move down one row instead.
Magic constant for an n×n square is n(n²+1)/2 = 5·26/2 = 65.
Tests 2D array via Array.init + Array.make, mod arithmetic with
the `(x - 1 + n) mod n` idiom for negative-safe wrap, nested
begin/end branches inside for-loop body. 166 baseline programs
total.
- 2026-05-10 Phase 5.1 — matrix_power.ml baseline (Fibonacci via
2×2 matrix fast exponentiation, F(30) = 832040). [[1,1],[1,0]]^n
has Fibonacci numbers in the top row; recursive O(log n) power