epergo
6/6/2016 - 1:52 PM

Tuenti Challenge exercise 1 in Crystal

Tuenti Challenge exercise 1 in Crystal

module TuentiChallenge1
  class Exercise
    property file : String

    def initialize(input_file)
      @file = input_file
    end

    def run
      lines = File.read_lines(file)

      lines.each_with_index do |line, index|
        next if index == 0
        puts "Case ##{index}: #{tables_necessary(line.to_i)}"
      end
    end

    def tables_necessary(diners)
      if diners <= 4 && diners > 0
        return 1
      elsif diners <= 0
        return 0
      end

      (((diners / 2.to_f) - 1).ceil).to_i
    end
  end
end

tc = TuentiChallenge1::Exercise.new("submitInput")
tc.run