1 / 106

Fizzbuzzalooza

Presented at ACCU (25th April 2015) <br><br>Fizz Buzz. It's a drinking game. It's an educational game to teach kids division. It's an interview question. It's a coding kata. It's all these things. And it can be fun. It can also be used to illustrate different coding paradigms, languages and techniques, from the serious to the jocoserious to the you-cannot-be-serious. This talk uses this simple problem to take you on a bazaar and bizarre tour, from plain examples to provocative examples in common and less common languages, sequential to concurrent, procedural to functional, elegant to ridiculous.

Kevlin
Download Presentation

Fizzbuzzalooza

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fizzbuzzalooza @KevlinHenney

  2. Art. Craft. Engineering. Science. These are the swirling muses of design patterns. Art and science are stories; craft and engineering are actions. Wayne Cool

  3. Art is useless because its aim is simply to create a mood. It is not meant to instruct, or to influence action in any way. It is superbly sterile. Oscar Wilde

  4. Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets. Imagination without skill gives us modern art. Tom Stoppard

  5. The ideal world of Vermeer's little lacemaker Peter Dormer

  6. Craft and craft-related activities are pleasurable, and the pleasure derives from doing something well that you know well how to do. The criteria for doing the job well and judging whether the job has been well done are known in advance.

  7. Fizz buzz is a group word game for children to teach them about division. http://en.wikipedia.org/wiki/Fizz_buzz

  8. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz

  9. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz

  10. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz

  11. Adults may play Fizz buzz as a drinking game, where making a mistake leads to the player having to make a drinking-related forfeit. [citation needed] http://en.wikipedia.org/wiki/Fizz_buzz

  12. Fizz buzz has been used as an interview screening device for computer programmers. http://en.wikipedia.org/wiki/Fizz_buzz

  13. Creating a list of the first 100 Fizz buzz numbers is a trivial problem for any would-be computer programmer. http://en.wikipedia.org/wiki/Fizz_buzz

  14. FizzBuzz was invented to avoid the awkwardness of realising that nobody in the room can binary search an array. https://twitter.com/richardadalton/status/591534529086693376

  15. FizzBuzz is also a popular Kata in the software craftsmanship movement. http://en.wikipedia.org/wiki/Fizz_buzz

  16. http://en.wikipedia.org/wiki/Fizz_buzz

  17. enterprise, noun  a project or undertaking that is especially bold, complicated or arduous  readiness to engage in undertakings of difficulty, risk, danger or daring  a design of which the execution is attempted  a commercial or industrial undertaking  a firm, company or business  a unit of economic organisation or activity Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary

  18. enterprise, noun  a project or undertaking that is especially bold, complicated or arduous  readiness to engage in undertakings of difficulty, risk, danger or daring  a design of which the execution is attempted  a commercial or industrial undertaking  a firm, company or business  a unit of economic organisation or activity Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary

  19. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  20. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  21. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  22. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  23. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  24. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  25. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if(n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if(n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if(n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }

  26. https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

  27. https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

  28. All architecture is design but not all design is architecture. Architecture represents the significant design decisions that shape a system, where significant is measured by cost of change. Grady Booch

  29. Architecture is the art of how to waste space. Philip Johnson

  30. https://twitter.com/KevlinHenney/status/476962681636020224

  31. https://twitter.com/KevlinHenney/status/476963022549032960

  32. http://cliffle.com/esoterica/hq9plus.html

  33. T123SE60S#S*S&S@SP100SP10SP5SP3S P1SQSPSBSFSISUSZSPSP1SPSPSO34SO3 5SO36ST49SA50SA41ST50SA50SU51SS4 0SE62SA40SS41SE73ST51SO34SO45SO4 6SO48SO48ST49SA50SS39SE75SA39SS4 1SE86ST51SO34SO44SO47SO48SO48ST4 9SA51SG53SO33ST49SA50SS37SA41SG9 8SZSO43SO43ST49ST52SA50SS38SG109 ST51SA52SA41ST52SA51SE101ST49SA5 2SS41SG117SA41SL512ST52SO52ST49S A51SL512ST52SO52SE53SXS Olve Maudal http://www.pvv.org/~oma/FizzBuzz_EDSAC_ACCU_Apr2015.pdf

  34. http://www.adampetersen.se/articles/fizzbuzz.htm

  35. http://www.adampetersen.se/articles/fizzbuzz.htm

  36. enum fizzbuzzed { fizz = -2, buzz = -1, fizzbuzz = 0, first = 1, last = 100 }; constexpr fizzbuzzed fizzbuzz_of(int n) { return n % 3 == 0 && n % 5 == 0 ? fizzbuzz : n % 3 == 0 ? fizz : n % 5 == 0 ? buzz : fizzbuzzed(n); }

  37. enum fizzbuzzed { fizz = -2, buzz = -1, fizzbuzz = 0, first = 1, last = 100 }; constexpr fizzbuzzed fizzbuzz_of(int n) { return n % 3 == 0 && n % 5 == 0 ? fizzbuzz : n % 3 == 0 ? fizz : n % 5 == 0 ? buzz : fizzbuzzed(n); }

More Related