SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
Fizz and Buzz
of
Computer Programs
in Python.
esehara shigeo
WHO
ARE
YOU?
Shigeo Esehara
Just a Programmer using Python
and
Love Trivial Programming
!! WARNING !!
I guess you get used to my funny English Speaking.
(or Programming ?)
OK. Ready!!
GO!!
Before,
Programmers had
“The Common Sense”...
SICP
But….
Jeff Atword
(ex-StackOverFlow)
wrote the essay:
Why Can't Programmers..
Program?
Then….
Now,
Programmer has
“The Common Sense”...
FIZZ
BUZZ
FizzBuzz Rule
● Write a program that prints the
numbers from 1 to 100.
● For multiples of three print “Fizz”
instead of the number
● For multiples of five print “Buzz”.
● For numbers which are multiples of
both three and five print “FizzBuzz”
Other Lang Example
Haskell :: Maybe Monads FizzBuzz
type IsFizzBuzz = Maybe String
is_n:: Integer -> Integer -> Integer
is_n x y = x `mod` y
fizz :: Integer -> Integer
fizz x = is_n x 3
buzz :: Integer -> Integer
buzz x = is_n x 5
maybe_div :: Integer -> String -> IsFizzBuzz ->
IsFizzBuzz
maybe_div 0 str m = case m of
Nothing -> Just str
Just x -> Just $ str ++ x
maybe_div _ str m = m
maybe_fizz :: Integer -> IsFizzBuzz -> IsFizzBuzz
maybe_fizz x m = maybe_div is_fizz "Fizz" m
where is_fizz = fizz x
maybe_buzz :: Integer -> IsFizzBuzz -> IsFizzBuzz
maybe_buzz x m = maybe_div is_buzz "Buzz" m
where is_buzz = buzz x
maybe_fizzbuzz :: Integer -> IsFizzBuzz -> String
maybe_fizzbuzz x m = case m of
Nothing -> show x
Just x -> x
maybe_process :: Integer -> String
maybe_process x = maybe_fizzbuzz x =<< is_fizzbuzz x
where is_fizzbuzz x = maybe_fizz x >>= maybe_buzz x
go :: (Integer -> String) -> IO ()
go f = process f 1
process :: (Integer -> String) -> Integer -> IO ()
process f 101 = putStr ""
process f x = (putStrLn $ f x) >> process f next
where next = x + 1
OK.
Real Pythonista
solves
the Problem at 3sec.
Basic
# begin code
for i in range(1, 100):
if (i % 15 == 0):
print "FizzBuzz"
if (i % 3 == 0):
print "Buzz"
if (i % 5 == 0):
print "Fizz"
print i
# end
“Are You
kidding me ?”
No!!
Real Pythonista
don’t use
“if”statement
in FizzBuzz.
Hint
FizzBuzz Structure
consist
“Loop” and “Branch”.
In other words ...
“Loop”
is
“Iteration”.
Iterator in Python ?
List.
3 of multiple explession:
[1, 2, 3, 4, 5, 6, 7, 8, 9 …]
Fizzlize!!
[‘’, ‘’, ‘Fizz’,
‘’, ‘’, ’Fizz’,
‘’, ‘’, ’Fizz’
…]
More!!
[‘’, ‘’, ‘Fizz’] * 3
List can be multipication in Python.
“Use type conversion, Luke.”
bool(‘’) = False
int(False) = 0
not use “if” statements
fizz = ['', '', “Fizz”] * 50
buzz = ['', '', '', '', “Buzz”] * 50
for x in range(1, 101):
fizzbuzz = fizz[x] + buzz[x]
number = str(x) * (not bool(fizzbuzz))
print fizzbuzz + number
“It seems bad
because
it generates list
like *malloc*
in C language.”
oh...
Real Pythonista
use “itertools”
in FizzBuzz.
Pythonista like ‘itertools’.
from itertools import cycle
fizz = cycle(['', '', 'Fizz'])
buzz = cycle(['', '', '', '', '', 'Buzz'])
for i in range(1, 101):
fizzbuzz = fizz.next() + buzz.next()
fizzbuzz += (str(i) * (not bool(fizzbuzz)))
print fizzbuzz
But...
TRUE Pythonista
don’t use *“List”
in FizzBuzz.
* Strictly speaking,
“String” has “List”(= array (= char sets)) Structure,
but now, String is exception.
Do you think
it possible ?
Yes,
We Can!!
OK.
Hint
Loop
can be created
using “Recurtion”.
Recursion
def loop(start, limit):
print start
(start == limit) or loop(start + 1, limit)
loop(1, 100)
FizzBuzz flag
Fizz, Buzz = [Bool, Bool]
FizzBuzz flag
Fizz, Buzz = [
0 or 1, 0 or 1]
FizzBuzz flag
Number = [0, 0]
Fizz = [1, 0]
Buzz = [0, 1]
FizzBuzz = [1, 1]
“It seems like
binary system.”
Yes !! Binary System.
Number = 00 = 0
Fizz = 01 = 1
Buzz = 10 = 2
FizzBuzz = 11 = 3
Example :: PHP
<?php
function _00($i) { echo $i; }
function _10($i) { echo "Fizz"; }
function _01($i) { echo "Buzz"; }
function _11($i) {
echo _10($i);
echo _01($i);
}
for ($i = 1; $i < 101; $i++) {
$fizz = $i % 3 === 0; $fizz = (int) $fizz;
$fizz = (string) $fizz;
$buzz = $i % 5 === 0; $buzz = (int) $buzz;
$buzz = (string) $buzz;
$fizzbuzz = "_" . $fizz . $buzz;
$fizzbuzz($i);
echo "n";
}
“Use the String, Luke.”
" FizzBuzzFizzBuzz"
“Use the String, Luke.”
" FizzBuzzFizzBuzz"
[ 0 ][ 1 ][2 ][3 ]
* “FizzBuzz” is just only 8 string.
Imagine
there’s
no list..
No List !!
def loop(start, limit):
fizzbuzz = (not start % 3) | ((not start % 5) * 2)
print (" FizzBuzz FizzBuzz"[
fizzbuzz * 4:
(fizzbuzz + 1) * 4 + ((fizzbuzz == 3) * 4)].strip()
) or start
(start == limit) or loop(start + 1, limit)
loop(1, 100)
Congratulations!!
Thanks for
your attention.
twitter: @esehara
github.com/esehara

Weitere ähnliche Inhalte

Was ist angesagt?

10 reasons to love CoffeeScript
10 reasons to love CoffeeScript10 reasons to love CoffeeScript
10 reasons to love CoffeeScript
Lukas Alexandre
 

Was ist angesagt? (20)

gitfs
gitfsgitfs
gitfs
 
Tuples
TuplesTuples
Tuples
 
Basics
BasicsBasics
Basics
 
Parsing Contexts for PetitParser
Parsing Contexts for PetitParserParsing Contexts for PetitParser
Parsing Contexts for PetitParser
 
10 reasons to love CoffeeScript
10 reasons to love CoffeeScript10 reasons to love CoffeeScript
10 reasons to love CoffeeScript
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
GNU Parallel și GNU Stow
GNU Parallel și GNU StowGNU Parallel și GNU Stow
GNU Parallel și GNU Stow
 
Libraries
LibrariesLibraries
Libraries
 
Let's golang
Let's golangLet's golang
Let's golang
 
Alias
AliasAlias
Alias
 
Python パッケージ構成
Python パッケージ構成Python パッケージ構成
Python パッケージ構成
 
Python Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding StylePython Programming in Entertainment Industry: Coding Style
Python Programming in Entertainment Industry: Coding Style
 
プログラミングはなぜ難しいのか
プログラミングはなぜ難しいのかプログラミングはなぜ難しいのか
プログラミングはなぜ難しいのか
 
Workshop programs
Workshop programsWorkshop programs
Workshop programs
 
Sistemas operacionais 13
Sistemas operacionais 13Sistemas operacionais 13
Sistemas operacionais 13
 
CentOS_slide_ver1.0
CentOS_slide_ver1.0CentOS_slide_ver1.0
CentOS_slide_ver1.0
 
Sample Jarvis(desktop assistant)
Sample Jarvis(desktop assistant)Sample Jarvis(desktop assistant)
Sample Jarvis(desktop assistant)
 
01 linux basics
01 linux basics01 linux basics
01 linux basics
 
Instalación de emu8086 y compilados
Instalación de emu8086 y compiladosInstalación de emu8086 y compilados
Instalación de emu8086 y compilados
 
Slicing
SlicingSlicing
Slicing
 

Andere mochten auch

Complejidad de los algoritmos
Complejidad de los algoritmosComplejidad de los algoritmos
Complejidad de los algoritmos
juanveg31
 
Iqbal email custom domain pada wl admin center
Iqbal   email custom domain pada wl admin centerIqbal   email custom domain pada wl admin center
Iqbal email custom domain pada wl admin center
anggaputra234
 
Country Manager_William Kim June 2015
Country Manager_William Kim June 2015Country Manager_William Kim June 2015
Country Manager_William Kim June 2015
William Kim
 
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
Tina_Karas
 
Building Communities in Context: The Opportunities and Challenges of Conducti...
Building Communities in Context: The Opportunities and Challenges of Conducti...Building Communities in Context: The Opportunities and Challenges of Conducti...
Building Communities in Context: The Opportunities and Challenges of Conducti...
Community Development Society
 

Andere mochten auch (20)

Proyecto Altair: Terapia psicológica en entornos virtuales
Proyecto Altair: Terapia psicológica en entornos virtualesProyecto Altair: Terapia psicológica en entornos virtuales
Proyecto Altair: Terapia psicológica en entornos virtuales
 
Le Guide Châteaux & Hôtels Collection 2012 dévoile sa sélection
Le Guide Châteaux & Hôtels Collection 2012 dévoile sa sélectionLe Guide Châteaux & Hôtels Collection 2012 dévoile sa sélection
Le Guide Châteaux & Hôtels Collection 2012 dévoile sa sélection
 
Complejidad de los algoritmos
Complejidad de los algoritmosComplejidad de los algoritmos
Complejidad de los algoritmos
 
Sentencia Comfaboy
Sentencia ComfaboySentencia Comfaboy
Sentencia Comfaboy
 
Vida muerte CONJURA CONTRA LA VIDA
Vida muerte CONJURA CONTRA LA VIDAVida muerte CONJURA CONTRA LA VIDA
Vida muerte CONJURA CONTRA LA VIDA
 
Iqbal email custom domain pada wl admin center
Iqbal   email custom domain pada wl admin centerIqbal   email custom domain pada wl admin center
Iqbal email custom domain pada wl admin center
 
Navegación web anónima con tor y privoxy en kali linux
Navegación web anónima con tor y privoxy en kali linuxNavegación web anónima con tor y privoxy en kali linux
Navegación web anónima con tor y privoxy en kali linux
 
Fregadero Teka STYLO 1C 1E
Fregadero Teka STYLO 1C 1EFregadero Teka STYLO 1C 1E
Fregadero Teka STYLO 1C 1E
 
Mis cosas favoritas
Mis cosas favoritasMis cosas favoritas
Mis cosas favoritas
 
Sintesis informativa 14 08 2014
Sintesis informativa 14 08 2014Sintesis informativa 14 08 2014
Sintesis informativa 14 08 2014
 
Talleres Comenius
Talleres ComeniusTalleres Comenius
Talleres Comenius
 
E s1-silber
E s1-silberE s1-silber
E s1-silber
 
Country Manager_William Kim June 2015
Country Manager_William Kim June 2015Country Manager_William Kim June 2015
Country Manager_William Kim June 2015
 
Hornos Mixtos
Hornos MixtosHornos Mixtos
Hornos Mixtos
 
Hatsu rei-ho-a-basic-japanese-reiki-technique
Hatsu rei-ho-a-basic-japanese-reiki-techniqueHatsu rei-ho-a-basic-japanese-reiki-technique
Hatsu rei-ho-a-basic-japanese-reiki-technique
 
Press Release (email format)
Press Release (email format)Press Release (email format)
Press Release (email format)
 
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
Heavy Haul Rail South America 2013 & Urban Rail Brazil, 15-17 October 2013 | ...
 
Building Communities in Context: The Opportunities and Challenges of Conducti...
Building Communities in Context: The Opportunities and Challenges of Conducti...Building Communities in Context: The Opportunities and Challenges of Conducti...
Building Communities in Context: The Opportunities and Challenges of Conducti...
 
Educació financera - EFEC
Educació financera - EFECEducació financera - EFEC
Educació financera - EFEC
 
Tarea 7.2: ¿Jugamos al estratego? - Pablo Muñoz Lorencio
Tarea 7.2: ¿Jugamos al estratego? - Pablo Muñoz LorencioTarea 7.2: ¿Jugamos al estratego? - Pablo Muñoz Lorencio
Tarea 7.2: ¿Jugamos al estratego? - Pablo Muñoz Lorencio
 

Ähnlich wie Fizz and buzz of computer programs in python.

Python for text processing
Python for text processingPython for text processing
Python for text processing
Xiang Li
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
Go Asgard
 

Ähnlich wie Fizz and buzz of computer programs in python. (20)

Test Driven Development Workshop
Test Driven Development WorkshopTest Driven Development Workshop
Test Driven Development Workshop
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?
 
Class 4: For and while
Class 4: For and whileClass 4: For and while
Class 4: For and while
 
Class 3: if/else
Class 3: if/elseClass 3: if/else
Class 3: if/else
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM Languages
 
Where do Rubyists go?
 Where do Rubyists go?  Where do Rubyists go?
Where do Rubyists go?
 
Magic 8 ball putting it all together
Magic 8 ball  putting it all togetherMagic 8 ball  putting it all together
Magic 8 ball putting it all together
 
Python
PythonPython
Python
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
 
Python for text processing
Python for text processingPython for text processing
Python for text processing
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Τα Πολύ Βασικά για την Python
Τα Πολύ Βασικά για την PythonΤα Πολύ Βασικά για την Python
Τα Πολύ Βασικά για την Python
 
Pythonの紹介
Pythonの紹介Pythonの紹介
Pythonの紹介
 
FizzBuzz Trek
FizzBuzz TrekFizzBuzz Trek
FizzBuzz Trek
 
Get Kata
Get KataGet Kata
Get Kata
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Fizz and buzz of computer programs in python.