bin/24games in 24games-0.2.2 vs bin/24games in 24games-0.2.3

- old
+ new

@@ -4,26 +4,32 @@ $:.unshift(lib_path) require 'calc24' require 'calc24/version' begin + digits = [] + raise Calc24::VERSION if ['--version', '-v'].include? ARGV[0] - # validate user input - digits = ARGV.to_i + if ARGV.count == 1 and ARGV[0].size == 4 + ARGV[0].each_char do |c| + digits << c + end + elsif ARGV.count == 4 + digits = ARGV.to_i + else + raise " inputs 4 numbers such as: 5959 or 5 9 5 9" + end - raise "need 4 digits, such as: 5 9 5 9" unless digits.size == 4 - t0 = Time.now player = Calc24::TwentyFourGamePlayer.new(digits) if player.solutions.empty? puts "no solutions" else - puts "found #{player.solutions.size} solutions:" - #STDIN.gets + puts "found #{player.solutions.size} solutions:\n\n" puts player.solutions.values.join("\n").to_p - puts "#{Time.now - t0}s" + puts "\n#{Time.now - t0}s" end rescue Exception => e print "#{e.class}: " unless e.class == RuntimeError puts "#{e.message}" exit 1