Skip to content

Instantly share code, notes, and snippets.

@dinopetrone
Created August 5, 2012 06:35
Show Gist options
  • Save dinopetrone/3262368 to your computer and use it in GitHub Desktop.
Save dinopetrone/3262368 to your computer and use it in GitHub Desktop.
var fb = {
fbArr:['','','Fizz','','Buzz','Fizz','','','Fizz','Buzz','','Fizz','','','FizzBuzz'],
next:function(){
var first_slot = this.fbArr.shift();
this.fbArr.push(first_slot);
console.log(first_slot);
}
}
fb.next();
while(true){
fb.next();
}
@theladyjaye
Copy link

let fizz = cycle ['', '', 'fizz']
let buzz = cycle ['', '', '', '', 'buzz']
let fizzbuzz = zipWith (++) fizz buzz
putStr (unlines fizzbuzz)

@theladyjaye
Copy link

Very clever use of shift and push.

@theladyjaye
Copy link

Executing it the same way, take a look at python's:

collections.deque module.

@ifnull
Copy link

ifnull commented Aug 5, 2012

Still doesn't satisfy all requirements. This only returns an infinite loop. How do you select a single iteration? i.e. what is 30?

@theladyjaye
Copy link

Which one? The JS or the Haskell?

@theladyjaye
Copy link

theladyjaye commented Aug 5, 2012 via email

@theladyjaye
Copy link

let r = take 30 fizzbuzz

^ first 30 results

last r

^ the last result in r

last (take 30 fizzbuzz)

@ifnull
Copy link

ifnull commented Aug 5, 2012

the JS one

@ifnull
Copy link

ifnull commented Aug 5, 2012

Simplified POC. Same functionality as Dino's with no numbers as well.

<?php 
$fb =  array('','','Fizz','','Buzz','Fizz','','','Fizz','Buzz','','Fizz','','','FizzBuzz');
$i = (int) null;
$i++;
while (true) {
    print(sprintf('%d: %s', $i, current($fb))."\n");
    if(next($fb) === false){
        reset($fb);
    }
    $i++;
}

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