From 76cc6f3ab0b6fd04b6eea37c04e4975b3c5c76cc Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 23 Jan 2025 15:34:21 +0100 Subject: Experiment of golfing Wilson's theorem --- samples/fun/wilsons_primes.bruijn | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 samples/fun/wilsons_primes.bruijn (limited to 'samples/fun') diff --git a/samples/fun/wilsons_primes.bruijn b/samples/fun/wilsons_primes.bruijn new file mode 100644 index 0000000..2bdf886 --- /dev/null +++ b/samples/fun/wilsons_primes.bruijn @@ -0,0 +1,17 @@ +# 208-bit golfed characteristic prime sequence using Wilson's theorem +# (Tromp's prime sieve only takes 143 bit) + +# b' not-zero? mod +zmod [[1 [0 [[1]]] (1 [1 [[[0 (2 [[1]]) 1]]] [1] [[0]]] [[[0]]]) [[0]]]] + +zero? [0 [[[0]]] [[1]]] ⧗ Unary → Boolean + +# experiment with repeated subtraction (flipped args, zero? not golfed yet) +# TODO: consider Parigot for trivial predecessor? +zmod' [[0 0] [[[zero? (0 3 1) (2 2 (0 1 3)) (zero? 1)] sub]]] + sub [[0 [[[2 [[0 (1 3)]] [1] [0]]]] 1]] + +# y [[[(zmod 1 0) : (2 (1 ⋅ (0 ⋅ 0)) ++0)]]] (+1u) (+1u) +loop [0 0] [[[[0 (2 [0 [[1]]] (2 [2 [[[0 (2 [[1]]) 1]]] [1] [[0]]] [[[0]]]) [[0]]) (3 3 [3 (2 (2 0))] [[1 (3 1 0)]])]]]] (+1u) (+1u) + +main [loop] -- cgit v1.2.3