Created
August 29, 2022 16:40
-
-
Save h0tw1r3/53762932b31dd9cd2a3cf186ffd41fab to your computer and use it in GitHub Desktop.
Puppet 99 Bottles of Beer on the Wall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$bottles = Integer[0,99].map |$bottle| { abs($bottle - 99) } | |
$report = { | |
bottles => '%s bottle%s of beer on the wall, %s bottle%s of beer.', | |
left => '%s bottle%s of beer on the wall.', | |
take => 'Take one down and pass it around', | |
buy => 'Go to the store and buy some more', | |
} | |
$bottles.map |$bottles_on_wall| { | |
$bottles_left = $bottles_on_wall ? { | |
0 => 99, | |
1 => 'no more', | |
default => ($bottles_on_wall - 1), | |
} | |
$action = $bottles_on_wall ? { | |
0 => 'buy', | |
default => 'take', | |
} | |
$bottles_as_word = ($bottles_on_wall == 0) ? { | |
true => 'no more', | |
false => $bottles_on_wall, | |
} | |
notice( | |
sprintf($report['bottles'], | |
capitalize($bottles_as_word), | |
($bottles_on_wall != 1) ? { true => 's', false => '' }, | |
$bottles_as_word, | |
($bottles_on_wall != 1) ? { true => 's', false => '' }, | |
) | |
) | |
notice( | |
sprintf("${report[$action]}, ${report['left']}", | |
$bottles_left, | |
($bottles_left != 1) ? { true => 's', false => '' }, | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment