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