Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
Add the fizzbuzz question
Browse files Browse the repository at this point in the history
Clear up text in the second chapter
  • Loading branch information
miekg committed Jun 30, 2010
1 parent 85c6978 commit 4883dcd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ex-basics/ex-fizzbuzz.tex
@@ -0,0 +1,17 @@
\begin{Exercise}[title={FizzBuzz},difficulty=1]
\label{ex:fizzbuzz}
\Question \label{ex:fizzbuzz q1} Solve this simple problem called
the Fizz-Buzz \cite{fizzbuzz} problem:
\begin{quote}
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".
\end{quote}
\end{Exercise}

\begin{Answer}
\Question The hard part was probably writing the thing in Go. A possible
solution to this simple problem is the following program.
\lstinputlisting[label=src:fizzbuzz,caption=Fizz-Buzz]{ex-basics/src/fizzbuzz.go}
\end{Answer}
19 changes: 19 additions & 0 deletions ex-basics/src/fizzbuzz.go
@@ -0,0 +1,19 @@
package main

import "fmt"

func main() {
fizz := 3
buzz := 5
for i := 1; i < 100; i++ {
if i%fizz == 0 {
fmt.Printf("Fizz")
} else if i%buzz == 0 {
fmt.Printf("FizzBuzz")
} else {
fmt.Printf("%v", i)
}
fmt.Println()

}
}
2 changes: 2 additions & 0 deletions go-basics.tex
Expand Up @@ -585,6 +585,8 @@ \subsection{Maps}
\section{Exercises}
\input{ex-basics/ex-for.tex}

\input{ex-basics/ex-fizzbuzz.tex}

\input{ex-basics/ex-strings.tex}

\cleardoublepage
Expand Down
7 changes: 7 additions & 0 deletions go.bib
Expand Up @@ -153,3 +153,10 @@ @misc{iota
howpublished = {Internet,
\url{http://en.wikipedia.org/wiki/Iota}}
}

@misc{fizzbuzz,
author = "Imran On Tech",
title = "Using FizzBuzz to Find Developers who Grok Coding",
howpublished = {Internet,
\url{http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/}}
}

0 comments on commit 4883dcd

Please sign in to comment.