Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- class PegCar
- PEG = 'Peg'
- CAR = 'Car'
- def initialize
- (1..100).map do |b|
- if b % 35 == 0
- puts "#{PEG}#{CAR}"
- elsif b % 5 == 0 && b % 7 != 0
- puts PEG
- elsif b % 7 == 0 && b % 5 != 0
- puts CAR
- else
- puts b
- end
- end
- end
- end
- PegCar.new
- # output
- 1
- 2
- 3
- 4
- Peg
- 6
- Car
- 8
- 9
- Peg
- 11
- 12
- 13
- Car
- Peg
- 16
- 17
- 18
- 19
- Peg
- Car
- 22
- 23
- 24
- Peg
- 26
- 27
- Car
- 29
- Peg
- 31
- 32
- 33
- 34
- PegCar
- 36
- 37
- 38
- 39
- Peg
- 41
- Car
- 43
- 44
- Peg
- 46
- 47
- 48
- Car
- Peg
- 51
- 52
- 53
- 54
- Peg
- Car
- 57
- 58
- 59
- Peg
- 61
- 62
- Car
- 64
- Peg
- 66
- 67
- 68
- 69
- PegCar
- 71
- 72
- 73
- 74
- Peg
- 76
- Car
- 78
- 79
- Peg
- 81
- 82
- 83
- Car
- Peg
- 86
- 87
- 88
- 89
- Peg
- Car
- 92
- 93
- 94
- Peg
- 96
- 97
- Car
- 99
- Peg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement