Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- program_name = $0.split("/").last
- lines = ARGV[0].to_i
- numargs = ARGV.length
- #just for testing
- #numargs = 1
- #lines = 8
- case numargs
- when 0
- puts "Error. No arguments given. Try #{program_name} --help"
- when 1
- puts "Printing #{lines} lines...\n"
- # control variables
- a = 3
- b = 1
- i = 1
- j = 1
- output = ""
- while i <= lines
- while j <= i
- if a == 0 && b == 0
- a = 3
- b = 1
- elsif a > 0
- output << "A"
- a = a - 1
- else
- output << "B"
- b = b - 1
- end
- j = j + 1
- end
- puts output
- i = i + 1
- end
- else
- puts "Too many arguments given. Try #{program_name} --help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement