Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $results = { :ignore => [], :include => [], 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,1,3,6].reverse()
- for i in 0..4
- 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...32
- array = dec_to_array(i)
- sum = sum_array(array)
- if (sum > 9 || i >> 3 == 3)
- $results[:ignore].push(i)
- else
- $results[:include].push(i)
- # Fill out bit-results
- for j in 0..3
- a = 2.pow(j)
- if (sum & a == a)
- $results[a].push(i)
- end
- end
- end
- end
- File.open("./tens_combos.txt", 'w') { |file|
- file.puts "32 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 = 11'3' + 1'13' + 1'1'3 + 113
- # 2-bit
- # F = 1'2'1'36' + 1'2'3'6 + 113'6' + 23'6' + 11'6 + 213
- # 4-bit
- # F = 1'2'3'6 + 11'6 + 13 + 23 + 13(second 1)
- # 8-bit
- # F = 116 + 26 + 36
Add Comment
Please, Sign In to add comment