Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created January 5, 2021 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/29d8bff6b73877b0bad8a92225601dd4 to your computer and use it in GitHub Desktop.
Save JoshCheek/29d8bff6b73877b0bad8a92225601dd4 to your computer and use it in GitHub Desktop.
Finally figured out this challenge from Clash of Code
# https://www.codingame.com/clashofcode/clash/report/15311917e86988f7c91d80a62ec9bf1022c0607
# It's a multiplexer, first bits select an output bit from the remaining bits.
# Only one person actually figured it out, and the others seem to think that person is a bot, so :shrug:
DATA.read.split("\n\n").map(&:lines).each do |test|
width, num_rows = test.shift.split.map(&:to_i)
rows = test.take(num_rows)
expecteds = test.drop(num_rows).map(&:chomp)
outputs = rows.map do |row|
# first $width bits choose which of the remaining bits we select
index = row[0, width].to_i(2)
bits = row[width, 2**width]
bits[index]
end
outputs == expecteds # => true, true, true, true, true, true, true, true, true
end
__END__
2 2
101001
111001
0
1
2 3
111001
110001
110000
1
1
0
1 18
110
110
110
110
101
001
001
001
001
010
110
110
110
110
101
001
010
110
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
0
1
0
2 10
100000
010000
100000
100000
000000
010000
000000
110000
110000
100000
0
0
0
0
0
0
0
0
0
0
3 16
00011000000
00111100000
01001110000
01100111000
10000011100
10100001110
11000000111
11100000011
11000000111
10100001110
10000011100
01100111000
01001110000
00111100000
00011000000
11111100000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
3 20
01000100000
01000100000
01100010000
01100010000
01100010000
10000001000
01100010000
01000100000
01000100000
01100010000
10000001000
10100000100
11000000010
11000000010
11000000010
11000000010
10100000100
10000001000
10000001000
01100010000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1 16
101
101
110
100
111
000
010
000
001
010
001
010
100
111
100
110
1
1
0
0
1
0
1
0
0
1
0
1
0
1
0
0
3 24
00001110110
00101110010
01001110111
01101101010
10011010010
10111110000
11001011001
11100001110
00000000111
00111010001
01011111000
01101001000
10000001101
10101000110
11001010000
11111000110
00011000011
00100000100
01011111101
01110110111
10010010010
10110101111
11011000011
11110001110
0
1
1
0
0
0
0
0
0
1
1
0
1
1
0
0
1
0
1
1
0
1
1
0
8 15
000100010001001110001001110001000000011001010101010011101000110101110011000101100101101011001101011000101010010110010101110000011100111011000100001001101111100100001000001100011011000000000110101111001101011010000101110011010111000101000000101111000110110000100111
101011100101101111111100001000101001011001000111000101001000010010010010011001101000110011000100010011100100010101011110101111101001110100100110101010110000000110001111011100000101000110100110010111001010100011111100010000011100101111010001011001101100110100101011
010101010011111001101000000100100000001010111100010101010100100000010001011100010010110111000110111100100001001011101100101111100010110111110110000011100100110110001001010001000011110000100000010001101100011010011001101110101100001110000100010000000011101011010011
011001011011010000011010100111001111000000101100000110101101010011110100010101001111101011000100011111100001011001111001001000010111001001000000101110101111011000101001001111100100010010000011111100010001010111001001110100101111101110010010100101010010111001110000
100000110000110000010010101100111001101110011001010111101110101110101101100010100100010101001101011011010000000001110011011000110001010100001000101001110000011011110100010110100101111001111010111001001110110010010001011110011110011001110001000001011101000110001010
111011000011000001011010010001010101101000101111011010101110111000110110101010101010010011000010001001111100011101111100110111010011010001001111001111011110001111111110110100100100100001011011101100101100101010110001101011100011000000011010000101111101101101011010
001010000101000111011100110001011111010011101000100011111110011111011111001111100000110111010010110001101001001011000100011000111011111111100001100011110100101010010001001011101101000011110110101011000101101001001101010010100110010100001100101010100010111001110000
010011001010100110100111100101001011111011000111001101100101000101010101111011110110011011100101010110010001011100001111110000111111010101100101111100110010011001011000000010101011000101110000011000001100001010101100010111000001001111110101101111110011011000011100
001001101100000111111110011111101100110000100100101010001011110010011001011110010010100011010101001110101101101100110111111100110110111010000110110010110111001001101110111101110010001111100001111110010010000000100000010001010011110110011011110110100110110010111101
010110001010000001010110101011100110110110110101010100011000111101001111100110110110110000010000010011111001001011011101101000010000111010100001010010001010110011001100110100110011000001000011000101001100000100010011111110000000011000101000010000100100110000101110
001011100011101011010010000000001111001110101000110001000010111010110101100011111101100110101110011110100110111101101010111101100000011000001001110110111101111000101100011001111001100010100101110110101000001000110101001110010101110010101111101001011011010110000111
110001111010011011001010110110001001100100101111011100000110111010001001110100101011110001001101011101011010101110000100111111100010111001010111010000000110011010000011001000111101000001010100100011110011010001001110000010101011010101011101001111101011100111010110
100011000110110111101111100100010001100010011011111011111001011011011111100010110010101100011011101010101000111111100001001010000011010101100110010000100001011001011100100010010111101010010101001010010101011010111101101001010011100011100010111010010101010010100010
110001111100100011111011111110010011011011111011001111011010000000001101110110000011011101010100111101011001011110110001110100010001100101100000010101000100110111011111110000001110011000000011111100110010100011100111101010001011110100111101111100111011110001000001
110110000101000110010000010011101100010001100100000110000101110001101000110111111100100101101001111111100011110011010110010101011001000110011101100011100000111101100111101001110100100010111101111000010010111011011101010111000001111010111100010011110001001110101110
1
0
1
1
0
0
1
0
0
0
0
0
0
0
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment