by Christopher Allen and Julie Moronuki · 1 Jan 2015 · 1,076pp · 67,364 words
which are multiples of both three and five print “FizzBuzz”. A typical fizzbuzz solution in Haskell looks something like: fizzBuzz :: Integer -> String fizzBuzz n | n `mod` 15 == 0 = | n `mod` 5 == 0 = | n `mod` 3 == 0 = | otherwise = "FizzBuzz" "Fizz" "Buzz" show n main :: IO () main = mapM_ (putStrLn . fizzBuzz) [1..100] You will craft a fizzbuzz that makes
…
://c2.com/cgi/wiki?FizzBuzzTest CHAPTER 23. STATE 835 import Control.Monad import Control.Monad.Trans.State fizzBuzz :: Integer -> String fizzBuzz n | n `mod` 15 == 0 = | n `mod` 5 == 0 = | n `mod` 3 == 0 = | otherwise = "FizzBuzz" "Fizz" "Buzz" show n fizzbuzzList :: [Integer] -> [String] fizzbuzzList list = execState (mapM_ addResult list) [] addResult :: Integer -> State [String] () addResult n
…
= do xs <- get let result = fizzBuzz n put (result : xs) main :: IO () main = mapM_ putStrLn $ reverse $ fizzbuzzList [1..100] The good
…
CHAPTER 23. STATE 836 import Control.Monad import Control.Monad.State import qualified Data.DList as DL fizzBuzz :: Integer -> String fizzBuzz n | n `mod` 15 == 0 = | n `mod` 5 == 0 = | n `mod` 3 == 0 = | otherwise = "FizzBuzz" "Fizz" "Buzz" show n fizzbuzzList :: [Integer] -> [String] fizzbuzzList list = let dlist = execState (mapM_ addResult list) DL.empty in DL
…
.apply dlist [] -- convert back to normal list addResult :: Integer -> State (DL.DList String) () addResult n = do xs <- get let result = fizzBuzz n -- snoc appends to the end, unlike
…
:: [Integer] -> DL.DList String fizzbuzzList list = execState (mapM_ addResult list) DL.empty addResult :: Integer -> State (DL.DList String) () addResult n = do xs <- get let result = fizzBuzz n put (DL.snoc xs result) main :: IO () main = mapM_ putStrLn $ fizzbuzzList [1..100] DList’s Foldable instance converts to a list before folding because
…
to use or not use State. Please frighten some interviewers with a spooky fizzbuzz. Make something even weirder than what we’ve shown you here! Fizzbuzz Differently It’s an exercise! Rather than changing the underlying data structure, fix our reversing fizzbuzz by changing the code in the following way: fizzbuzzFromTo
by Jeff Atwood · 3 Jul 2012 · 270pp · 64,235 words
this kind of developer and came up with a class of questions I call “FizzBuzz Questions,” named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following: Write a program that prints the numbers from 1 to
…
100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz.” Most good
…
. I assumed anyone applying for a job as a programmer had already crossed this chasm. Apparently this is not a reasonable assumption to make. Apparently, FizzBuzz-style screening is required to keep interviewers from wasting their time interviewing programmers who can’t program. Lest you think the
…
is too easy — and it is blindingly, intentionally easy — a commenter to Imran’s post notes its efficacy: I’d hate interviewers to dismiss [the FizzBuzz] test as being too easy – in my experience it is genuinely astonishing how many candidates are incapable of the simplest programming tasks. Maybe it’s
…
program or not. Steve’s article predates it, but I’d be remiss if I didn’t mention Why Can’t Programmers.. Program? here. The FizzBuzz problem is quite similar, and it’s shocking how often interviewees can’t do it. It’s a bit hard to comprehend, like a potential
…
should be CEO of a startup by now.) What I’m optimizing for here is the ability to communicate. Most programmers, once they pass the FizzBuzz level of competency, are decent enough. But coding chops aren’t enough. To go from good to great, you must be able to communicate effectively
by Jim Blandy and Jason Orendorff · 21 Nov 2017 · 1,331pp · 183,137 words
("").take(2).chain(once("fizz")).cycle(); let buzzes = repeat("").take(4).chain(once("buzz")).cycle(); let fizzes_buzzes = fizzes.zip(buzzes); let fizz_buzz = (1..100).zip(fizzes_buzzes) .map(|tuple| match tuple { (i, ("", "")) => i.to_string(), (_, (fizz, buzz)) => format!("{}{}", fizz, buzz) }); for line in fizz_buzz { println!("{}", line); } This plays a children’s word game, now sometimes used as a job
…
interview question for coders, in which the players take turns counting, replacing any number divisible by three with the word “fizz”, and any number divisible by five with “buzz”. Numbers divisible by both become “fizzbuzz
by Drew Neil · 6 Oct 2012 · 722pp · 90,903 words
this:[32] => $ npm install nodelint -g As a test case, we’ll use this JavaScript implementation of FizzBuzz: quickfix/fizzbuzz.js var i; for (i=1; i <= 100; i++) { if(i % 15 == 0) { console.log('Fizzbuzz'); } else if(i % 5 == 0) { console.log('Buzz'); } else if(i % 3 == 0) { console.log('Fizz'); } else
…
=NODE_DISABLE_COLORS=1\ nodelint\ % The % symbol is expanded to the path for the current file. So if we were editing a file called ~/quickfix/fizzbuzz.js, then running :make inside Vim would be equivalent to running this in the shell: => $ export NODE_DISABLE_COLORS=1 => $ nodelint ~/quickfix
…
/fizzbuzz.js <= ~/quickfix/fizzbuzz.js, line 2, character 22: Unexpected '++'. for (i=1; i <= 100; i++) { ~/quickfix/fizzbuzz.js, line 3, character 15: Expected '===' ... if(i % 15 == 0) { ~/quickfix/fizzbuzz.js, line 5, character 21: Expected '===' ... } else if(i % 5 == 0) { ~/quickfix
…
/fizzbuzz.js, line 7, character 21: Expected '===' ... } else if(i % 3 == 0) { ~/quickfix/fizzbuzz.js, line 12, character 2: Unexpected ';'. }; 5 errors By default, nodelint highlights errors in red using
by Drew Neil
this:[28] => $ npm install nodelint -g As a test case, we’ll use this JavaScript implementation of FizzBuzz: quickfix/fizzbuzz.js var i; for (i=1; i <= 100; i++) { if(i % 15 == 0) { console.log('Fizzbuzz'); } else if(i % 5 == 0) { console.log('Buzz'); } else if(i % 3 == 0) { console.log('Fizz'); } else
…
=NODE_DISABLE_COLORS=1\ nodelint\ % The % symbol is expanded to the path for the current file. So if we were editing a file called ~/quickfix/fizzbuzz.js, then running :make inside Vim would be equivalent to running this in the shell: => $ export NODE_DISABLE_COLORS=1 => $ nodelint ~/quickfix
…
/fizzbuzz.js <= ~/quickfix/fizzbuzz.js, line 2, character 22: Unexpected '++'. for (i=1; i <= 100; i++) { ~/quickfix/fizzbuzz.js, line 3, character 15: Expected '===' ... if(i % 15 == 0) { ~/quickfix/fizzbuzz.js, line 5, character 21: Expected '===' ... } else if(i % 5 == 0) { ~/quickfix
…
/fizzbuzz.js, line 7, character 21: Expected '===' ... } else if(i % 3 == 0) { ~/quickfix/fizzbuzz.js, line 12, character 2: Unexpected ';'. }; 5 errors By default, nodelint highlights errors in red using
by Drew Neil
this:[28] => $ npm install nodelint -g As a test case, we’ll use this JavaScript implementation of FizzBuzz: quickfix/fizzbuzz.js var i; for (i=1; i <= 100; i++) { if(i % 15 == 0) { console.log('Fizzbuzz'); } else if(i % 5 == 0) { console.log('Buzz'); } else if(i % 3 == 0) { console.log('Fizz'); } else
…
=NODE_DISABLE_COLORS=1\ nodelint\ % The % symbol is expanded to the path for the current file. So if we were editing a file called ~/quickfix/fizzbuzz.js, then running :make inside Vim would be equivalent to running this in the shell: => $ export NODE_DISABLE_COLORS=1 => $ nodelint ~/quickfix
…
/fizzbuzz.js <= ~/quickfix/fizzbuzz.js, line 2, character 22: Unexpected '++'. for (i=1; i <= 100; i++) { ~/quickfix/fizzbuzz.js, line 3, character 15: Expected '===' ... if(i % 15 == 0) { ~/quickfix/fizzbuzz.js, line 5, character 21: Expected '===' ... } else if(i % 5 == 0) { ~/quickfix
…
/fizzbuzz.js, line 7, character 21: Expected '===' ... } else if(i % 3 == 0) { ~/quickfix/fizzbuzz.js, line 12, character 2: Unexpected ';'. }; 5 errors By default, nodelint highlights errors in red using
by Marijn Haverbeke · 15 Nov 2018 · 560pp · 135,629 words
Indenting Code for Loops Breaking Out of a Loop Updating Bindings Succinctly Dispatching on a Value with switch Capitalization Comments Summary Exercises Looping a Triangle FizzBuzz Chessboard 3 FUNCTIONS Defining a Function Bindings and Scopes Nested Scope Functions as Values Declaration Notation Arrow Functions The Call Stack Optional Arguments Closure Recursion
…
Work Profiling Function Inlining Creating Less Garbage Garbage Collection Dynamic Types Summary Exercises Pathfinding Timing Optimizing EXERCISE HINTS Chapter 2: Program Structure Looping a Triangle FizzBuzz Chessboard Chapter 3: Functions Minimum Recursion Bean Counting Chapter 4: Data Structures: Objects and Arrays The Sum of a Range Reversing an Array A List
…
useful to know that you can find the length of a string by writing .length after it. let abc = "abc"; console.log(abc.length); // → 3 FizzBuzz Write a program that uses console.log to print all the numbers from 1 to 100, with two exceptions. For numbers divisible by 3, print
…
of the number, and for numbers divisible by 5 (and not 3), print "Buzz" instead. When you have that working, modify your program to print "FizzBuzz" for numbers that are divisible by both 3 and 5 (and still print "Fizz" or "Buzz" for numbers divisible by only one of those). (This
…
to 2 by adding 1 (+= 1). You can go from "#" to "##" by adding a character (+= "#"). Thus, your solution can closely follow the number-printing program. FizzBuzz Going over the numbers is clearly a looping job, and selecting what to print is a matter of conditional execution. Remember the trick of using
…
function, 124, 193 finish event, 367 Firefox, 225, 398, 400, 402, 404 firewall, 372 firstChild property, 230 fixed positioning, 257 fixing scope (exercise), 215, 417 FizzBuzz (exercise), 37, 407 flattening (exercise), 95 flexibility, 6 flipHorizontally function, 304, 420 flipHorizontally method, 298 flipping, 297–298 floating-point number, 12–13 flood fill