Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $results = { :ignore => [], 1 => [], 2 => [], 4 => [], 8 => [] }
- def sum_array (numbers)
- n = 0
- for i in 0...numbers.length
- n += numbers[i]
- end
- return n
- end
- def dec_to_array (n)
- array = []
- numbers = [1,2,4,8,6,2,4].reverse()
- for i in 0..6
- a = 2.pow(i)
- if (n & a == a)
- array.push(numbers[i])
- end
- end
- return array
- end
- # Calculate included and excluded values
- for i in 0...128
- array = dec_to_array(i)
- sum = sum_array(array)
- ones = sum % 10
- if (sum > 99)
- $results[:ignore].push(i)
- else
- # Fill out bit-results
- for j in 0..3
- a = 2.pow(j)
- if (ones & a == a)
- $results[a].push(i)
- end
- end
- end
- end
- File.open("./ones_combos.txt", 'w') { |file|
- file.puts "128 total combinations"
- for i in 0...$results.keys.length
- result = $results[$results.keys[i]]
- file.puts "------------|| #{$results.keys[i]} (#{result.length} combos) ||------------"
- for j in 0...result.length
- dec = result[j]
- file.puts "#{dec_to_array(dec).to_s} = #{dec}"
- end
- end
- file.puts "\n"
- for i in 0...$results.keys.length
- result = $results[$results.keys[i]]
- file.puts "------------|| #{$results.keys[i]} (#{result.length} combos) ||------------"
- for j in 0...result.length
- file.print "#{result[j]}"
- if (j < result.length - 1)
- file.print(",")
- end
- end
- file.print("\n")
- end
- }
- # MAPPING RESULTS
- # 1-bit
- # F = 1
- # 2-bit
- # F = 2'4'8'62'4' + 24'862'4' + 2'4'8624' + 248'6'24 + 24'8'6'2' + 2'4'8'6'2 + 248'2'4' + 2'486'2' + 2'48'24' + 2'86'2'4 + 24'86'2 + 28'62'4 + 2'482'4 + 2'8'624 + 24824' + 28624
- # 4-bit
- # F = 24'8'6'24' + 2'486'2'4 + 248'624' + 24'8'624 + 2'48'6'4' + 2'4'62'4' + 2'4'8'6'4 + 246'2'4' + 24'6'2'4 + 4'862'4' + 2'4'864' + 486'24' + 2'48'64 + 4'86'24 + 2462'4 + 48624
- # 8-bit
- # F = 2'4'86'2'4' + 24'8'62'4' + 2'48'6'2'4 + 2'4'8'624' + 248'6'24' + 24'8'6'24 + 2'4862'4' + 2'4'862'4 + 2486'2'4 + 24'8624' + 2'486'24 + 248'624
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement