From 6b4580607efa698abdc07718f00c6cbdb425c210 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Mon, 5 Oct 2026 13:24:59 +0100 Subject: Research 124's suite: seven kinds of work in one event each (roots, knapsack, sort, join, words, matmul, BFS), each against the C one would write, in one process with the same inputs and answers; PURE_AHEAD=0 to measure the code without reading ahead --- research/experiments/040-against-c/sort.aup | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 research/experiments/040-against-c/sort.aup (limited to 'research/experiments/040-against-c/sort.aup') diff --git a/research/experiments/040-against-c/sort.aup b/research/experiments/040-against-c/sort.aup new file mode 100644 index 0000000..967b500 --- /dev/null +++ b/research/experiments/040-against-c/sort.aup @@ -0,0 +1,34 @@ +# Sorting (research 124's suite): n numbers drawn by MINSTD from seed 1 +# (distinct: its period is 2^31 - 2) into a list kept by them, then read in +# order: the smallest, the middle one, the largest, and how many follow a +# larger one (none when sorted). +record Key { + k = 0 +} +state first = 0 +state middle = 0 +state last = 0 +state disorder = 0 +input go = message { + n: u32 +} +on go { + let keys: list of Key by k + let x = 1 + for i in 0 .. go.n { + x = x * 48271 - floor(x * 48271 / 2147483647) * 2147483647 + keys.add(Key { k: x }) + } + let at = 0 + let before = -1 + let wrong = 0 + for e in keys { + if e.k < before { wrong = wrong + 1 } + if at == floor(go.n / 2) { middle = e.k } + before = e.k + at = at + 1 + } + first = keys.first.k + last = keys.last.k + disorder = wrong +} -- cgit v1.2.3