Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.73 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. program_name = $0.split("/").last
  3. lines = ARGV[0].to_i
  4. numargs = ARGV.length
  5.  
  6. #just for testing
  7. #numargs = 1
  8. #lines = 8
  9.  
  10.  
  11. case numargs
  12.         when 0
  13.           puts "Error. No arguments given. Try #{program_name} --help"
  14.         when 1
  15.           puts "Printing #{lines} lines...\n"
  16.           # control variables
  17. a = 3
  18. b = 1
  19. i = 1
  20. j = 1
  21. output = ""
  22.  
  23. while i <= lines
  24. while j <= i
  25.  
  26.     if a == 0 && b == 0
  27.       a = 3
  28.       b = 1
  29.  
  30.         elsif a > 0
  31.           output << "A"
  32.           a = a - 1
  33.  
  34.     else
  35.       output << "B"
  36.       b = b - 1
  37.     end
  38.     j = j + 1
  39.   end
  40. puts output
  41. i = i + 1
  42. end
  43.  
  44.  
  45.         else
  46.           puts "Too many arguments given. Try #{program_name} --help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement