[{"data":1,"prerenderedAt":645},["ShallowReactive",2],{"i-lucide:sun-moon":3,"i-lucide:menu":8,"post-\u002Fblog\u002F2023-08-14-fizzbuzzin-py-and-js":10,"surround-\u002Fblog\u002F2023-08-14-fizzbuzzin-py-and-js":628,"i-lucide:arrow-left":639,"i-lucide:sparkles":641,"i-lucide:user":643},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M12 2v2m2.837 12.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715M16 12a4 4 0 0 0-4-4m7-3l-1.256 1.256M20 12h2\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 5h16M4 12h16M4 19h16\"\u002F>",{"id":11,"title":12,"authors":13,"body":16,"date":615,"description":44,"extension":616,"meta":617,"navigation":66,"path":620,"seo":621,"stem":622,"tags":623,"toc":66,"__hash__":627},"blog\u002Fblog\u002F2023-08-14-fizzbuzzin-py-and-js.md","Solving FizzBuzz in Python and JavaScript",[14,15],"gpt","pfarmer",{"type":17,"value":18,"toc":610},"minimark",[19,24,28,31,35,38,288,291,344,347,355,358,362,365,575,578,594,597,603,606],[20,21,23],"h2",{"id":22},"what-is-fizzbuzz","What is FizzBuzz?",[25,26,27],"p",{},"FizzBuzz is a simple coding problem used in interviews to test basic programming skills. The task is to print the numbers from 1 to a given number, but print \"Fizz\" instead if the number is divisible by 3, \"Buzz\" instead if divisible by 5, and \"FizzBuzz\" if divisible by both 3 and 5.",[25,29,30],{},"The origins of FizzBuzz are unclear, but it has become a popular interview screening technique to quickly assess a candidate's ability to write basic code. Though simple, it requires knowledge of loops, conditionals, and modular division.",[20,32,34],{"id":33},"python-solution","Python solution",[25,36,37],{},"Here is how to implement FizzBuzz in Python:",[39,40,45],"pre",{"className":41,"code":42,"language":43,"meta":44,"style":44},"language-python shiki shiki-themes github-light github-dark-default","import sys\n\ndef fizzbuzz(end):\n  for num in range(1, end+1):\n    if num % 3 == 0 and num % 5 == 0:\n      print(\"FizzBuzz\")\n    elif num % 3 == 0:\n      print(\"Fizz\")\n    elif num % 5 == 0:\n      print(\"Buzz\")\n    else:\n      print(num)\n\nif __name__ == \"__main__\":\n  end = int(sys.argv[1])\n  fizzbuzz(end)\n","python","",[46,47,48,61,68,81,114,151,166,184,196,213,225,233,241,246,262,282],"code",{"__ignoreMap":44},[49,50,53,57],"span",{"class":51,"line":52},"line",1,[49,54,56],{"class":55},"sDgYj","import",[49,58,60],{"class":59},"szmH1"," sys\n",[49,62,64],{"class":51,"line":63},2,[49,65,67],{"emptyLinePlaceholder":66},true,"\n",[49,69,71,74,78],{"class":51,"line":70},3,[49,72,73],{"class":55},"def",[49,75,77],{"class":76},"sVjZL"," fizzbuzz",[49,79,80],{"class":59},"(end):\n",[49,82,84,87,90,93,97,100,103,106,109,111],{"class":51,"line":83},4,[49,85,86],{"class":55},"  for",[49,88,89],{"class":59}," num ",[49,91,92],{"class":55},"in",[49,94,96],{"class":95},"sPgVT"," range",[49,98,99],{"class":59},"(",[49,101,102],{"class":95},"1",[49,104,105],{"class":59},", end",[49,107,108],{"class":55},"+",[49,110,102],{"class":95},[49,112,113],{"class":59},"):\n",[49,115,117,120,122,125,128,131,134,137,139,141,144,146,148],{"class":51,"line":116},5,[49,118,119],{"class":55},"    if",[49,121,89],{"class":59},[49,123,124],{"class":55},"%",[49,126,127],{"class":95}," 3",[49,129,130],{"class":55}," ==",[49,132,133],{"class":95}," 0",[49,135,136],{"class":55}," and",[49,138,89],{"class":59},[49,140,124],{"class":55},[49,142,143],{"class":95}," 5",[49,145,130],{"class":55},[49,147,133],{"class":95},[49,149,150],{"class":59},":\n",[49,152,154,157,159,163],{"class":51,"line":153},6,[49,155,156],{"class":95},"      print",[49,158,99],{"class":59},[49,160,162],{"class":161},"sNbzA","\"FizzBuzz\"",[49,164,165],{"class":59},")\n",[49,167,169,172,174,176,178,180,182],{"class":51,"line":168},7,[49,170,171],{"class":55},"    elif",[49,173,89],{"class":59},[49,175,124],{"class":55},[49,177,127],{"class":95},[49,179,130],{"class":55},[49,181,133],{"class":95},[49,183,150],{"class":59},[49,185,187,189,191,194],{"class":51,"line":186},8,[49,188,156],{"class":95},[49,190,99],{"class":59},[49,192,193],{"class":161},"\"Fizz\"",[49,195,165],{"class":59},[49,197,199,201,203,205,207,209,211],{"class":51,"line":198},9,[49,200,171],{"class":55},[49,202,89],{"class":59},[49,204,124],{"class":55},[49,206,143],{"class":95},[49,208,130],{"class":55},[49,210,133],{"class":95},[49,212,150],{"class":59},[49,214,216,218,220,223],{"class":51,"line":215},10,[49,217,156],{"class":95},[49,219,99],{"class":59},[49,221,222],{"class":161},"\"Buzz\"",[49,224,165],{"class":59},[49,226,228,231],{"class":51,"line":227},11,[49,229,230],{"class":55},"    else",[49,232,150],{"class":59},[49,234,236,238],{"class":51,"line":235},12,[49,237,156],{"class":95},[49,239,240],{"class":59},"(num)\n",[49,242,244],{"class":51,"line":243},13,[49,245,67],{"emptyLinePlaceholder":66},[49,247,249,252,255,257,260],{"class":51,"line":248},14,[49,250,251],{"class":55},"if",[49,253,254],{"class":95}," __name__",[49,256,130],{"class":55},[49,258,259],{"class":161}," \"__main__\"",[49,261,150],{"class":59},[49,263,265,268,271,274,277,279],{"class":51,"line":264},15,[49,266,267],{"class":59},"  end ",[49,269,270],{"class":55},"=",[49,272,273],{"class":95}," int",[49,275,276],{"class":59},"(sys.argv[",[49,278,102],{"class":95},[49,280,281],{"class":59},"])\n",[49,283,285],{"class":51,"line":284},16,[49,286,287],{"class":59},"  fizzbuzz(end)\n",[25,289,290],{},"Let's break this down:",[292,293,294,301,307,326,332,338],"ul",{},[295,296,297,300],"li",{},[46,298,299],{},"import sys"," imports the sys module to access command line arguments",[295,302,303,306],{},[46,304,305],{},"def fizzbuzz(end):"," defines the fizzbuzz function",[295,308,309,310],{},"The main logic is inside the function:\n",[292,311,312,315,320,323],{},[295,313,314],{},"Loop from 1 to end",[295,316,317,318],{},"Check for divisibility by 3 and 5 using ",[46,319,124],{},[295,321,322],{},"Print FizzBuzz, Fizz or Buzz if conditions met",[295,324,325],{},"Else, print the number",[295,327,328,331],{},[46,329,330],{},"if __name__ == \"__main__\":"," runs the code only if executed directly",[295,333,334,337],{},[46,335,336],{},"end = int(sys.argv[1])"," gets the end number from command line",[295,339,340,343],{},[46,341,342],{},"fizzbuzz(end)"," calls the function",[25,345,346],{},"To run it:",[39,348,353],{"className":349,"code":351,"language":352},[350],"language-text","python fizzbuzz.py 100\n","text",[46,354,351],{"__ignoreMap":44},[25,356,357],{},"This structure allows the FizzBuzz logic to be reused by importing the script.",[20,359,361],{"id":360},"javascript-solution","JavaScript solution",[25,363,364],{},"Here is how to implement FizzBuzz in JavaScript using Node.js:",[39,366,370],{"className":367,"code":368,"language":369,"meta":44,"style":44},"language-js shiki shiki-themes github-light github-dark-default","const end = parseInt(process.argv[2]);\n\nfor (let i = 1; i \u003C= end; i++) {\n  if (i % 3 === 0 && i % 5 === 0) {\n    console.log(\"FizzBuzz\");\n  } else if (i % 3 === 0) {\n    console.log(\"Fizz\");\n  } else if (i % 5 === 0) {\n    console.log(\"Buzz\");\n  } else {\n    console.log(i);\n  }\n}\n","js",[46,371,372,395,399,433,465,480,503,515,535,547,556,565,570],{"__ignoreMap":44},[49,373,374,377,380,383,386,389,392],{"class":51,"line":52},[49,375,376],{"class":55},"const",[49,378,379],{"class":95}," end",[49,381,382],{"class":55}," =",[49,384,385],{"class":76}," parseInt",[49,387,388],{"class":59},"(process.argv[",[49,390,391],{"class":95},"2",[49,393,394],{"class":59},"]);\n",[49,396,397],{"class":51,"line":63},[49,398,67],{"emptyLinePlaceholder":66},[49,400,401,404,407,410,413,415,418,421,424,427,430],{"class":51,"line":70},[49,402,403],{"class":55},"for",[49,405,406],{"class":59}," (",[49,408,409],{"class":55},"let",[49,411,412],{"class":59}," i ",[49,414,270],{"class":55},[49,416,417],{"class":95}," 1",[49,419,420],{"class":59},"; i ",[49,422,423],{"class":55},"\u003C=",[49,425,426],{"class":59}," end; i",[49,428,429],{"class":55},"++",[49,431,432],{"class":59},") {\n",[49,434,435,438,441,443,445,448,450,453,455,457,459,461,463],{"class":51,"line":83},[49,436,437],{"class":55},"  if",[49,439,440],{"class":59}," (i ",[49,442,124],{"class":55},[49,444,127],{"class":95},[49,446,447],{"class":55}," ===",[49,449,133],{"class":95},[49,451,452],{"class":55}," &&",[49,454,412],{"class":59},[49,456,124],{"class":55},[49,458,143],{"class":95},[49,460,447],{"class":55},[49,462,133],{"class":95},[49,464,432],{"class":59},[49,466,467,470,473,475,477],{"class":51,"line":116},[49,468,469],{"class":59},"    console.",[49,471,472],{"class":76},"log",[49,474,99],{"class":59},[49,476,162],{"class":161},[49,478,479],{"class":59},");\n",[49,481,482,485,488,491,493,495,497,499,501],{"class":51,"line":153},[49,483,484],{"class":59},"  } ",[49,486,487],{"class":55},"else",[49,489,490],{"class":55}," if",[49,492,440],{"class":59},[49,494,124],{"class":55},[49,496,127],{"class":95},[49,498,447],{"class":55},[49,500,133],{"class":95},[49,502,432],{"class":59},[49,504,505,507,509,511,513],{"class":51,"line":168},[49,506,469],{"class":59},[49,508,472],{"class":76},[49,510,99],{"class":59},[49,512,193],{"class":161},[49,514,479],{"class":59},[49,516,517,519,521,523,525,527,529,531,533],{"class":51,"line":186},[49,518,484],{"class":59},[49,520,487],{"class":55},[49,522,490],{"class":55},[49,524,440],{"class":59},[49,526,124],{"class":55},[49,528,143],{"class":95},[49,530,447],{"class":55},[49,532,133],{"class":95},[49,534,432],{"class":59},[49,536,537,539,541,543,545],{"class":51,"line":198},[49,538,469],{"class":59},[49,540,472],{"class":76},[49,542,99],{"class":59},[49,544,222],{"class":161},[49,546,479],{"class":59},[49,548,549,551,553],{"class":51,"line":215},[49,550,484],{"class":59},[49,552,487],{"class":55},[49,554,555],{"class":59}," {\n",[49,557,558,560,562],{"class":51,"line":227},[49,559,469],{"class":59},[49,561,472],{"class":76},[49,563,564],{"class":59},"(i);\n",[49,566,567],{"class":51,"line":235},[49,568,569],{"class":59},"  }\n",[49,571,572],{"class":51,"line":243},[49,573,574],{"class":59},"}\n",[25,576,577],{},"The logic follows the same structure:",[292,579,580,583,585,588,591],{},[295,581,582],{},"Get the end number from command line argument",[295,584,314],{},[295,586,587],{},"Check for divisibility by 3 and 5",[295,589,590],{},"Print FizzBuzz, Fizz or Buzz based on conditions",[295,592,593],{},"Else print the number",[25,595,596],{},"To run:",[39,598,601],{"className":599,"code":600,"language":352},[350],"node fizzbuzz.js 100\n",[46,602,600],{"__ignoreMap":44},[25,604,605],{},"FizzBuzz tests basic coding concepts in any language. By accepting input and using modular division and conditionals, we can easily solve this problem. This example demonstrates a structured approach in both Python and JavaScript.",[607,608,609],"style",{},"html pre.shiki code .sDgYj, html code.shiki .sDgYj{--shiki-default:#D73A49;--shiki-dark:#FF7B72}html pre.shiki code .szmH1, html code.shiki .szmH1{--shiki-default:#24292E;--shiki-dark:#E6EDF3}html pre.shiki code .sVjZL, html code.shiki .sVjZL{--shiki-default:#6F42C1;--shiki-dark:#D2A8FF}html pre.shiki code .sPgVT, html code.shiki .sPgVT{--shiki-default:#005CC5;--shiki-dark:#79C0FF}html pre.shiki code .sNbzA, html code.shiki .sNbzA{--shiki-default:#032F62;--shiki-dark:#A5D6FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":44,"searchDepth":63,"depth":63,"links":611},[612,613,614],{"id":22,"depth":63,"text":23},{"id":33,"depth":63,"text":34},{"id":360,"depth":63,"text":361},"2023-08-14","md",{"type":618,"layout":619},"post","blog_page","\u002Fblog\u002F2023-08-14-fizzbuzzin-py-and-js",{"title":12,"description":44},"blog\u002F2023-08-14-fizzbuzzin-py-and-js",[624,625,43,626],"programming","javascript","interview","Hbe54Ws939iFWFuFOnQEv2EgHP4QJ0m0XSMdWO1a0xQ",[629,634],{"title":630,"path":631,"stem":632,"date":633,"children":-1},"Leveraging Map, Reduce and Filter for Cleaner Code","\u002Fblog\u002F2023-07-21-map-reduce-filter","blog\u002F2023-07-21-map-reduce-filter","2023-07-21",{"title":635,"path":636,"stem":637,"date":638,"children":-1},"Optional Chaining in JavaScript","\u002Fblog\u002F2023-09-01-optional-chaining-in-javascript","blog\u002F2023-09-01-optional-chaining-in-javascript","2023-09-01",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":640},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m12 19l-7-7l7-7m7 7H5\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":642},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594zM20 2v4m2-2h-4\"\u002F>\u003Ccircle cx=\"4\" cy=\"20\" r=\"2\"\u002F>\u003C\u002Fg>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":644},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2\"\u002F>\u003Ccircle cx=\"12\" cy=\"7\" r=\"4\"\u002F>\u003C\u002Fg>",1783616165790]