diff options
| author | eunhhu <[email protected]> | 2026-10-05 13:24:59 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-05 13:24:59 +0100 |
| commit | 6b4580607efa698abdc07718f00c6cbdb425c210 (patch) | |
| tree | 0cad9cddfd332140ecce47d17e439573f32ea11e /research/experiments/040-against-c/sort.aup | |
| parent | 5a3466e8ff4d8f3c4271719b90858b7d08697dcd (diff) | |
| download | pure-6b4580607efa698abdc07718f00c6cbdb425c210.tar.gz pure-6b4580607efa698abdc07718f00c6cbdb425c210.zip | |
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
Diffstat (limited to 'research/experiments/040-against-c/sort.aup')
| -rw-r--r-- | research/experiments/040-against-c/sort.aup | 34 |
1 files changed, 34 insertions, 0 deletions
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 +} |
