codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
# FizzBuzz by transforming lists. # A list that goes from 1 to 100 @FB1 = (1..100); # Make a new list from the previous list. # The new list replaces all values that are multiples of 3 & 5 with "FizzBuzz" @FB2 = map{!($_%3 or $_%5)?'FizzBuzz': $_}@FB1; # Make a new list from the previous list. # The new list replaces all values that are multiples of 3 with "Fizz" @FB3 = map{(/\d/ and !($_%3))?'Fizz': $_}@FB2; # Make a new list from the previous list. # The new list replaces all values that are multiples of 5 with "Buzz" @FB4 = map{(/\d/ and !($_%5))?'Buzz': $_}@FB3; # Make a new list from the previous list. # Add a line return to each value in that list @FB5 = map{$_."\n"}@FB4; # print the final list and toast your success with some bubbly. print @FB5;
Private
[
?
]
Run code
Submit