Created
June 20, 2022 10:45
-
-
Save tompng/4fd48db28bfe089f2fe631184fa456b5 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
# https://twitter.com/potetoichiro/status/1538130783785095173 を見て遊んでみた | |
hoge=(11..99).select{_1%10!=0}.to_h do |num| | |
a, b = num.divmod 10 | |
nums = (1..9).to_a | |
combinations = nums.repeated_permutation(4).select do |a2, a3, b2, b3| | |
num == a * b + a2 * b2 + a3 * b3 | |
end | |
[num, combinations.map{|a2,a3,b2,b3|[[a,a2,a3],[b,b2,b3]]}] | |
end | |
nums=(1..9).to_a | |
ltors = 3.times.map{|i| | |
3.times.map{|j| | |
nums.repeated_permutation(3).to_h do |l| | |
[l, | |
nums.repeated_permutation(3).select{|r| | |
l[0]*r[0]+l[1]*r[1]+l[2]*r[2]==l[i]*10+r[j] | |
} | |
] | |
end | |
} | |
};1 | |
cnt=0 | |
l1l2s = [] | |
max=[*1..9].repeated_permutation(6).size | |
[*1..9].repeated_permutation(6).each do |nums| | |
cnt+=1 | |
l1, l2, l3 = nums.each_slice(3).to_a | |
as=ltors[0][0][l1]<ors[0][1][l2] | |
bs=ltors[1][0][l1]<ors[1][1][l2] | |
cs=ltors[2][0][l1]<ors[2][1][l2] | |
puts "#{cnt}/#{max}" if cnt%10000==0 | |
if as&&bs&&cs&&as.size>0&&bs.size>0&&cs.size>0 | |
l1l2s<<[l1,l2] | |
end | |
end | |
max=l1l2s.size | |
answers_left = {};cnt=0;l1l2s.each do |(l1,l2)| | |
cnt+=1 | |
as=ltors[0][0][l1]<ors[0][1][l2] | |
bs=ltors[1][0][l1]<ors[1][1][l2] | |
cs=ltors[2][0][l1]<ors[2][1][l2] | |
l3a = ltors[0][2].reject{(_2 & as).empty?}.keys | |
next if l3a.empty? | |
l3b = ltors[1][2].reject{(_2 & bs).empty?}.keys | |
next if l3b.empty? | |
l3c = ltors[2][2].reject{(_2 & cs).empty?}.keys | |
next if l3c.empty? | |
puts "#{cnt}/#{max}" if cnt%100==0 | |
(l3a&l3b&l3c).each do |l3| | |
as_=as<ors[0][2][l3] | |
bs_=bs<ors[1][2][l3] | |
cs_=cs<ors[2][2][l3] | |
if as_&&bs_&&cs_&&as_.size>0&&bs_.size>0&&cs_.size>0 | |
answers_left[l1+l2+l3]=true | |
end | |
end | |
end | |
answers_left = answers_left.keys | |
puts "combinations: #{answers_left.size}" | |
answers_left.each do |nums| | |
l1, l2, l3 = nums.each_slice(3).to_a | |
r1=(ltors[0][0][l1]<ors[0][1][l2]<ors[0][2][l3]).first | |
r2=(ltors[1][0][l1]<ors[1][1][l2]<ors[1][2][l3]).first | |
r3=(ltors[2][0][l1]<ors[2][1][l2]<ors[2][2][l3]).first | |
p [l1,l2,l3,r1,r2,r3] if [l1,l2,l3]==[[4,3,2],[5,4,3],[9,7,5]] | |
end | |
binding.irb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment