Sha256: b5990659f533fb379d92821779b00e316b9adb6354660838210d7e02d319a524
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 KB
Contents
#!/usr/bin/env ruby lib_path = File.expand_path('../../lib', __FILE__) $:.unshift(lib_path) require 'sudokus' require 'sudokusolver' begin if ARGV[0] and !['-h','--help'].include? ARGV[0] case ARGV[0] when '--version', '-v' then raise Sudokus::VERSION when 'which' then system('gem which sudokusolver') when 'patch' then if ARGV[1] and File.exists?(ARGV[1]) File.open(ARGV[1], 'r') do |f| buff = f.read buff.gsub!('cols.each { |c| @unitlist.push(cross(rows, c)) }', '@cols.each { |c| @unitlist.push(cross(@rows, [c])) }') buff.gsub!('rows.each { |r| @unitlist.push(cross(r, cols)) }', '@rows.each { |r| @unitlist.push(cross([r], @cols)) }') File.open(ARGV[1], 'w') do |f2| f2.write(buff) end end puts 'patched.' else raise %q{ unknown path of sudokusolver.rb command `sudokus patch <path>` to patch command `sudokus which` to get the sudokusolver path and paste in <path>. } end else s = SudokuSolver.new s.print_grid(s.search(s.parse_grid(ARGV[0]))) end else raise %q{ Usage: sudokus -v/--version sudokus -h/--help sudokus NUMBER_STRING #Solve NUMBER_STRING [example] sudokus ..9748...7.........2.1.9.....7...24..64.1.59..98...3.....8.3.2.........6...2759.. sudokus patch SUDOKUSOLVER_PATH #Patch (NoMethodError) in sudokusolver [example] sudokus patch /usr/lib/ruby/gems/1.9.1/gems/sudokusolver-1.4/lib/sudokusolver.rb sudokus which #Find the library file of sudokusolver } end rescue NoMethodError => e print "#{e.class}: " puts "#{e.message}" puts 'command `sudokus patch SUDOKUSOLVER_PATH` to fix it.' exit 1 rescue Exception => e print "#{e.class}: " unless e.class == RuntimeError puts "#{e.message}" exit 1 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sudokus-1.4.1 | bin/sudokus |