Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Golf Challenge: FizzBuzz

by jdporter (Canon)
on Dec 27, 2015 at 04:45 UTC ( #1151212=note: print w/replies, xml ) Need Help??


in reply to Re^3: Golf Challenge: FizzBuzz
in thread Golf Challenge: FizzBuzz

It contributes to the notion of perl being obscure and hard to read

or it gets the hose again.

Replies are listed 'Best First'.
Re^5: Golf Challenge: FizzBuzz
by jdporter (Canon) on Dec 27, 2015 at 04:58 UTC

    Sorry. :-D

    Here's my fun solution to the problem. It's not golfed, but is intended to show a different approach from the usual modulus operator based solutions. Instead, this uses a "generator".

    use strict; use warnings; $\ = "\n"; my %label = ( 3 => 'fizz', 5 => 'buzz', ); my $end = 100; my %queue; $queue{0}{$_} = 1 for keys %label; my $i = 0; while (1) { my($n) = sort { $a <=> $b } keys %queue; # "shift" the next genera +ted number while ( $i < $n ) { print $i++; } # print any "non-special" number +s before it last if $i++ > $end; my @why_its_special = sort { $a <=> $b } keys %{ delete $queue{$n} + }; print @label{ @why_its_special }; $queue{ $n + $_ }{$_} = 1 for @why_its_special; # generate the ne +xt succeeding number(s) }
    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1151212]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2019-11-19 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (96 votes). Check out past polls.

    Notices?