Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created February 9, 2018 22:33
Show Gist options
  • Save vznvzn/66a53d6f50fbbb6f5b867996cb3fa71d to your computer and use it in GitHub Desktop.
Save vznvzn/66a53d6f50fbbb6f5b867996cb3fa71d to your computer and use it in GitHub Desktop.
def f2(n)
return n.odd? ? (n * 3 + 1) / 2 : n / 2
end
def count(n)
n1 = n
l = [n]
begin
n = f2(n)
l << n
end while n > n1
m = (0...l.size).max_by { |x| l[x] }
r = l[m].to_s(2).length - n1.to_s(2).length
return {'c' => l.size, 'n' => n1, 'l' => l, 'm' => m, 'r' => r}
end
def group(f, t, u)
f1 = File.open("out#{t}a.txt", 'w')
f2 = File.open("out#{t}b.txt", 'w')
i = 0
u.each \
{
|n|
z = count(n)
z['l'][0..z['m']].each \
{
|x|
s = x.to_s(2).gsub('0', ' ').gsub('1', '#').reverse
f1.puts([i, x.to_s(2).length, s].join("\t"))
s.length.times \
{
|j|
x = s[j, 1]
f2.puts([i, j].join("\t")) if (x != ' ')
}
i += 1
}
f1.puts
i += 10
}
f1.close
f2.close
f.puts("plot 'out#{t}b.txt' pt 5 ps 0.2,'out#{t}a.txt' using 1:2 with line lw 4")
f.puts("pause -1")
end
u = [1188422437712810453548692144111,
1267645764524909143928782979055,
950718153992428974215671054331,
1267650599619486847064288002031,
1267263743928478267661447331823,
1267650600228157343902665277435,
1267650600228229120021726494715,
1187029374906136646647505215483,
1187566500367426151132698771451,
1262698840071087879262966906875,
1262079860601523887534124302319,
944544301776605808442996686831,
1267650600228229401492408238075,
1267650600227941171115988090875,
1089387196644627700395764875259,
1267631257415042911701410250747,
1267650600228229400946947391483,
1267650295626364506530572664827,
950737949837973124922201866223,
1208152107089751447308077105147,
1267495857723300714563831332859,
1267650524670365671184333275119,
1262620108772473765213857906683,
1168571863718606745625097666543,
950699264544943791451680538623,
]
f = File.open('gnuplot.cmd', 'w')
group(f, 0, u[0..4])
group(f, 1, u[5..9])
group(f, 2, u[10..14])
group(f, 3, u[15..19])
group(f, 4, u[20..24])
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment