fizzbuzz.html
HTML document, ASCII text, with very long lines (653)
1<!DOCTYPE html> 2<html lang="en-us" prefix="og: https://ogp.me/ns# article: http://ogp.me/ns/article# profile: https://ogp.me/ns/profile#"> 3 4<head> 5 6 7<meta charset="UTF-8" /> 8<meta name="viewport" content="width=device-width, initial-scale=1.0" /> 9<title>The FizzBuzz Program - S0G</title> 10<link rel="stylesheet" href="/src/global.css" /> 11<meta property="og:locale" content="en_US" /> 12<meta property="og:site_name" content="Steve0Greatness" /> 13<meta property="og:image" content="/OG-Image.png" /> 14 15<link rel="stylesheet" href="/src/code-blocks.css" /> 16<link rel="stylesheet" href="/src/blog.css" /> 17<link rel="alternate" href="/blog/fizzbuzz.txt" type="text/plain" title="Post source" /> 18<meta property="og:title" content="The FizzBuzz Program" /> 19<meta property="og:type" content="article" /> 20<meta property="article:published_time" content="2022-02-20T00:00:00Z" /> 21<meta property="article:author" content"https://steve0greatness.github.io" /> 22<meta property="article:modified_time" content="2024-02-02T00:00:00Z" /> 23<meta property="profile:first_name" content="Steve0Greatness" /> 24<meta property="profile:username" content="Steve0Greatness" /> 25<meta property="profile:gender" content="male" /> 26<meta property="og:url" content="https://steve0greatness.github.io/blog/fizzbuzz.html" /> 27 28</head> 29 30<body> 31<header> 32<h2><a href="/"><img src="/SteveLogo.webp" height="35" width="215" alt="Steve0Greatness" /></a></h2> 33<nav> 34<a href="/blog">Blog</a> 35<a href="/list/link-tree.html">Link Tree</a> 36</nav> 37</header> 38 39<nav aria-label="breadcrumbs" aria-roledescription="Site breadcrumb"> 40<ol class="breadcrumbs"> 41 42<li> 43<a href="/">Index</a> 44</li> 45 46<li > 47<a 48 49href="/blog" 50>Blog Index</a> 51</li> 52 53<li > 54<a 55aria-current="location" 56href="/blog/fizzbuzz.html" 57>The FizzBuzz Program</a> 58</li> 59 60 61</ol> 62</nav> 63<main> 64<h1>The FizzBuzz Program</h1> 65<article> 66<header> 67<div role="toolbar" class="toolbar"> 68<strong>Share</strong> 69<a href="https://toot.kytta.dev/?text=Take a look at this article by @S0G@mastodon.social: https://steve0greatness.github.io/blog/fizzbuzz.html" title="Share to Mastodon"> 70<img src="/toot-kytta-dev-icon.png" width="16" height="16" aria-hidden="true" title="Share to Mastodon" /> 71</a> 72<a href="/blog/fizzbuzz.html" title="Direct link"> 73<img src="/link-icon.png" width="16" height="16" aria-hidden="true" title="Direct link" /> 74</a> 75<a href="/blog/fizzbuzz.txt" title="Markdown source"> 76<img src="/md-src.png" width="16" height="16" aria-hidden="true" /> 77</a> 78</div> 79<div class="time-stamps"> 80<time datetime="2022-02-20T00:00:00-08:00">2022 Feb 20 PST</time> 81- <span aria-hidden="true" style="font-style:italic">Revision as of: </span> <time datetime="2024-02-02T00:00:00-08:00" aria-label="Revision">2024 Feb 2 PST</time> 82 83</div> 84</header> 85<p>A FizzBuzz Program is a program used in many job interviews to see if a programmer is good at problem solving. There are many ways to make one.</p> 86 87<p>First let me tell you why I write these programs. These programs, at least in my opinion, are good when you're learning a new programming language. It gives you a problem to solve, and all you need to do to solve it. Incase you're wondering, the problem is to make a program that counts from 1 to 100 and replaces all multiples of 3 with Fizz, all multiples of 5 with Buzz, and multiples of both with FizzBuzz. Generally in interviews, they also ask you to add on more multiples, such as multiples of 7 are replaced with Fuzz, and multiples of 11 are replaced with Bizz.</p> 88 89<p>Now that I've told you what a FizzBuzz Program is, let me show you how I make them in Python.</p> 90 91<div class="codehilite"> 92<pre><span></span><code><span class="k">for</span> <span class="n">Index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">):</span> 93<span class="n">Response</span> <span class="o">=</span> <span class="s2">""</span> 94<span class="nb">print</span><span class="p">(</span><span class="n">Response</span><span class="p">)</span> 95</code></pre> 96</div> 97 98<p>The first thing I do is I create a for loop, and within it I put a print statement and a variable named toPrint.</p> 99 100<div class="codehilite"> 101<pre><span></span><code><span class="k">def</span> <span class="nf">FizzCompute</span><span class="p">(</span><span class="n">Number</span><span class="p">,</span> <span class="n">Divisor</span><span class="p">,</span> <span class="n">String</span><span class="p">):</span> 102<span class="k">return</span> <span class="n">String</span> <span class="k">if</span> <span class="n">Number</span> <span class="o">%</span> <span class="n">Divisor</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="s2">""</span> 103 104<span class="k">def</span> <span class="nf">SubstituteEmpty</span><span class="p">(</span><span class="n">String</span><span class="p">,</span> <span class="n">Number</span><span class="p">):</span> 105<span class="k">return</span> <span class="n">String</span> <span class="k">if</span> <span class="n">String</span> <span class="o">!=</span> <span class="s2">""</span> <span class="k">else</span> <span class="n">Number</span> 106 107<span class="k">for</span> <span class="n">Index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">):</span> 108<span class="n">Response</span> <span class="o">=</span> <span class="n">SubstituteEmpty</span><span class="p">(</span><span class="n">FizzCompute</span><span class="p">(</span><span class="n">Index</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">"Fizz"</span><span class="p">)</span> <span class="o">+</span> <span class="n">FizzCompute</span><span class="p">(</span><span class="n">Index</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="s2">"Buzz"</span><span class="p">),</span> <span class="n">Index</span><span class="p">)</span> 109<span class="nb">print</span><span class="p">(</span><span class="n">Response</span><span class="p">)</span> 110</code></pre> 111</div> 112 113<p><details> 114<summary>Output</summary> 115<samp>1 1162 117Fizz 1184 119Buzz 120Fizz 1217 1228 123Fizz 124Buzz 12511 126Fizz 12713 12814 129FizzBuzz 13016 13117 132Fizz 13319 134Buzz 135Fizz 13622 13723 138Fizz 139Buzz 14026 141Fizz 14228 14329 144FizzBuzz 14531 14632 147Fizz 14834 149Buzz 150Fizz 15137 15238 153Fizz 154Buzz 15541 156Fizz 15743 15844 159FizzBuzz 16046 16147 162Fizz 16349 164Buzz 165Fizz 16652 16753 168Fizz 169Buzz 17056 171Fizz 17258 17359 174FizzBuzz 17561 17662 177Fizz 17864 179Buzz 180Fizz 18167 18268 183Fizz 184Buzz 18571 186Fizz 18773 18874 189FizzBuzz 19076 19177 192Fizz 19379 194Buzz 195Fizz 19682 19783 198Fizz 199Buzz 20086 201Fizz 20288 20389 204FizzBuzz 20591 20692 207Fizz 20894 209Buzz 210Fizz 21197 21298 213Fizz</samp> 214</details></p> 215 216<p>The next thing I do is I define a function that checks if one number is a multiple of another, and if it is, then it returns the string, otherwise, it returns an empty string.</p> 217 218<p>Then I make a function that checks if a string is an empty one, if it is, then it returns a number.</p> 219 220<p>Once I have these 2 functions, I go back into the for loop and make the <code>Response</code> variable have the variable for checking if a string is empty(and if it is replace it with a number) check if 2 of the other function that check if one number is a multiple of another(and if it is, return a string). Finally, it prints the output.</p> 221 222<p>I've tried this method many times. Below are some examples of this method in action!</p> 223 224<ul> 225<li><a href="https://replit.com/@StevesGreatness/FizzBuzzKotlin">Kotlin</a></li> 226<li><a href="https://replit.com/@StevesGreatness/FizzBuzzlua">Lua</a></li> 227<li><a href="https://replit.com/@StevesGreatness/FizzBuzzpython">Python</a></li> 228<li><a href="https://replit.com/@StevesGreatness/FizzBuzzRuby">Ruby</a></li> 229</ul> 230 231</article> 232</main> 233<footer> 234<div class="footer-link-list-holder" role="group"> 235<span aria-hidden="true" id="footer-label-site-details" class="footer-link-list-label">Site Meta</span> 236<ol class="footer-link-list" aria-labelledby="footer-label-site-details"> 237<li><a href="/list/website-sources-mirrors.html">Source Code and Mirrors</a></li> 238<li><a href="https://steve0greatness.github.io/extras">Extras</a></li> 239</ol> 240</div> 241<div class="footer-link-list-holder" role="group"> 242<span aria-hidden="true" id="footer-label-social-accounts" class="footer-link-list-label">Social Accounts</span> 243<ol class="footer-link-list" aria-labelledby="footer-label-social-accounts"> 244<li><a href="https://mastodon.social/@S0G" rel="me">Mastodon</a></li> 245<li><a href="https://youtube.com/@s0g">YouTube</a></li> 246<li><a href="/list/link-tree.html">More...</a></li> 247</ol> 248</div> 249</footer> 250</body> 251 252</html>