Created
December 14, 2015 20:30
-
-
Save eam/4f80d5ecb0ce36516edc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$elements = { | |
:H => { :string => "22", :evolution => [:H], }, | |
:He => { :string => "13112221133211322112211213322112", :evolution => [:Hf,:Pa,:H,:Ca,:Li], }, | |
:Li => { :string => "312211322212221121123222112", :evolution => [:He], }, | |
:Be => { :string => "111312211312113221133211322112211213322112", :evolution => [:Ge,:Ca,:Li], }, | |
:B => { :string => "1321132122211322212221121123222112", :evolution => [:Be], }, | |
:C => { :string => "3113112211322112211213322112", :evolution => [:B], }, | |
:N => { :string => "111312212221121123222112", :evolution => [:C], }, | |
:O => { :string => "132112211213322112", :evolution => [:N], }, | |
:F => { :string => "31121123222112", :evolution => [:O], }, | |
:Ne => { :string => "111213322112", :evolution => [:F], }, | |
:Na => { :string => "123222112", :evolution => [:Ne], }, | |
:Mg => { :string => "3113322112", :evolution => [:Pm,:Na], }, | |
:Al => { :string => "1113222112", :evolution => [:Mg], }, | |
:Si => { :string => "1322112", :evolution => [:Al], }, | |
:P => { :string => "311311222112", :evolution => [:Ho,:Si], }, | |
:S => { :string => "1113122112", :evolution => [:P], }, | |
:Cl => { :string => "132112", :evolution => [:S], }, | |
:Ar => { :string => "3112", :evolution => [:Cl], }, | |
:K => { :string => "1112", :evolution => [:Ar], }, | |
:Ca => { :string => "12", :evolution => [:K], }, | |
:Sc => { :string => "3113112221133112", :evolution => [:Ho,:Pa,:H,:Ca,:Co], }, | |
:Ti => { :string => "11131221131112", :evolution => [:Sc], }, | |
:V => { :string => "13211312", :evolution => [:Ti], }, | |
:Cr => { :string => "31132", :evolution => [:V], }, | |
:Mn => { :string => "111311222112", :evolution => [:Cr,:Si], }, | |
:Fe => { :string => "13122112", :evolution => [:Mn], }, | |
:Co => { :string => "32112", :evolution => [:Fe], }, | |
:Ni => { :string => "11133112", :evolution => [:Zn,:Co], }, | |
:Cu => { :string => "131112", :evolution => [:Ni], }, | |
:Zn => { :string => "312", :evolution => [:Cu], }, | |
:Ga => { :string => "13221133122211332", :evolution => [:Eu,:Ca,:Ac,:H,:Ca,:Zn], }, | |
:Ge => { :string => "31131122211311122113222", :evolution => [:Ho,:Ga], }, | |
:As => { :string => "11131221131211322113322112", :evolution => [:Ge,:Na], }, | |
:Se => { :string => "13211321222113222112", :evolution => [:As], }, | |
:Br => { :string => "3113112211322112", :evolution => [:Se], }, | |
:Kr => { :string => "11131221222112", :evolution => [:Br], }, | |
:Rb => { :string => "1321122112", :evolution => [:Kr], }, | |
:Sr => { :string => "3112112", :evolution => [:Rb], }, | |
:Y => { :string => "1112133", :evolution => [:Sr,:U], }, | |
:Zr => { :string => "12322211331222113112211", :evolution => [:Y,:H,:Ca,:Tc], }, | |
:Nb => { :string => "1113122113322113111221131221", :evolution => [:Er,:Zr], }, | |
:Mo => { :string => "13211322211312113211", :evolution => [:Nb], }, | |
:Tc => { :string => "311322113212221", :evolution => [:Mo], }, | |
:Ru => { :string => "132211331222113112211", :evolution => [:Eu,:Ca,:Tc], }, | |
:Rh => { :string => "311311222113111221131221", :evolution => [:Ho,:Ru], }, | |
:Pd => { :string => "111312211312113211", :evolution => [:Rh], }, | |
:Ag => { :string => "132113212221", :evolution => [:Pd], }, | |
:Cd => { :string => "3113112211", :evolution => [:Ag], }, | |
:In => { :string => "11131221", :evolution => [:Cd], }, | |
:Sn => { :string => "13211", :evolution => [:In], }, | |
:Sb => { :string => "3112221", :evolution => [:Pm,:Sn], }, | |
:Te => { :string => "1322113312211", :evolution => [:Eu,:Ca,:Sb], }, | |
:I => { :string => "311311222113111221", :evolution => [:Ho,:Te], }, | |
:Xe => { :string => "11131221131211", :evolution => [:I], }, | |
:Cs => { :string => "13211321", :evolution => [:Xe], }, | |
:Ba => { :string => "311311", :evolution => [:Cs], }, | |
:La => { :string => "11131", :evolution => [:Ba], }, | |
:Ce => { :string => "1321133112", :evolution => [:La,:H,:Ca,:Co], }, | |
:Pr => { :string => "31131112", :evolution => [:Ce], }, | |
:Nd => { :string => "111312", :evolution => [:Pr], }, | |
:Pm => { :string => "132", :evolution => [:Nd], }, | |
:Sm => { :string => "311332", :evolution => [:Pm,:Ca,:Zn], }, | |
:Eu => { :string => "1113222", :evolution => [:Sm], }, | |
:Gd => { :string => "13221133112", :evolution => [:Eu,:Ca,:Co], }, | |
:Tb => { :string => "3113112221131112", :evolution => [:Ho,:Gd], }, | |
:Dy => { :string => "111312211312", :evolution => [:Tb], }, | |
:Ho => { :string => "1321132", :evolution => [:Dy], }, | |
:Er => { :string => "311311222", :evolution => [:Ho,:Pm], }, | |
:Tm => { :string => "11131221133112", :evolution => [:Er,:Ca,:Co], }, | |
:Yb => { :string => "1321131112", :evolution => [:Tm], }, | |
:Lu => { :string => "311312", :evolution => [:Yb], }, | |
:Hf => { :string => "11132", :evolution => [:Lu], }, | |
:Ta => { :string => "13112221133211322112211213322113", :evolution => [:Hf,:Pa,:H,:Ca,:W], }, | |
:W => { :string => "312211322212221121123222113", :evolution => [:Ta], }, | |
:Re => { :string => "111312211312113221133211322112211213322113", :evolution => [:Ge,:Ca,:W], }, | |
:Os => { :string => "1321132122211322212221121123222113", :evolution => [:Re], }, | |
:Ir => { :string => "3113112211322112211213322113", :evolution => [:Os], }, | |
:Pt => { :string => "111312212221121123222113", :evolution => [:Ir], }, | |
:Au => { :string => "132112211213322113", :evolution => [:Pt], }, | |
:Hg => { :string => "31121123222113", :evolution => [:Au], }, | |
:Tl => { :string => "111213322113", :evolution => [:Hg], }, | |
:Pb => { :string => "123222113", :evolution => [:Tl], }, | |
:Bi => { :string => "3113322113", :evolution => [:Pm,:Pb], }, | |
:Po => { :string => "1113222113", :evolution => [:Bi], }, | |
:At => { :string => "1322113", :evolution => [:Po], }, | |
:Rn => { :string => "311311222113", :evolution => [:Ho,:At], }, | |
:Fr => { :string => "1113122113", :evolution => [:Rn], }, | |
:Ra => { :string => "132113", :evolution => [:Fr], }, | |
:Ac => { :string => "3113", :evolution => [:Ra], }, | |
:Th => { :string => "1113", :evolution => [:Ac], }, | |
:Pa => { :string => "13", :evolution => [:Th], }, | |
:U => { :string => "3", :evolution => [:Pa], }, | |
} | |
num, iters = ARGV | |
def step_state s | |
new_state = Hash.new(0) | |
s.each_key do |old_element| | |
new_elements = $elements[old_element][:evolution] | |
count = s[old_element] | |
new_elements.each do |new_element| | |
new_state[new_element] += count | |
end | |
end | |
new_state | |
end | |
# element.length * element.count | |
def count_chars s | |
sum = 0 | |
s.each_pair do |element, count| | |
sum += $elements[element][:string].length * count | |
end | |
sum | |
end | |
element = $elements.select {|k,v| v[:string] == num }.keys.first | |
raise "can't find element for string" if element.empty? | |
puts "encoding #{num} which is element: #{element} with #{iters} iterations" | |
state = Hash.new(0) | |
state[element] = 1 | |
puts "start state: #{state}" | |
iters.to_i.times do |i| | |
state = step_state state | |
end | |
puts "end state: #{state}" | |
puts "count of end string length: #{count_chars state}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment