Return to Snippet

Revision: 1307
at September 27, 2006 11:01 by gdonald


Updated Code
#!/usr/bin/ruby

10.times do
  s = 0
  1.upto(9) do |x|
    1.upto(9) do |y|
      1.upto(9) do |z|
        if x + y + z == 15 && x != y && x != z && y != z
          1.upto(9) do |a|
            1.upto(9) do |b|
              1.upto(9) do |c|
                if( ( a + b + c == 15) && ( ( a != b ) && ( a != c ) && ( b != c ) ) )
                  1.upto(9) do |i|
                    1.upto(9) do |o|
                      1.upto(9) do |p|
                        if( ( i + o + p == 15 ) && ( ( i != o ) && ( i != p ) && ( o != p ) ) ) 
                          if( ( x + a + i == 15 ) && ( ( x != a ) && ( x != i ) && ( a != i ) ) )
                            if( ( y + b + o == 15 ) && ( ( y != b ) && ( y != o ) && ( b != o ) ) )
                              if( ( z + c + p == 15 ) && ( ( z != c ) && ( z != p ) && ( c != p ) ) )
                                if( ( x != b ) && ( x != c ) && ( x != o ) && ( x != p ) )
                                  if( ( y != a ) && ( y != i ) && ( y != c ) && ( y != p ) )
                                    if( ( z != b ) && ( z != a ) && ( z != o ) && ( z != i ) )
                                      s += 1
                                      $stdout.print "Solution ##{s}:\n"
                                      $stdout.print "#{x} #{y} #{z}\n"
                                      $stdout.print "#{a} #{b} #{c}\n"
                                      $stdout.print "#{i} #{o} #{p}\n\n"
                                    end
                                  end
                                end
                              end
                            end
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Revision: 1306
at September 27, 2006 11:00 by gdonald


Initial Code
#!/usr/bin/ruby

10.times do
  s = 0
  1.upto(9) do |x|
    1.upto(9) do |y|
      1.upto(9) do |z|
        if x + y + z == 15 && x != y && x != z && y != z
          1.upto(9) do |a|
            1.upto(9) do |b|
              1.upto(9) do |c|
                if( ( a + b + c == 15) && ( ( a != b ) && ( a != c ) && ( b != c ) ) )
                  1.upto(9) do |i|
                    1.upto(9) do |o|
                      1.upto(9) do |p|
                        if( ( i + o + p == 15 ) && ( ( i != o ) && ( i != p ) && ( o != p ) ) ) 
                          if( ( x + a + i == 15 ) && ( ( x != a ) && ( x != i ) && ( a != i ) ) )
                            if( ( y + b + o == 15 ) && ( ( y != b ) && ( y != o ) && ( b != o ) ) )
                              if( ( z + c + p == 15 ) && ( ( z != c ) && ( z != p ) && ( c != p ) ) )
                                if( ( x != b ) && ( x != c ) && ( x != o ) && ( x != p ) )
                                  if( ( y != a ) && ( y != i ) && ( y != c ) && ( y != p ) )
                                    if( ( z != b ) && ( z != a ) && ( z != o ) && ( z != i ) )
                                      s += 1
                                      $stdout.print "Solution ##{s}:\n"
                                      $stdout.print "#{x} #{y} #{z}\n"
                                      $stdout.print "#{a} #{b} #{c}\n"
                                      $stdout.print "#{i} #{o} #{p}\n\n"
                                    end
                                  end
                                end
                              end
                            end
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Initial URL

                                

Initial Description

                                

Initial Title
Ruby sudoku solver

Initial Tags

                                

Initial Language
Ruby