Skip to content

Instantly share code, notes, and snippets.

@worace
Last active August 29, 2015 14:04
Show Gist options
  • Save worace/744bd6d879fc7768167c to your computer and use it in GitHub Desktop.
Save worace/744bd6d879fc7768167c to your computer and use it in GitHub Desktop.
def cracklepop(i)
if i % 15 == 0
"CracklePop"
elsif i % 5 == 0
"Pop"
elsif i % 3 == 0
"Crackle"
else
i
end
end
puts (1..100).map { |i| cracklepop(i) }
@worace
Copy link
Author

worace commented Aug 8, 2014

sample output:

irb(main):037:0> def cracklepop(i)
irb(main):038:1>     if i % 15 == 0
irb(main):039:2>         "CracklePop"
irb(main):040:2>       elsif i % 5 == 0
irb(main):041:2>         "Pop"
irb(main):042:2>       elsif i % 3  == 0
irb(main):043:2>         "Crackle"
irb(main):044:2>       else
irb(main):045:2*           i
irb(main):046:2>       end
irb(main):047:1>   end
=> :cracklepop
irb(main):048:0> puts (1..100).map { |i| cracklepop(i) }
1
2
Crackle
4
Pop
Crackle
7
8
Crackle
Pop
11
Crackle
13
14
CracklePop
16
17
Crackle
19
Pop
Crackle
22
23
Crackle
Pop
26
Crackle
28
29
CracklePop
31
32
Crackle
34
Pop
Crackle
37
38
Crackle
Pop
41
Crackle
43
44
CracklePop
46
47
Crackle
49
Pop
Crackle
52
53
Crackle
Pop
56
Crackle
58
59
CracklePop
61
62
Crackle
64
Pop
Crackle
67
68
Crackle
Pop
71
Crackle
73
74
CracklePop
76
77
Crackle
79
Pop
Crackle
82
83
Crackle
Pop
86
Crackle
88
89
CracklePop
91
92
Crackle
94
Pop
Crackle
97
98
Crackle
Pop
=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment