From a79414bcf14d17c58e040a7b8524f7bd8f7e5e03 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 22 Jan 2024 10:23:58 +0000 Subject: Migrate from gists --- cpc/cpc2.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cpc/cpc2.rb (limited to 'cpc/cpc2.rb') diff --git a/cpc/cpc2.rb b/cpc/cpc2.rb new file mode 100644 index 0000000..54d05c6 --- /dev/null +++ b/cpc/cpc2.rb @@ -0,0 +1,25 @@ +BITS = 8 + +class Integer + def rotate_left(bits, width = bit_width) + bits %= width + (self << bits | self >> (width - bits)) & ((1 << width) - 1) + end +end + +candidates = (0...(2**BITS)).to_a + +(2**BITS).times do |candidate| + next if candidates[candidate].nil? + (1...BITS).each do |bits| + candidates[candidate.rotate_left(bits, BITS)] = nil + end +end + +codewords = candidates.compact + +p codewords +puts codewords.length + +#=> [1, 3, 5, 7, 9, 11, 13, 15, 19, 21, 23, 25, 27, 29, 31, 37, 39, 43, 45, 47, 53, 55, 59, 61, 63, 87, 91, 95, 111, 127] +#=> 30 -- cgit v1.2.1