A+ 13*b/c +d + 12*e -f -11 +g*h/i -10 == 66

Hello,

Founded 20 solutions with :

$c=0
puts “a b c d e f g h i”
puts “-----------------”
[1,2,3,4,5,6,7,8,9].permutation do |a,b,c,d,e,f,g,h,i|
next if (13b).divmod©.last!=0
next if (g
h).divmod(i).last!=0
if a+ 13b/c +d + 12e -f -11 +g*h/i -10 == 66
$c+=1
puts “#{a} #{b} #{c} #{d} #{e} #{f} #{g} #{h} #{i}”
end
end
puts “Count: #{$c}”

Is there some mistake ?

Regis d’Aubarede wrote in post #1174025:

In the formula, a and d are equivalent, g and h too.
so

==
puts “a b c d e f g h i\n-----------------”
count=(1…9).to_a.permutation.map do |l| a,b,c,d,e,f,g,h,i=l
next(nil) if (13
b).divmod©.last!=0
next(nil) if (gh).divmod(i).last!=0
next(nil) if a>d
next(nil) if g>h
next(nil) unless ((a+ 13
b/c +d + 12e -f -11 +gh/i -10) == 66)
puts l.join(" ")
1
end.compact.size
puts “Count: #{count}”

ruby cc.rb
a b c d e f g h i


3 2 1 5 4 7 8 9 6
5 3 1 7 2 6 8 9 4
5 4 1 9 2 7 3 8 6
5 9 3 6 2 1 7 8 4
6 3 1 9 2 5 7 8 4
Count: 5

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs