Skip to content

Instantly share code, notes, and snippets.

@readingtype
Forked from anonymous/col-widther.rb
Created April 5, 2013 12:19
Show Gist options
  • Save readingtype/5318876 to your computer and use it in GitHub Desktop.
Save readingtype/5318876 to your computer and use it in GitHub Desktop.
@colwidth = 100
@margin = 10
@total = 0
def spanwidth(cols)
[(cols * @colwidth.to_i), (@margin.to_i * (cols-1))]
end
def calculate
(1..@cols.to_i).each do | i |
width = spanwidth(i)
puts "-- #{@total} --"
puts "-- #{@total + @margin.to_i} --"
puts " [#{i}] #{width[0] + width[1]}"
@total += (@colwidth.to_i + @margin.to_i)
end
puts "-- #{@margin.to_i} --"
end
puts "Column width: "
@colwidth = gets
puts "Margin width: "
@margin = gets
puts "Total columns: "
@cols = gets
puts ". . . . . ."
if @colwidth.to_i > 1 && @margin.to_i > 1 && @cols.to_i > 1
calculate
puts "Total: #{@total}"
else
puts "Oops."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment