| Bytes | Lang | Time | Link |
|---|---|---|---|
| 034 | Uiua | 240403T153509Z | noodle p |
| 088 | AutoHotkey v2 | 250922T070721Z | amorphob |
| 043 | BQN CBQN | 220511T171643Z | DLosc |
| 012 | Vyxal 3 | 250226T142927Z | Themooni |
| 176 | SAKO | 250314T154216Z | Acrimori |
| 072 | Tcl | 170121T232409Z | sergiol |
| 032 | Jalapeño | 250212T031449Z | ATaco |
| 3364 | ☾ | 250126T043736Z | noodle p |
| 256 | Hatchback | 250206T175545Z | madeforl |
| 080 | CASIO BASIC CASIO fx9750GIII | 250129T175415Z | madeforl |
| 561 | Bespoke | 250116T002101Z | Josiah W |
| 135 | Acc!! | 250115T212938Z | emanresu |
| 197 | ibe | 241127T213753Z | madeforl |
| 056 | AWK | 241126T164255Z | xrs |
| 097 | BrainChild | 241104T041822Z | ATaco |
| 029 | Iogii | 241030T131057Z | lyxal |
| 032 | TinyAPL | 241016T144548Z | noodle p |
| 064 | TinyAPL | 241016T033505Z | emanresu |
| 142 | Scratch | 241016T193630Z | ayaan098 |
| 093 | Perl 5 | 150924T193932Z | ASCIIThe |
| 114 | Boo | 220513T012529Z | DaCuteRa |
| 125 | Fortran GFortran | 221104T222148Z | roblogic |
| 050 | Jellyfish | 221116T041341Z | angel_p_ |
| 080 | tinylisp 2 | 240821T230636Z | DLosc |
| 133 | Rockstar | 210902T164238Z | Shaggy |
| 130 | tinylisp | 171028T042042Z | DLosc |
| 047 | J | 240721T073806Z | noodle p |
| 046 | J | 190226T171203Z | Bailis C |
| 068 | gnuplot | 240717T202543Z | Glory2Uk |
| 139 | Go | 150925T190706Z | Justin P |
| 237 | Acc!! | 171030T051014Z | DLosc |
| 183 | TypeScript's type system | 231212T144348Z | noodle p |
| 090 | Easyfuck | 240325T175031Z | Quadrupl |
| 187 | Fortran | 170803T152736Z | lewisfis |
| 106 | Janet | 231006T235504Z | DaCuteRa |
| 048 | Uiua | 230929T113717Z | lyxal |
| 063 | sclin | 230908T002033Z | lyxal |
| nan | Aubergine | 230827T082907Z | angel_p_ |
| 485 | HTML & CSS | 211122T011506Z | customco |
| 666 | Minecraft Function | 230805T163535Z | user1003 |
| nan | Common Lisp | 150925T090153Z | coredump |
| nan | SAS 4GL | 230509T133234Z | Bartosz |
| 011 | Thunno 2 N | 230412T104212Z | The Thon |
| 244 | Desmos | 230507T135233Z | Jakdad J |
| 8125 | Vyxal | 200829T054352Z | lyxal |
| 033 | vemf | 230328T034849Z | lyxal |
| 059 | Julia 59 char | 230221T144649Z | oliverjo |
| 257 | Typescript Type System + tsarithmetic | 230222T013312Z | noodle p |
| 043 | jq nr | 230221T170151Z | pmf |
| nan | 230104T111827Z | The Thon | |
| 091 | Pyt | 230128T171725Z | Kip the |
| 044 | Rattle | 200814T192545Z | d01 |
| nan | 230104T122052Z | lyxal | |
| nan | Miled | 221213T094351Z | atzlt |
| 269 | Functional | 221116T151619Z | angel_p_ |
| 062 | Klong [klongpy] | 221206T133212Z | lyxal |
| 580 | Python | 221204T024909Z | Scovetta |
| 210 | Whitespacev0.3 on ideone.com | 221120T143053Z | angel_p_ |
| 022 | Terse | 221117T211839Z | Gymhgy |
| 202 | Assembly MIPS | 221110T170020Z | EasyasPi |
| nan | Pure Bash | 221105T030046Z | IY5dVSjA |
| 047 | Phooey | 210129T124802Z | EasyasPi |
| 142 | MediaWiki markup + WP templates | 220831T170903Z | user1741 |
| 162 | Pascal | 221105T115843Z | Kai Burg |
| 051 | PowerShell | 150924T194454Z | AdmBorkB |
| 035 | Convex | 221015T051943Z | lyxal |
| nan | Fig | 220908T184339Z | Seggan |
| nan | Fig | 220908T020052Z | lyxal |
| 090 | D | 220818T194754Z | weltenst |
| 088 | Dart | 151029T071810Z | lrn |
| 420 | CATHY | 220626T224858Z | emanresu |
| 162 | Cubestack | 220613T010544Z | lyxal |
| 072 | Kustom | 220603T132305Z | Leaf |
| 131 | Squirrel | 220514T202342Z | DaCuteRa |
| 057 | rSNBATWPL | 220511T161527Z | rydwolf |
| 058 | PARI/GP | 220504T000058Z | alephalp |
| 137 | V vlang.io | 220503T221458Z | DaCuteRa |
| 183 | SQLite | 220503T213702Z | DaCuteRa |
| 044 | Raku | 220503T211416Z | DaCuteRa |
| 165 | Prolog SWI | 220503T034601Z | DaCuteRa |
| 1777 | Morse Code | 220503T161458Z | DaCuteRa |
| 180 | Pascal FPC | 220503T020655Z | DaCuteRa |
| 072 | Nim | 220503T020236Z | DaCuteRa |
| 056 | JavaScript code.golf | 220503T011406Z | DaCuteRa |
| 187 | Fortran GFortran | 220503T003516Z | DaCuteRa |
| 115 | D | 220503T002054Z | DaCuteRa |
| 114 | Crystal | 220502T234142Z | DaCuteRa |
| 037 | Aya | 220208T000733Z | Blazing |
| 101 | Quipu | 210902T162852Z | Aaroneou |
| 117 | Kotlin | 220131T180936Z | random p |
| 102 | Python | 220130T170946Z | Oliver |
| 012 | Vyxal | 210627T150030Z | math sca |
| 009 | Apple Shortcuts | 220129T064720Z | Aaroneou |
| nan | Apple shortcut language | 220128T222834Z | emanresu |
| 030 | Pip | 150926T024536Z | DLosc |
| 078 | jq | 211122T013957Z | customco |
| 185 | RickRollLang | 211111T142207Z | scpchick |
| nan | Pure Bash | 211111T101959Z | user1004 |
| 187 | aussie++ | 211030T065438Z | lyxal |
| 089 | Dash and utils | 210910T142330Z | bxm |
| 635 | XML + XSLT | 210911T041308Z | lyxal |
| 082 | jq | 210902T102311Z | AviFS |
| 011 | Fact | 210830T014509Z | user1067 |
| 063 | ><> | 150925T090652Z | Aaron |
| 123 | Javastack | 210808T133203Z | lyxal |
| 145 | Javastack | 210808T075156Z | wasif |
| 025 | 05AB1E | 210809T134412Z | lyxal |
| 073 | PostScript | 210725T002346Z | Pertinen |
| 690 | Perl 5 ppencodecompatible | 210803T085148Z | user1004 |
| 059 | Python 3 | 210805T042744Z | Ryno |
| 202 | C++20 | 210714T031840Z | Matthew |
| 092 | Squire | 210604T172124Z | EasyasPi |
| 043 | Knight | 210522T040556Z | EasyasPi |
| 058 | BRASCA | 210513T133134Z | RezNesX |
| 090 | Pinecone | 210421T161348Z | wasif |
| 164 | PPL | 210419T190634Z | user1006 |
| 098 | Branch | 210417T004458Z | hyperneu |
| 5743 | Turing Machine Code | 210203T145425Z | ouflak |
| 115 | M4 | 210319T130957Z | user1004 |
| 9591 | C# | 210331T085805Z | baltermi |
| 079 | Excel | 210302T154225Z | Axuary |
| 021 | Stax | 210402T105540Z | Razetime |
| 3299 | Deadfish~ | 210331T215705Z | emanresu |
| 081 | Pxem | 210320T091017Z | user1004 |
| 095 | Kotlin | 210325T000855Z | Roan Coo |
| nan | Factor | 210322T130420Z | hdrz |
| 081 | Excel VBA | 170820T175100Z | Taylor R |
| 325 | CSASM v2.1.2.1 | 210320T164050Z | absolute |
| nan | Dash | 210319T132434Z | user1004 |
| 094 | sed 4.2.2 r | 210312T212315Z | Mitch Sc |
| 097 | C# | 210319T000958Z | mattnewp |
| 072 | Burlesque | 210318T114431Z | lyxal |
| 047 | Retina | 210314T114717Z | Neil |
| 045 | jq | 210310T150817Z | Wezl |
| 235 | /// | 210216T001227Z | Samuel W |
| 076 | JavaScript | 210208T075722Z | user1006 |
| 126 | GNU sed 4.2.2 | 210207T133322Z | seshouma |
| 091 | Java 91 Bytes loop without class declaration or main function by Alex North | 210201T005807Z | Xander W |
| 049 | ThumbGolf | 210205T065913Z | EasyasPi |
| 136 | Java | 210130T211046Z | Xander W |
| 150 | Whispers v2 | 210203T235100Z | Leo |
| 6968 | JavaScript | 210131T112625Z | atzlt |
| 157 | Myddin | 210131T012953Z | binaryca |
| 099 | Javascript | 210128T115421Z | Rohan |
| 073 | Mouse83/Mouse2002 | 210129T104052Z | lyxal |
| 081 | BRASCA | 210126T114124Z | lyxal |
| nan | GNU AWK | 201226T044157Z | Pedro Ma |
| 073 | Python 3 | 210116T134611Z | nTerior |
| 031 | Canvas | 210103T071015Z | lyxal |
| 086 | FALSE | 201228T190417Z | ReedsSho |
| 096 | uBASIC | 180308T221906Z | Taylor R |
| 037 | 05AB1E | 201120T183850Z | Makonede |
| 027 | Japt R | 201119T152034Z | Shaggy |
| 057 | Kakoune | 201111T125838Z | xenia |
| 018 | Arn hm | 200815T215616Z | ZippyMag |
| 378 | !@#$%^&*_+ | 201104T122628Z | Conor O& |
| 353 | LolCode | 201103T152209Z | OCDkirby |
| 095 | Forth gforth | 201102T233313Z | lyxal |
| 112 | AppleSoft BASIC | 201025T224722Z | roblogic |
| 522 | Spaghetti | 200921T131012Z | Razetime |
| 059 | ><> | 171220T130103Z | Jo King |
| 066 | R | 200717T102958Z | zydras |
| 240 | MineFriff | 190920T231642Z | lyxal |
| 082 | Haskell | 150926T224318Z | lynn |
| 089 | Add++ | 200919T013858Z | lyxal |
| 046 | Add++ i | 200909T154731Z | caird co |
| 029 | Charcoal | 200905T022159Z | lyxal |
| 060 | MAWP 2.0 | 200903T132343Z | Dion |
| 057 | LiveScript | 200901T030739Z | xunxekri |
| 056 | Python 2 | 150924T194313Z | feersum |
| 416 | Integral | 200804T062326Z | lyxal |
| 073 | Python 2 | 200803T091759Z | Thomas |
| 120 | MAWP | 200723T102808Z | Dion |
| 060 | International Phonetic Esoteric Language | 200620T154257Z | bigyihsu |
| 149 | Windows Batch | 150928T214010Z | dbenham |
| 2221 | W n | 200217T145329Z | user9206 |
| 058 | Bash | 200321T110403Z | Anders K |
| 166 | Erlang escript | 200316T004359Z | user9206 |
| 128 | Symja | 200229T031325Z | lyxal |
| 043 | Keg | 191117T080056Z | lyxal |
| 027 | Stax | 200217T164039Z | Nanajnai |
| 123 | Visual Basic Script | 190829T193623Z | Sagittar |
| 2923 | W d | 191214T081558Z | user8505 |
| 058 | Javascript 78 but kinda | 200110T005403Z | Sebasti& |
| 114 | Rust | 200116T222523Z | Axel Mon |
| 129 | sed 4.2.2 | 200110T145343Z | user4180 |
| 052 | APL | 200110T120435Z | Popov |
| 022 | DIVSPL | 200104T140220Z | Ethan Mc |
| 133 | MC6000 ASM Shenzhen I/O | 191222T121805Z | soweli N |
| 7568 | 80386 machine code + DOS | 190827T171216Z | 640KB |
| 064 | Scala | 191211T182651Z | gregam3 |
| 080 | Python 3 | 191121T023703Z | PythoNis |
| 078 | Wren | 191117T034345Z | user8505 |
| 087 | Julia | 191116T140651Z | caseyk |
| 061 | Zsh | 190828T131858Z | roblogic |
| 048 | Ink | 190227T012813Z | Sara J |
| 115 | Hoon | 190923T060324Z | mattnewp |
| 6015 | Seed | 190614T100747Z | Kamila S |
| 087 | Julia | 190827T193855Z | Sagittar |
| 108 | SQL Oracle | 150929T003628Z | MT0 |
| 114 | SNOBOL4 CSNOBOL4 | 180131T151031Z | Giuseppe |
| 041 | Pip | 190628T195451Z | Kenzie |
| 060 | 33 | 190721T095227Z | TheOnlyM |
| 037 | APL Dyalog Unicode | 190614T064240Z | Adá |
| 024 | 05AB1E | 190604T162013Z | Grimmy |
| 094 | C | 190323T114552Z | qookie |
| 107 | Racket | 190326T235930Z | waf9000 |
| 118 | Scheme | 190326T224831Z | waf9000 |
| 122 | C++ | 190322T134057Z | Yoris |
| 079 | JavaScript | 190308T003955Z | Ryan Knu |
| 129 | Java 8 | 190307T223618Z | Benjamin |
| 499 | brainfuck | 190228T011129Z | ThePlasm |
| 048 | Brachylog | 190228T105929Z | Unrelate |
| nan | bytes | 160422T162505Z | phrebh |
| 071 | JavaScript Node.js | 190227T195341Z | Kamil Na |
| 086 | BuzzFizz | 181221T061706Z | ais523 |
| 080 | Javascript | 190227T121521Z | Jeyanth |
| 065 | JavaScript | 150925T134551Z | Diego To |
| 101 | Alchemist | 190203T011728Z | Jo King |
| 080 | Dart | 181123T151008Z | Elcan |
| 072 | Julia 1.0 | 181123T050328Z | DLosc |
| 071 | Bash | 150925T041936Z | Dennis |
| 039 | Pyth | 181004T231547Z | Tryer |
| 3978 | APLNARS | 171206T141204Z | user5898 |
| 043 | K oK | 180927T161321Z | mkst |
| 119 | C# | 181002T133313Z | Maz |
| 070 | R | 150924T211107Z | MickyT |
| 022 | MathGolf | 180912T082003Z | maxb |
| 062 | Python 3 | 180913T153432Z | Josh B. |
| 063 | Groovy | 180913T114705Z | archange |
| 080 | Lua | 180804T054726Z | GalladeG |
| 050 | 12BASIC | 180504T163558Z | 12Me21 |
| 105 | Python 2.7 | 180718T104125Z | Stealthy |
| 412 | BrainFlak | 180407T104513Z | Jo King |
| 307 | Whitespace | 180314T142045Z | Kevin Cr |
| 206 | brainfuck | 180713T132034Z | Mitch Sc |
| 150 | Pyret | 180619T231401Z | Tango |
| 094 | QB64 | 150927T221159Z | DLosc |
| 084 | Common Lisp | 170217T224335Z | user6516 |
| 196 | Ada GNAT | 180424T101907Z | ASCII-on |
| 107 | ORACLE SQL | 180516T095713Z | Kamil Mę |
| 057 | Phooey | 180420T130113Z | Conor O& |
| nan | Go | 150929T115419Z | Kristoff |
| 110 | TransactSQL | 160506T020154Z | Phrancis |
| 098 | Forth | 180418T232139Z | Alex |
| 298 | Ada GNAT | 180418T215555Z | LambdaBe |
| 198 | /// | 180407T045244Z | Conor O& |
| 036 | Jstx | 180401T065534Z | Quantum6 |
| nan | TIS | 180328T180302Z | Phlarx |
| 076 | Hexagony | 180324T114047Z | Jo King |
| nan | sed | 180324T042554Z | lucasb |
| 035 | Husk | 180323T225107Z | Sophia L |
| 258 | brainfuck | 171124T074547Z | Jo King |
| 061 | Befunge93 | 171123T110915Z | Jo King |
| 250 | KoopaScript | 180308T194853Z | Jhynjhir |
| 108 | Yabasic | 180308T221924Z | Taylor R |
| 151 | Visual Basic .NET Mono | 180308T220625Z | Taylor R |
| 116 | MYBASIC | 180308T215818Z | Taylor R |
| 070 | SmileBASIC | 170205T211759Z | 12Me21 |
| 049 | Wumpus | 180214T145608Z | Martin E |
| 688 | kavod | 180205T225849Z | Conor O& |
| 229 | 17 | 180204T102717Z | Hugh Wil |
| 055 | Retina | 150925T080255Z | Martin E |
| 073 | J | 180102T201835Z | Bolce Bu |
| 152 | face | 180102T173804Z | Doorknob |
| 115 | Kotlin | 171220T223211Z | Damiano |
| 324 | Symbolic Python | 171207T211105Z | FlipTack |
| 101 | C gcc | 171207T195500Z | user5898 |
| 152 | C | 171207T172503Z | Kishan K |
| nan | Clean | 171207T091646Z | Οurous |
| 093 | APL Nars | 171205T192255Z | user5898 |
| 060 | nodejs repl | 171204T221838Z | Armand |
| 127 | Java OpenJDK 8 | 171123T113224Z | Luca H |
| 222 | Modula2 | 171109T013654Z | kernigh |
| 100 | AppleScript | 171025T023304Z | kernigh |
| 059 | Funky | 171025T042015Z | ATaco |
| 029 | 05AB1E | 170612T231039Z | Datboi |
| nan | Extremely late answer and for a language that has already a bit too many answers | 170926T091519Z | Brian H. |
| 090 | Jq 1.5 | 170926T061358Z | jq170727 |
| 046 | Recursiva | 170914T115946Z | 0xffcour |
| 057 | Python 2 | 170925T120833Z | german_g |
| 055 | groovy | 170924T071608Z | kau |
| 152 | AsciiDots | 170925T022652Z | user3141 |
| 938 | TrumpScript | 170921T184738Z | Grzegorz |
| 059 | Python 2.7 | 170825T154401Z | Cóe |
| 060 | Python 2 | 150924T193723Z | Blue |
| 172 | MATLAB | 150924T234107Z | Luis Men |
| 304 | TeX | 170820T000208Z | Leaky Nu |
| 106 | Python 2 | 170805T092626Z | Husnain |
| 041 | APL | 170715T002952Z | Ala' |
| 068 | Ruby | 150924T212332Z | Camden N |
| 049 | q/kdb+ | 170527T211420Z | mkst |
| 097 | Swift | 170627T200635Z | SrB |
| 072 | Micro | 170610T003458Z | raddish0 |
| 040 | braingasm | 170527T155854Z | daniero |
| 208 | /// | 170515T025711Z | Esolangi |
| 081 | Fourier | 170515T094515Z | Beta Dec |
| 065 | Ruby | 170516T091034Z | marmelad |
| 081 | REXX 81 Bytes | 170516T095141Z | theblitz |
| 221 | Turtlèd | 170515T093109Z | Destruct |
| 070 | Julia | 170515T045952Z | eaglgene |
| 141 | S.I.L.O.S | 170514T151245Z | Rohan Jh |
| 062 | 8086 machine code | 170310T074132Z | user5434 |
| 052 | K | 170313T005003Z | Chromozo |
| 145 | Java | 170312T132244Z | user6333 |
| 126 | Lua | 170310T174339Z | Josh |
| 094 | REXX | 170310T131437Z | idrougge |
| 217 | Cardinal | 170223T134607Z | fəˈnɛtɪk |
| 031 | Japt | 151104T171918Z | ETHprodu |
| 064 | Plain Javascript no console.log & no alert | 170210T062356Z | BTC |
| 056 | Javascript | 170210T062031Z | BTC |
| 013 | Valyrio | 170205T205003Z | user6357 |
| 065 | Befunge | 170122T162157Z | James Ho |
| 061 | Mathematica | 170120T175216Z | A Simmon |
| 076 | DUP | 161223T220131Z | M L |
| 425 | Brainfuck | 161227T093952Z | Forcent |
| 073 | Nim | 150925T001702Z | Sp3000 |
| 044 | Vim | 161013T045218Z | udioica |
| 061 | Groovy | 160911T203830Z | kinbiko |
| 090 | JavaScript using external library | 160725T155548Z | applejac |
| 187 | ROOP | 160725T051321Z | DarkPhan |
| 098 | Oration | 160606T175830Z | Żáł |
| 072 | Ruby | 160603T144630Z | user5418 |
| 229 | /// | 160603T141752Z | Leaky Nu |
| 182 | Elixir | 160507T092602Z | lad2025 |
| 091 | Python 91 Bytes | 160507T063439Z | JoshK |
| 136 | Tcl | 160506T015659Z | Dút |
| 064 | Javascript | 160506T000604Z | RuteNL |
| 056 | Vim | 160505T202005Z | DJMcMayh |
| 036 | Seriously | 151110T230534Z | user4594 |
| 020 | Jelly | 160126T151736Z | Dennis |
| 091 | Hexagony | 160305T215643Z | M L |
| 191 | Javascript | 160310T093430Z | Harshal |
| 091 | Python 2 | 160308T182458Z | Oliver N |
| 172 | XQuery 3 | 160312T012708Z | Aaron |
| 115 | Kotlin | 160310T193928Z | Justinw |
| nan | 150924T221026Z | Sam Este | |
| 145 | Kotlin | 160310T164641Z | Matt Sam |
| 842 | ArnoldC | 160310T173054Z | drolex |
| nan | beeswax | 151225T025812Z | M L |
| 208 | TCL | 160308T041138Z | Benjamin |
| 122 | Racket | 160307T061522Z | Winny |
| 054 | Python 2 REPL | 160307T022052Z | Tersosau |
| 073 | Mathematica | 150924T211548Z | DavidC |
| 126 | Hoon | 160302T200901Z | RenderSe |
| 130 | D | 160302T155841Z | cat |
| 174 | C# | 160226T175917Z | froggyof |
| 062 | JavaScript | 151103T003822Z | Mama Fun |
| 031 | Jolf | 160224T234455Z | Conor O& |
| 046 | Perl 6 | 160224T205439Z | Hotkeys |
| 3247 | 𝔼𝕊𝕄𝕚𝕟 | 151103T004319Z | Mama Fun |
| 031 | Rotor | 151108T015013Z | a spaghe |
| 062 | Mathematica | 150925T143221Z | LegionMa |
| 131 | Rust | 151216T091155Z | S22h |
| 077 | Javascript ES6 | 151213T213218Z | Qwertiy |
| 051 | scg | 151213T155025Z | anOKsqui |
| 057 | ShapeScript | 151115T040547Z | Dennis |
| 1597 | Brainfuck | 151115T101032Z | flawr |
| 040 | Gol><> | 151027T123536Z | Sp3000 |
| 050 | APL | 151108T093518Z | user4691 |
| 112 | Hexagony | 151108T205802Z | Martin E |
| 111 | F# | 151104T170403Z | mattnewp |
| 115 | C++ | 150926T011227Z | mattnewp |
| 072 | Python 2 | 151102T225945Z | James Mu |
| 185 | Scratch | 151028T062133Z | Tuesday |
| 030 | Pyth | 150924T194711Z | FryAmThe |
| 069 | Groovy | 150927T174510Z | The Code |
| 082 | MoonScript | 150926T050448Z | Veer Sin |
| 080 | Groovy | 151029T214233Z | K. Klass |
| 075 | Swift | 151027T121032Z | Richard |
| 050 | Minkolang | 151025T232654Z | El'e |
| 129 | Bubblegum | 150924T193702Z | Dennis |
| 094 | Scala | 150926T202318Z | gilad ho |
| 097 | Snowman 1.0.2 | 151002T212546Z | Doorknob |
| 090 | Scala | 151002T212448Z | Ben |
| 106 | OCaml | 151001T032844Z | feersum |
| 052 | O | 151001T225731Z | MickyT |
| 091 | rs | 150928T142040Z | kirbyfan |
| 106 | MSXBASIC | 150930T085958Z | Konamima |
| 142 | C# | 150928T211737Z | Ken Greg |
| 083 | C | 150928T224045Z | Stefano |
| 172 | Windows Batch | 150928T213716Z | dbenham |
| 110 | haxe | 150928T202934Z | Aurea |
| 186 | C# using LINQ | 150928T155514Z | Bill T |
| 106 | UniBasic | 150928T180906Z | Ken Greg |
| 054 | MUMPS | 150924T200320Z | senshin |
| 087 | Commodore Basic | 150926T060557Z | Mark |
| 124 | C# | 150924T214058Z | Pierre-L |
| 037 | GolfScript | 150928T002256Z | brendan |
| 133 | Python 2 | 150927T174756Z | tommy_p1 |
| 041 | Bash + coreutils | 150927T225537Z | lynn |
| 063 | zsh | 150926T083831Z | karolba |
| 050 | Ruby | 150927T224409Z | lynn |
| 072 | Lua | 150927T221556Z | lynn |
| 115 | STATA | 150927T204324Z | bmarks |
| 059 | Python 3 | 150927T170611Z | Jean Nas |
| 074 | C | 150927T164020Z | lynn |
| 049 | Perl 5 | 150924T200553Z | Dom Hast |
| 094 | Labyrinth | 150926T125606Z | Sp3000 |
| 086 | Lua | 150924T211512Z | Nico A |
| 059 | TIBASIC | 150926T221514Z | lirtosia |
| 6462 | dc | 150924T214923Z | daniero |
| 075 | 80386 machine code + DOS | 150926T094111Z | anatolyg |
| 077 | Swift | 150926T070823Z | Najkin |
| 094 | MATLAB | 150925T135330Z | Tom Carp |
| 213 | Fortran | 150926T024527Z | casey |
| 071 | Groovy | 150926T003904Z | Kleyguer |
| 146 | VB.Net | 150925T084617Z | Najkin |
| 059 | Ruby | 150925T224647Z | Reinstat |
Uiua, 43 39 37 35 34 bytes
≡&p↥⊃°⋕⍚(˜▽"FizzBuzz"▽4¬◿3_5)⇡₁100
80 # this runs on each 1 to 100; consider the 80th run
80
=0◿3_5 # check divisibility against 3 and 5
[0 1]
▽4 # take 4 of each
[0 0 0 0 1 1 1 1]
▽⊙"FizzBuzz" # use this as a filter on "FizzBuzz"
"Buzz"
⍚(▽⊙"FizzBuzz"▽4=0◿3_5)⇡₁100
[""│""│"Fizz"│""│"Buzz"│"Fizz"│""|...90 more...│""│"Fizz"│"Buzz"]
# max of each with the number
↥⊃°⋕⍚(▽⊙"FizzBuzz"▽4=0◿3_5)⇡₁100
["1"│"2"│"Fizz"│"4"│"Buzz"│"Fizz"│"7"|...|"98"│"Fizz"│"Buzz"]
≡&p # print each line
AutoHotkey (v2), 88 bytes
Very straightforward ternary operations.
loop 100
f:=mod(n:=a_index,5),o.=(mod(n,3)?f?n:"Buzz":f?"Fizz":"FizzBuzz") "`n"
msgbox o
BQN (CBQN), 48 43 bytes
-5 bytes thanks to noodle person
(•Out·⊑·∨•Fmt⋈"FizzBuzz"/˜4/0=3‿5|⊢)¨1+↕100
Explanation
(...)¨1+↕100
↕100 ⟨ 0 1 2 ... 98 99 ⟩
1+ ⟨ 1 2 3 ... 99 100 ⟩
(...)¨ Apply this function to each:
•Out·⊑·∨•Fmt⋈"FizzBuzz"/˜4/0=3‿5|⊢
⊢ The argument number
3‿5| Mod 3 and mod 5, in a list
0= Is each equal to 0? (1 if so, 0 if not)
4/ Make 4 copies of each element
"FizzBuzz" String "FizzBuzz"
/˜ Repeat each letter a number of times
equal to the corresponding number
from the previous step, giving
"", "Fizz", "Buzz", or "FizzBuzz"
⋈ Pair with
•Fmt The initial number cast to string
∨ Sort that list of two strings descending
⊑· Take the first one (i.e. the one
that is lexicographically larger)
•Out· Print that string with a newline
Vyxal 3, 12 bytes
-6 bytes by weird glyphs
-2 bytes by noodle person
-5 bytes by me
⑤ƛ35f≛kF½•∨,
⑤ƛ35f≛kF½•∨,
⑤ƛ # map over 1..100
35f # does 3 or 5...
≛ # divide the number? result is 2-wide bitmask
kF½ # ["Fizz", "Buzz"]
• # multiply previous by bitmask, then concatenate
∨ # if previous is falsey (empty string), push implicit n
, # print
💎
Created with the help of Luminespire.
<script type="vyxal3">
⑤ƛ35f≛kF½•∨,
</script>
<script>
args=[]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
SAKO, 176 bytes
CALKOWITE:I
*1)T=MOD(I,5)
GDYMOD(I,3)=0:3,INACZEJ4
3)TEKST
Fizz
GDYT=0:5,INACZEJ7
4)GDYT=0:5,INACZEJ6
5)TEKST
Buzz
SKOCZDO7
6)DRUKUJ(0):I
7)LINIA
POWTORZ:I=1(1)100
STOP1
KONIEC
I believe it's possible to shorten it more, but I don't see a way to do it.
Tcl, 72 bytes
time {puts [expr [incr i]%3?$i%5?$i:"":"Fizz"][expr $i%5?"":"Buzz"]} 100
I think it is more golfable, to avoid the repetition of i%5
Jalapeño, 32 bytes
1‥e₂↦{₄%{₂3,5↭ₓ{¬*}{₂↻′)^FₓXZa‚β₋"wJ|I₀L₋
Explained
1‥e₂↦{₄%{₂3,5↭ₓ{¬*}{₂↻′)^FₓXZa‚β₋"wJ|I₀L₋
1‥e₂ # range of 1 to 100
↦{₄ # mapped via the next 4 links
%{₂3,5 # the value modulo both 3 and 5
↭ₓ # Zipping by
{¬*} # Logical not of left, repeating right
{₂↻′)^FₓXZa‚β₋"w # The literal string "Fizz Buzz" split by spaces
J # Joined, giving either ""|"Fizz"|"Buzz"|"FizzBuzz"
|I₀ # Logical or with the input number
L₋ # Joined by newlines
Hex-Dump of Bytecode
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: 31 2e 3b d0 c8 54 c6 33 29 35 cc c4 58 52 c5 c6
0010: ff 71 07 55 04 7f 89 27 a6 48 20 18 14 57 90 17
☾, 34 33 chars (64 bytes)
100ᐖ3∣⟞⭢⋅"Fizz"+"Buzz"⋅⭠5∣⟞→∨⟞→☾
Try it: ☾ web interpreter
For each in [1..100], repeat Fizz by whether 3 divides it, append Buzz repeated by whether 5 divides it, take the logical OR with the number, and print it.
Hatchback, 256 bytes
0 1 3 0 2 5 0 4 1 0 5 100 0 9 70 0 10 105 0 8 122 0 12 66 0 13 117 0 14 10 2 0 4 10 7 0 15 7 1 6 7 65281 50 0 3 1 13 9 13 10 13 8 13 8 10 7 0 15 7 2 6 7 65281 71 13 12 13 13 13 8 13 8 0 65281 78 6 3 65281 77 12 0 13 14 10 6 0 9 6 5 0 3 0 6 6 65281 26 65535
this is super not optimized. I could probably make it better but this language is like super hard to understand
ungolfed and explained: (not valid code)
| 0x0 is the incrementer
| for clarification, the address 0xFF01 is used to increment
| through instructions in the interpreter. when setting that
| address, you have to set the number back by ~4 (depending on
| what command you use) because of the interpreter skipping
| a certain amount of times so it doesn't accidentally run
| arguments like a command
0 1 3 | set 0x1 to 3 (mod 3)
0 2 5 | set 0x2 to 5 (mod 5)
0 4 1 | set 0x4 to 1 (increment)
0 5 100 | set 0x5 to 100 (max)
0 9 70 | set 0x9 to 70 (letter F)
0 10 105 | set 0xA to 105 (letter i)
0 8 122 | set 0x8 to 122 (letter z)
0 12 66 | set 0xC to 66 (letter B)
0 13 117 | set 0xD to 117 (letter u)
0 14 10 | set 0xE to 10 (newline)
| start of loop...
2 0 4 | increment 0x0
10 7 0 | copy 0x0 to 0x7
15 7 1 | modulo 0x7 by 3
6 7 65281 50 | if 0x7 != 0, set 0xFF01 to 50 (jump to instruction). else...
0 3 1 | set 0x3 to 1 (so it knows not to print the number)
13 9 | inline print F
13 10 | ...i
13 8 | ...z
13 8 | ...z
10 7 0 | copy 0x0 to 0x7 again
15 7 2 | modulo 0x7 by 5
6 7 65281 71 | if 0x7 != 0, set 0xFF01 to 71. else...
13 12 | inline print B
13 13 | ...u
13 8 | ...z
13 8 | ...z
0 65281 78 | set 0xFF01 to 78 to skip printing the number
6 3 65281 77 | if 0x3 == 1, set 0xFF01 to 77. else...
12 0 | inline print 0x0
13 14 | print newline
10 6 0 | copy 0x0 to 0x6
9 6 5 | set 0x6 to the boolean result of (0x6 < 100) aka (0x6 < 0x5)
0 3 0 | set 0x3 to 0
6 6 65281 26 | if 0x6 != 0, then jump to the start of the loop.
65535 | end of program
CASIO BASIC (CASIO fx-9750GIII), 52* 80 bytes
*invalid answer
For 1→N To ᴇ2
N Rmdr 3→C
N Rmdr 5
If Not (C+Ans
Then "FIZZBUZZ"
Else Not C⟹"FIZZ"
Not Ans⟹"BUZZ"
CAns⟹N◢
IfEnd
Next
now valid! heres the output for numbers up to 22:
1
2
FIZZ
4
BUZZ
FIZZ
7
8
FIZZ
BUZZ
11
FIZZ
13
14
FIZZBUZZ
16
17
FIZZ
19
BUZZ
FIZZ
22
- Disp -
Bespoke, 561 bytes
list a hundred numbers;it must be done well
but remember:things seldomly r so easy
numbers do not go forward ordinarily;theres no one,two,a subsequent three
rather,go one,two(t-hr-ee?no)Fizz
indeed,it recurs if numbers get to divide with three
everyone thinks"probably I go FOUR despite it,yes?it should become easier"oh yes
but u r ongoing
nextly,we say fou-r(fi-ve?no)Buzz
indeed,it recurs if numbers are dividing five
remember a feature:if we ever factor a fifteen out,you do a connection,saying as FizzBuzz
meaning,do both
are you a mastermind?i presumed so
I included a FizzBuzz program as an example program with my official interpreter for Bespoke, but I wrote that one in a more extensible and readable way.
In this one, instead of using a heap value to store whether or not any of Fizz or Buzz were outputted, I directly add n mod 3 to n mod 5. Otherwise, it works largely the same in the broad strokes.
Acc!!, 135 bytes
Count i while 900-i {
i/9%3/2*47620372+i/9%5/4*47621400*86^4
(_+0^_*(i/90+i%90/9*86+86)+86^8*85)/86^(i%9)%86
Write (_+48)%123)*0^0^(_
}
This started as a golf to DLosc's answer, but got a lot shorter from there.
The main optimisation this uses is, instead of manually writing the logic to conditionally print Fizz, Buzz and numbers, we build up an output buffer for each line and then print each character.
The buffer needs to fit 9 characters - potentially containing FizzBuzz\n - and needs to be able to contain the characters 123456789BFiuz\n. In particular, we never need to print 0, and indeed don't want to where it occurs as a first digit - we want 1, 2, Fizz, 4 not 01, 02, Fizz, 04. This means we can use 0 as a null character, and print buffer values with 48 - the codepoint of 0 - added to their charcodes. This also means that digits in the buffer will just be printed as themselves.
We do also need to print \n, which has a charcode of 10, and the way I've dealt with this is by storing it as 85 and moduloing the printed character by 123 (since z has a codepoint of 122), which results in (85 + 48) % 123) = 10. The buffer is stored in base 86, and built up like so:
0 0 0 0 0 0 0 0 Initial buffer
F i z z Added if multiple of 3
B u z z Added if multiple of 5
5 6 Added if buffer is still zero
\n Added after ^, due to zero checks
The hardcoded numbers 47620372 and 47621400 correspond to Fizz and Buzz respectively.
The other optimisation this uses is, rather than iterating 100 times to build each buffer and iterate over all 9 chars, we can iterate 900 times and divmod by 90 to get a line number and a buffer index. Count i while 900-i { iterates i from 0 to 899, and then:
i/9is the line number from0to99, andi/9%3/2is 1 iffi%3 == 2i.e. the line number is divisible by 3, so we put aFizzin the buffer if that's the case. A similar thing happens forBuzz, and the buffer is then stored in the accumulator_.0^_is 1 if the buffer is 0, i.e. if the buffer contains neitherFizznorBuzz. If this is nonzero, we add the digits to the buffer. However,i/9ranges from0to99and we want to print1to100. While we could just use(i/9+1), we can take advantage of the fact that we never have to print a multiple of 10 for a shorter way.Instead of incrementing
14into15and then manipulating its digits, we can take1 4and add1to the last digit to get1 5. If done on e.g.19, this will produce1 10instead of2 0, but as this would result in a Buzz anyway it doesn't matter, and it saves a few bytes.We then add this to the buffer, along with a
86^8*85representing a newline, and divide the buffer by the appropriate power of 86 to get the corresponding character, which is stored in the accumulator_again.Finally, we print the character, by adding to 48 and printing if it's nonzero exploiting an Acc!! bug -
Write (_+48)%123)*0^0^(_is transpiled toprint(end=chr((_+48)%123)*0^0^(_)), and*in Python is string multiplication, so this will print the char only if it's nonzero.
ibe, 197 bytes
adadadadakqafQmwafWmQafEmQsjWmrsjEmyafRmWafRmEshRmqmwsliqslwqyslweeslweesluuslwwislweeslweeslwqaltakwshWmqmesliqslwqyslweeslweeslwqaltakeshEmqmrsluuslwwislweeslweeslwqaltakrasQaktskWskEskRssQmwqqmq
code explained: (since ibe doesn't support comments, this code is not valid)
adadadad | initialize 4 items in tape: Q, W, E, and R. they all start out as 0
| Q is the initial counter
| W is Q % 3
| E is Q % 5
| R is W + E
akq | start of loop (point 0 aka 'q')
afQmw | increase Q by 1
afWmQ | add Q to W
afEmQ | add Q to E
sjWmr | modulo W by 3
sjEmy | modulo E by 5
afRmW | add W to R
afRmE | add E to R
shRmqmw | if R is not equal to 0, goto point 1 (aka 'w'). else...
sliq | write F
slwqy | ..i
slwee | ..z
slwee | ..z
sluu | ..B
slwwi | ..u
slwee | ..z
slwee | ..z
slwq | ..newline
alt | goto point 4 (aka 't')
akw | point 1 (aka 'w')
shWmqme | if W is not equal to 0, goto point 2 (aka 'e'). else...
sliq | write F
slwqy | ..i
slwee | ..z
slwee | ..z
slwq | ..newline
alt | goto point 4 (aka 't')
ake | point 2 (aka 'e')
shEmqmr | if E is not equal to 0, goto point 3 (aka 'r'). else...
sluu | write B
slwwi | ..u
slwee | ..z
slwee | ..z
slwq | ..newline
alt | goto point 4 (aka 't')
akr | point 3 (aka 'r')
asQ | print Q, since nothing isn't true if it can reach this
akt | point 4 (aka 't')
skW | set W to 0
skE | set E to 0
skR | set R to 0
ssQmwqqmq | if Q < 100, goto point 0 (aka 'q')
AWK, 56 bytes
{for(;i++<$1;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}
To test:
awk '{for(;i++<$1;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}' <<< 100
BrainChild, 97 bytes
include*;var p=print;while(int i++<100){if!(i%3)p("Fizz")if!(i%5)p("Buzz")if i%3&&i%5p(i)p("\n")}
Readable
include io.bc;
int i = 0;
while(i<100){
i++;
if (!(i%3))
print("Fizz")
if (!(i%5))
print("Buzz")
if (i%3 && i%5)
print(i)
print("\n")
}
Iogii, 29 bytes
"Fizz","Buzz"@r3,5%0q*u100}@O
Little peculiar that the last value next to the register sets all the other values. You can try it online by putting it in the program box here: https://golfscript.com/iogii/online_interpreter.html
Explained
I haven't quite figured out how to structure Iogii explanations yet, so some lines are somewhat oversimplified. If it helps, this is my standard approach of "multiply ["Fizz", "Buzz"] by [n % 3 == 0, n % 5 == 0], join into string, and logical or.
"Fizz","Buzz"@r3,5%0q*u100}@O
100}@ # For each number in the range [1, 100]:
@r3,5% # Push [number % 3, number % 5]
0q # Do those equal 0?
"Fizz","Buzz" * # Correspond those to the list ["Fizz", "Buzz"] via replication.
u # Join into a single string (either "Fizz", "Buzz", "FizzBuzz", or "")
@O # Logical or each with the original number from the range
💎
Created with the help of Luminespire.
TinyAPL, 41 32 bytes*
{⎕←⍵↾"FizzBuzz"⌿⍨4⌿0=3‿5|⍵}¨⍳100
Try it: TinyAPL REPL
Now using ¨ Each rather than ◡ On Cells to avoid throwing an error, as suggested by RubenVerg.
This uses a similar technique to my Uiua and J answers. The main idea is that in each iteration, check divisibility against 3 and 5, replicate four of each boolean (giving a length 8 vector), and use that as a filter on "FizzBuzz". Then, print this string unless it's empty, in which case you print the number. In TinyAPL, deciding which value to place is super short, coming in at a grand total of 1 character: ↾ Maximal.
Previously I had been using a much more convoluted method of deciding which to print, but now that I've found Maximal, this now seems to be the shortest FizzBuzz program in any APL!
*Encoded with 1 byte per character using (⎕Import"std:sbcs")→Encode.
TinyAPL, 64 bytes (SBCS)
⊃⍪¨⍆((⊃¨⍪¨⍆¨(4×0=3‿5|ᑈx)↑¨ᐵ"Fizz"‿"Buzz")↾¨'0'+10⊤ᑈx←⍳100)⍪ᐵ"⍘n"
After messing around with this last night, I cleaned it up a bit and decided to post it. It's still awful but it works.
x← Assign x to
⍳100 A range from 1 to 100
10⊤ᑈ Convert each to base 10
'0'+ Add the character '0' to each, casting to a string of digits
ᑈx To each element of x
| Take the remainder when dividing by
3‿5 Each of [3, 5]
4×0= Check if these are 0 (i.e. divisible by 3/5) and multiply by 4, giving 4 for divisible, 0 for not
( ) ¨ᐵ Over each of those pairs
↑ Take the first n characters of
"Fizz"‿"Buzz" Each of "Fizz" and "Buzz"
⊃¨⍪¨⍆¨ And concatenate each into a string
( )↾¨ Take the pairwise maximum with the stringified ints from before
( )⍪ᐵ"⍘n" Append a newline to each
⊃⍪¨⍆ And concatenate the whole thing
Scratch, 157 156 142 bytes
define(n)(o
replace item((b)-((b)mod(n)))of[q v]with(o
when gf clicked
repeat(100
change[b v]by(1
add(b)to[q v
(3)[Fizz
(5)[Buzz
(15)[FizzBuzz
Note: This requires b to have the value 0 before starting (which is the default value that all variables are initialized to upon creation in Scratch), and it requires the list q to be blank and displayed (which are the default conditions when creating a list).
Perl 5, 109 93 bytes
for$i(1..100){if($i%3<1){say"Fizz"};if($i%5<1){say"Buzz"};if($i%3>0&&$i%5>0){say$i};say"\n";}
There might be some more golfing potential here.
Takes advantage the fact that 0 is the only way x % y can be less than 1 (thanks to Alex. A for shaving off 4 bytes with this) and Perl 6's say keyword.
Boo, 114 bytes
for i in range(1,101):
if i%15==0:print'FizzBuzz'
elif i%5==0:print'Buzz'
elif i%3==0:print'Fizz'
else:print i
Fortran (GFortran), 145 138 134 128 125 bytes
character*8s;do5 i=1,100;s=''
if(mod(i,3)<1)s='fizz'
if(mod(i,5)<1)s=trim(s)//'buzz'
if(s=='')write(s,'(i0)')i
5 print*,s
end
On line 4 we write the current value of i into the string s. This greatly simplifies the subsequent print statement.
128b
134b
138b
145b
Jellyfish, 124 105 98 97 92 87 64 50 bytes
P
LM`jr'e
1 B<1
^"FizzBuzz
$ -*b373907863
'dEE4
Try it online!
Try the 64B version online!
Try the 87B version online!
Try the 92B version online!
Try the 97B version online!
Try the 98B version online!
Try the 105B version online!
Try the 124B version online!
explanation
TBD
tinylisp 2, 80 bytes
(quiet(m(\(N)(w(?(% N 3)(?(% N 5)N"Buzz")(?(% N 5)"Fizz""FizzBuzz"))nl))(1to 100
Ungolfed/explanation
We map a lambda function over the numbers from 1 to 100. For each number N:
- Is it nonzero mod 3?
- Is it nonzero mod 5? Then return N
- Else, return "Buzz"
- Else:
- Is it nonzero mod 5? Then return "Fizz"
- Else, return "FizzBuzz"
We then write this value, followed by a newline. Since write returns nil, the result of the map is a list of 100 copies of nil. We prevent the interpreter from outputting this list by passing it to quiet.
(quiet
(map
(lambda (N)
(write
(if (% N 3)
(if (% N 5)
N
"Buzz")
(if (% N 5)
"Fizz"
"FizzBuzz"))
nl))
(1to 100)))
Rockstar, 138 135 133 bytes
F takes I&S
let M be N/I
turn up M
if N-I*M
S's ""
give S
N's 0
while N-100
build N up
say F taking 3,"Fizz"+F taking 5,"Buzz" or N
Try it here (Code will need to be pasted in)
F takes I&S :Function F, taking an integer I & string S as arguments
let M be N/I : Assign N/I to variable M
turn up M : Round M up
if not N-I*M : If N is less than I*M
S's "" : Assign the (falsey) empty string to S
: End if
give S : Return S
:End function
N's 0 :Initialise N as 0
while N-100 :While N is less than 100
build N up : Increment N
say :Output
F taking 3,"Fizz" : The return value of a call to F with arguments 3 & "Fizz"
+ : Append
F taking 5,"Buzz" : The return value of a call to F with arguments 5 & "Buzz"
or N : Logical OR with N
tinylisp, 130 bytes
(d f(q((n # %)(i(e n 100)(q Buzz)(i(disp(i #(i % n(q Buzz))(i %(q Fizz)(q FizzBuzz))))0(f(a n 1)(i #(s # 1)2)(i %(s % 1)4
(f 1 2 4
Explanation
It took me a while to realize I could do FizzBuzz in tinylisp, since the language doesn't have strings. However, it does have the Name type, which can be any run of non-whitespace, non-parenthesis characters; and it also has the disp command, which outputs a value followed by a newline. Together with some creative abuse of recursion, we can get the desired output.
We define a function f with three arguments:
nis the counter. We will start at1and recurse until100.#is the number of iterations till the next divisible-by-3 number. (Mnemonic: Shift-3)%is the number of iterations till the next divisible-by-5 number. (Mnemonic: Shift-5)
The first thing f does is check whether n is 100. If so, we return Buzz. This value gets passed all the way up the call stack and printed at the end.
If not, we need to use disp to print either the number, Fizz, Buzz, or FizzBuzz, depending on the values of # and %:
- If
#and%are both nonzero (truthy), the number is not divisible by 3 or 5. Display the number,n. - If
#is nonzero but%is zero, the number is divisible by 5 but not 3. DisplayBuzz. - If
#is zero but%is nonzero, the number is divisible by 3 but not 5. DisplayFizz. - If
#and%are both zero, the number is divisible by 3 and 5. DisplayFizzBuzz.
Since tinylisp does not have an equivalent to Common Lisp's progn, disp'ing something and then returning a value requires a little trickery. Since disp always returns (), which is falsey, we can use the disp call as the condition of an if (i). The true branch will never be evaluated (0 is a convenient placeholder), and we can put the actual return value in the false branch.
This return value is a recursive call. We add 1 to n, and we subtract 1 from # and % unless they are zero, in which case we reset them to (3-1) or (5-1), respectively.
Ungolfed, using the standard library for long names of builtins (TIO):
(load library)
(def fizz-buzz
(lambda (counter steps-till-fizz steps-till-buzz)
(if (equal? counter 100)
(q Buzz)
(if
(disp
(if steps-till-fizz
(if steps-till-buzz counter (q Buzz))
(if steps-till-buzz (q Fizz) (q FizzBuzz))))
(comment Return val of disp is always falsey, so the true branch is never executed)
(fizz-buzz
(add2 counter 1)
(if steps-till-fizz (sub2 steps-till-fizz 1) 2)
(if steps-till-buzz (sub2 steps-till-buzz 1) 4))))))
(fizz-buzz 1 2 4)
J, 47 bytes
echo(0{[:\:~":,:'FizzBuzz'#~4#0=3 5&|)"0>:i.100
or, if you assume implicit echo like in Jconsole, as the other leading J solution here does, then you can remove the echo from the start for 43 bytes.
There seem to be shorter solutions on code.golf but solutions are private there so I don't know what they are… For now this can be the shortest we have on CGCC.
NB. this runs for each 1 to 100, consider the 80th line.
(0=3 5&|) 80
0 1
(4#0=3 5&|) 80
0 0 0 0 1 1 1 1
('FizzBuzz'#~4#0=3 5&|) 80
Buzz
(":,:'FizzBuzz'#~4#0=3 5&|) 80
80
Buzz
([:\:~":,:'FizzBuzz'#~4#0=3 5&|) 80
NB. sort reverse-lexicographically; n only wins if s is empty
Buzz
80
(0{[:\:~":,:'FizzBuzz'#~4#0=3 5&|) 80
Buzz
J, 46 bytes
New Version, thanks to Bolce Bussiere:
(,&((;,>)Fizz`Buzz)@":{~+.&3-~0:<5&|)"0>:i.100
Old version (52 bytes):
(,&('Fizz'(,>@;;)'Buzz')@":{~+.&3-~0:~:5&|)"0>:i.100
Explanation
Best explained by breaking it up into smaller verbs. Overall the main working portion is a train:
getlist {~ getindex
where getlist i returns a 4-length list of the default format of i, 'FizzBuzz', 'Fizz', and 'Buzz'; and getindex i returns -1 if i is divisible by 5 only, -2 if divisible by 3 only, 1 if divisible by both, and 0 otherwise. The verb {~ grabs the right argumentth element from its left argument, the list created by getlist, where the index is modulo'd by the length of the list, meaning -1 will grab the last element, -2 the second-to-last, etc.
In
getlist=:,&('Fizz'(,>@;;)'Buzz')@":
": gets the default format of i, and then ,&('Fizz'(,>@;;)'Buzz') appends it to the beginning of the list created using the train ,>@;; on the two arguments 'Fizz' and 'Buzz' (append them and raze them, then raze those results together and unbox each item), in the new version ((;,>)Fizz`Buzz) does essentially the same thing but takes advantage of the ` that boxes, then appends the two strings before applying the train ;,> on the resulting list of boxes (unbox each element; raze the elements together to get FizzBuzz; append the unboxed elements with FizzBuzz)
In
getindex=:+.&3-~0:~:5&|
+.&3 gets the GCD of i and 3, and 5&| returns i modulo 5. The train 0:~:5&| returns 1 if 5&| is unequal (~:, or in the new version < because the result of 5&| will always be greater than or equal to 0) to the result of the constant function 0: (which returns 0 for any argument) and 0 otherwise, then getindex is a train that, from this value, subtracts +.&3 resulting in the return values given above.
The boring parts are the "0 which simply tells the verb to operate on atoms of any argument given to it, and >:i.100, which returns a list of integers from 1 to 100 (inclusive).
gnuplot, 72 68 bytes
- -4 bytes thanks to noodle person
se pr'-'
do for[i=1:100]{pr i%15?i%5?i%3?i:"Fizz":"Buzz":"FizzBuzz"}
Not sure whether the statement se pr'-' (set output to the console) would be allowed to be moved to the header, so, let's keep it in the body.
Go, 162 158 145 143 142 139 bytes
package main
import."fmt"
func main(){for i,p:=1,Println;i<101;i++{s:=""
if i%3<1{s+="Fizz"}
if i%5<1{s+="Buzz"}
if s!=""{p(s)}else{p(i)}}}
Acc!!, 260 245 237 bytes
-15 bytes and another -8 bytes thanks to Mukundan314
Count i while 100-i {
i+1
Count f while i%3/2-f {
Write 70
Write 105
Write 122
Write 122
0
}
Count b while i%5/4-b {
Write 66
Write 117
Write 122
Write 122
0
}
Count d while _ {
Count z while _/10 {
Write 48+_/10
_%10
}
_*10
}
Write 10
}
Explanation
Once you know how Acc!! works, this is mostly pretty straightforward. (Crash course: Count while loops increment their variable from 0 as long as their condition is true. Write takes an ASCII code and outputs the corresponding character. Bare expressions like i+1 are assigned to the accumulator, _. Division is integer division.)
Our code iterates i from 0 through 99; thus, the number in question on each iteration is actually i+1. We set the accumulator to this value at the top of the loop.
If i%3 is 2 (i.e. i+1 is divisible by 3), we want to print Fizz.
- Loop
fwith conditioni%3/2-f; we enter the loop iffi%3/2is nonzero. - Inside the loop, write
Fizzand set the accumulator to 0. - The second time through,
fis 1, makingi%3/2-f0 and breaking out of the loop.
If i%5 is 4 (i.e. i+1 is divisible by 5), we want to print Buzz. Same approach as above.
If we printed Fizz and/or Buzz, the accumulator is now 0; otherwise, it is a positive number that we need to output. The number will have either one or two digits, and its 1's digit will not be 0.
- Loop
dwith condition_: the accumulator is not 0.- Loop
zwith condition_/10: the accumulator has a 10's digit.- Write the 10's digit.
- Set the accumulator to
_%10, discarding the 10's digit.
- Set the accumulator to
_*10, shifting the 1's digit to be the new 10's digit. - After two times through the
dloop, the accumulator becomes 0 and we exit the loop.
- Loop
Finally, write a newline.
TypeScript's type system, 183 bytes
//@ts-ignore
type G<I=[1],M=1,S="",N=I["length"],L=`${M extends 0?"Fizz":""}${`${N}`extends`${any}${0|5}`?"Buzz":""}`>=N extends 101?S:G<[...I,1],[1,2,0][M],`${S}${L extends""?N:L}
`>
Finally sub 200, and by a longshot! I used an almost entirely different method to save 36 bytes.
Instead of having two types, one to check divisibility and one to construct the FizzBuzz output, I reduced it to just a single type.
This new solution checks divisibility by 3 by cycling a type argument M between 1, 2, and 0, and outputting "Fizz" when M extends 0. It checks divisibility by 5 by checking if the decimal representation of the loop counter ends in 0 or 5 (`${N}`extends`${any}${0|5}`).
Below is my older solution, which is itself a newer version of one of my first TypeScript types golfs.
TypeScript’s Type System, 227 219 bytes
//@ts-ignore
type M<N,B,T>=N extends[...B,...infer R]?M<R,B,T>:N extends[]?T:"";type F<N=[1],S="",O=`${M<N,[1,1,1],"Fizz">}${M<N,[1,1,1,1,1],"Buzz">}`,Z=N["length"]>=Z extends 101?S:F<[...N,1],`${S}${O extends""?Z:O}
`>
I already have an answer in TypeScript types here, but it’s from when I first started using TS, and is bad on multiple fronts:
- It runs with compilation errors
- It uses an external library
- It doesn’t use tail-recursion, so it hits the recursion depth very fast and therefore requires lots of extra code
- It’s long
This submission has none of the same problems, and uses a technique I’ve been sitting on for a while and haven’t had a chance to use until now.
Explanation:
// M does divisibility (unary numbers)
type M<
N, // N is the dividend
B, // B is the divisor
T, // T is returned if N is divisible
>=
// if B fits in N, let R be the difference
N extends[...B,...infer R]
?M<R,B,T> // recurse with N = R
:N extends[] // else if N is 0
?T // return T
:"" // else return ""
// F generates the main FizzBuzz text
type F<
N=[1], // N is the current number (in unary)
S="", // S is the whole string
O= // O is the text for the current iteration
`${ // Fizz if N divisible by 3
M<N,[1,1,1],"Fizz">
}${ // concatenated to Buzz if N divisible by 5
M<N,[1,1,1,1,1],"Buzz">
}`,
Z=N["length"] // Z is an alias for N in decimal
>=
Z extends 101 // if N is 101,
?S // return S
:F< // else recurse with
[...N,1], // N + 1
`${S}${ // append to S:
O extends""?Z:O // Z if O is empty, else O
}\n` // append a newline
>
Easyfuck, 103 92 90 bytes
Æ¡ãÄ©␟[Vîê§VTSx(\ùòîO␗.SÉD§ÏAPC>|¥ãÄSTSHYÞHù␋åoPU2c[HOPD®␊y$|NELóçÉ␞c[HOPD§Ü␔ò|úÛÇHTJÝÝCCHñsÄSTMWÞ»␂4-=}d␂␄␘\¢PAD
due to lack of unicode representations for c1 control characters, they have been replaced by their superscripted abbreviations
Decompressed:
c(<<%$>[+;]*<)p(.>>.r<..)r(J>>>>>)<<$r[^$>!>+>$c-`(Jp)r$>!>>>$<c-`(J>p)r>>[<<';]J<.<$r+^]@FBiuzd␁␁␃␅e␊
Explanation part 1:
c(<<%$>[+;]*<)p(.>>.r<..)r(J>>>>>)<<$r
c( ) define function c
<< go to the cell 2 steps to the left
%$> modulo the cell by the value in storage, copy it to storage, move 1 cell to the right
[ ] while loop
+; *< increment the cell, break out of the while, multiply it by the value in storage, and move 1 cell to the left
p( ) define function p
.>>.r<.. print ascii, move 2 cells to the right, print ascii, invoke function r, move 1 cell to the left, print ascii twice
r( ) define function r
J>>>>> go to the first cell and move 5 cells to the right
<<$r move to the 2nd to last cell, copy it to storage and invoke function r
Explanation part 2:
[^$>!>+>$c-`(Jp)r$>!>>>$<c-`(J>p)r>>[<<';]J<.<$r+^]@FBiuzd␁␁␃␅e␊
[ ] while loop
^ bitwise xor the cell with the storage cell
$>!>+> copy the cell to storage, move 1 cell right, set the cell to value in storage, move 1 cell right, increment, move 1 cell right
$c- copy the cell to storage, invoke function c, decrement
`(Jp) if previous command caused an overflow, execute a lambda which moves the pointer to the first cell and invokes function p
r$>!>>> invoke function r, copy the cell to storage, move 1 cell to the right, set the cell to value in storage, then move 3 cells right
$<c- copy the cell to storage, move 1 cell left, invoke function c, decrement
`(J>p) if previous command caused an overflow, execute a lambda which moves the pointer to the second cell and invokes function p
r>> invoke function r and move 2 cells to the right
[ ] while loop
<<'; move 2 cells left, print integer in the cell at the pointer, break out of the while
J<.<$ move to the last cell, print ascii, move 1 cell left, copy it to storage
r+^ invoke function r, increment the cell at the pointer and xor it with storage cell
@ terminate program
FBiuzd␁␁␃␅e␊ initializer data
Fortran, 187 bytes
do i=1,100
if(mod(i,3)==0.and.mod(i,5)==0)then;print'(a)','fizzbuzz'
elseif(mod(i,3)==0)then;print'(a)','fizz'
elseif(mod(i,5)==0)then;print'(a)','buzz'
else;print'(i0)',i
endif;enddo;end
Janet, 106 bytes
Note: Janet is not in TIO so I couldn't put a link or anything.
(loop[i :range[1 101]:let[f(zero?(% i 3))b(zero?(% i 5))]](print(cond(and f b)"FizzBuzz"f"Fizz"b"Buzz"i)))
Uiua, 48 bytes
∵(&p□/⊂∵!♭▽∶⊂{"Fizz""Buzz"}∶⊂∶¬/↥.=0◿3_5.)+1⇡100
What if APL but stack? That's the core question of Uiua and given that the shortest APL fizzbuzz is 7 bytes shorter, I clearly aren't stacking efficiently.
Explained
∵(&p□/⊂∵!♭▽∶⊂{"Fizz""Buzz"}∶⊂∶¬/↥.=0◿3_5.)+1⇡100
+1⇡100 # The range [1, 100]
∵( ) # To each number n in that range
=0◿3_5 # Push whether the number is divisible by 3 and 5
⊂∶¬/↥. # Append to that list the maximum. This serves as a check as to whether the number should be printed, or a fizzbuzz string.
⊂{"Fizz""Buzz"}∶ # The list ["Fizz", "Buzz"] with n appended. These are all constants (i.e. functions that return the value) for array model reasons.
▽∶ # Use the modulo mask from earlier to select values from ^
/⊂∵!♭ # Flatten, deconstantify each, and join into a single 1d array
□ # Wrap back in a constant for array model reasons
&p # And print the result on STDOUT
💎
Created with the help of Luminespire.
sclin, 63 bytes
100I-a \; tap
"Fizz""Buzz", over3 5, % ! ** c>< dup \pop |# n>o
My collection grows once again
Aubergine, 225 bytes ( 222 bytes with error )
:Ba=aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA=a1-ii? \0B*Fizz\0\0FBuzz\0[-aa=aA-aA+ai-ai=bi-bi+iA=ab-a1=oA=oB=bi-bi+B1+b1=oB+b1-aa:aB+ii=a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab-ib-a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1-iAo01
* four \0 mean NUL(ASCII 0) character
The equivalent pseudo code in C is like below;
#include <stdio.h>
#include <stdint.h>
#define I(x) ((intptr_t)&&x)
#define P(x) *(void*)(x)
static void nop(void) {}
int main(void) {
intptr_t
*cp,*cpt,t,p,
pvars0[] =
{ I(Tj3)-I(Tj1), I(Tj2)-I(Tj1), I(Tj2)-I(Tj1), 0, I(Tc1)-I(Tj3),
I(Lb), 3, 'F', 'i', 'z', 'z', 0, I(Lb)-I(Tx2), },
pvars1[] =
{ I(Lj), 5, 'B', 'u', 'z', 'z', 0, I(Lc)-I(Tx2), },
dvars[] = { I(Tc2)-I(Tj3), '0', '1', '\n', 10, },
*pbase[] = { &pvars0[6], &pvars1[1] },
*dbase3=&dvars[2], *dbase1=&dvars[4];
int i=0;
Lx: // Fizz/Buzz print ( i=0 for Fizz, i=1 for Buzz )
// decrement counter
cp = pbase[i];
*cp-=1;
if ( *cp!=0 ) goto P(*(cp-1)); // skip printing and jump to Lb/Jj
*cp+=3; // restore the counter to 3 ( add more 2 for Buzz in Lc )
cp+=1;
p=I(Tx1);
Tx1: // putchar loop
putchar(*cp);
cp+=1;
if ( *cp!=0 ) goto P(p); // jump to Tx1
goto P(I(Tx2)+*(cp+1)); // jump to Lb/Lc
Tx2:
Lb: // Buzz print
i=1;
goto Lx;
Lj: // number print and post process
cp=pbase[0];
// select &pvars[0] thru &pvars[2] as jump offset
cp-=*cp;
cp-=3;
cpt=dbase3;
goto P( I(Tj1)+*cp ); // jump to Tj3(when Fizz) or Tj1/Tj2
Tj1: // print the upper digit
cp=cpt-1;
putchar(*cp);
Tj2: // print the lower digit
putchar(*cpt);
Tj3: // print a new line and increment the lower digit
cp=dbase3;
*cp+=1;
cp+=1;
putchar(*cp);
cp+=1;
i=0;
if ( *cp!=0 ) goto Lx; // next iteration
return 0; // exit
Lc: // after Buzz
// add more 2 to the Buzz counter
cp=pbase[1];
*cp+=2;
// switch pvars0[3] ( jump offset ) between 0 and pvars0[4]
cp=pbase[0]-2;
t=*cp;
cp-=1;
t-=*cp;
*cp=t;
goto P( I(Tc1)-t ); // jump to Tc1/Tj3
Tc1: // carry up
// reset jump offsets in pvars[1],pvars[2]
// so that the 1st "goto" in Lj jump to Tj1 instead of Tj2
cp-=1;
*cp=0;
cp-=1;
*cp=0;
// decrement global loop counter
cp=dbase1;
*cp-=1;
// decrease the lower digit by 10
cp-=1;
t=*cp;
cp-=1;
*cp-=t;
// increment the upper digit
cp-=1;
*cp+=1;
cp-=1;
goto P(I(Tc2)-*cp); // jump to Tj3
Tc2:
nop(); // not reached
}
Each code block handles;
- Label Lx
Print Fizz ( when i=0 ) or Buzz ( when i=1 ) ifnis the multiple of 3 or 5. - Label Lb
Just jump to Lx after setting i=1. - Label Lj
Printnitself ( when Fizz or Buzz are not printed ) and do post-process. - Label Lc
Carry-up operation.
In Aubergine code, each address range corresponds to;
- 0 thru 2
The 1st instruction:Bahas no effect, but storespbase[].
pbase[0]isord(':')=58,pbase[1]isord('B')=66. - 3 thru 50
The code block with label Lx.
Lx:=aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA, Tx1:=a1-ii
* set i=0 (-ii) to implementgoto Lx - 51
A blank area. - 52 thru 72
Storespvars0[]andpvars1[] - 73 thru 135
The code block with Label Lj.
Lj:-aa=aA-aA+ai-ai=bi-bi+iA, Tj1:=ab-a1=oA, Tj2:=oB, TJ3:=bi-bi+B1+b1=oB+b1-aa:aB+ii
The last instruction+iijumps to an address out of range to stop the program. - 136 thru 219
The code block with Label Lc.
Lc:=a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab-ib, Tc1:-a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1-iA - 220 thru 224
Storesdvars[]
This area is accessed via minus addresses such as dbase1=-1 or dbase3=-3.
The 222 bytes version, which is shown below, outputs some error.
:Ba=aA-A1=ba-b1:BA-Ai+Ai+a1=bi=oA+a1:bA+a1+iA=a1-ii? \0Q*Fizz\0\0\x9aBuzz\0=a1=aA+A1+A1-aa=aA-a1-a1=bA-a1-bA=Ab+ib-a1-AA-a1-AA-aa-a1-A1-a1=bA-a1-Ab-a1+A1-a1+iA-aa=aA-aA+ai-ai=bi-bi+iA=ab-a1=oA=oB=bi-bi+B1+b1=oB+b1-aa:aB$01
* \0 is NUL, and \x9a is a byte 232
This code cannot be run on TIO because TIO requires codes to be UTF-8 clean. ( a single \x9a is not valid as UTF-8 byte sequence )
The differences between 225B version and this 222B version are;
- Exchange the position in code of the Lj code block and the Lc code block.
- Replace relative backward jump instructions
-ib,-iAin Lc code block to forward jumps+ib,+iA. - Omit the instruction
+ii, which works to stop the code, from Lj code block.
* The code stops in error when the instruction pointer points thedvarsarea just after the Lj code block.
HTML & CSS, 502 485 bytes
body{counter-reset:n}
p::after{counter-increment:n;content:counter(n)}
p:nth-child(3n)::before{content:"Fizz"}
p:nth-child(3n)::after{content:""}
p:nth-child(5n)::after{content:"Buzz"}
<p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>
Minecraft Function, 666 bytes
scoreboard objectives add c dummy
scoreboard players add c c 1
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
execute if score c c matches ..99 run function a:b
Must be run as a function named a in a data pack named b. I think this is about optimal for a scoreboard based solution.
Commented version:
# Create scoreboard to store variables
scoreboard objectives add c dummy
# Increment counter by 1 (starts at 0)
scoreboard players add c c 1
# Set constants 0, 3, and 5 for comparison and modulo
scoreboard players set 0 c 0
scoreboard players set 3 c 3
scoreboard players set 5 c 5
# Copy value of counter to f and b and modulo them by 3 and 5 respectively.
scoreboard players operation f c = c c
scoreboard players operation b c = c c
scoreboard players operation f c %= 3 c
scoreboard players operation b c %= 5 c
# If f and b are both > 0, print the counter
execute if score f c > 0 c if score b c > 0 c run tellraw @a {"score":{"name":"c","objective":"c"}}
# If f = 0 and b > 0, print Fizz
execute if score f c = 0 c if score b c > 0 c run tellraw @a "Fizz"
# If f > 0 and b > 0, print Buzz
execute if score f c > 0 c if score b c = 0 c run tellraw @a "Buzz"
# If both are 0 print FizzBuzz (Minecraft doesn't support string concatenation so this is necessary)
execute if score f c = 0 c if score b c = 0 c run tellraw @a "FizzBuzz"
# Run the function again if the counter is <= 99
execute if score c c matches ..99 run function a:b
Common Lisp, 123 116
(dotimes(i 100)(loop for(m s)in'((3"Fizz")(5"Buzz"))if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ(1+ i))))
Pretty-printed
(dotimes (i 100)
(loop for (m s) in '((3 "Fizz") (5 "Buzz"))
if (= (mod (1+ i) m) 0)
do (princ s))
(do () ((fresh-line)) (princ (1+ i))))
The do/fresh-line trick
The inner loop iterates over ((3 "Fizz") (5 "Buzz")) for each i and, according to the result of the two consecutive mod operations, eventually prints:
- nothing
- or
Fizz - or
Buzz - or
FizzBuzz
fresh-line is a nice little function that as far as I know is only found in Common Lisp. It adds a newline only if necessary, and returns T only when the newline was added. For the above situations, according to whether we printed something or not, the return values of (fresh-line) are thus respectively:
NILTTT
So I know that the integer must be printed only when we did not print a fresh-line. But if I print the integer, I must also print a newline after it. That's why there is a DO.
DO is a basic yet looping construct that iterates until a condition is met. Here, the condition is the return value of (fresh-line). It it tested before each iteration of the body of the loop, notably the first one. So if the test returns T, then we exit the DO. Otherwise, we execute the body, which prints the integer. Then, we execute the test once again and this time, it returns T because current line is "dirty" (there is an integer printed now).
SAS 4GL, 84 (or 81 or 72 or 63) 100 (or 89? ) 110 bytes (or 104? or 88?) 133 bytes (or 120? or 111?) 142 bytes (or 129? or 120?) (out of game 82)
- The code (short)
data;do n=1to 1e2;x=scan('Fizz FizzBuzz Buzz'!!n,mod(gcd(n,15),11)-2);put x;end;run;
- The "human readable" code
data;
do n = 1 to 1e2;
x = scan('Fizz FizzBuzz Buzz'!!n, mod(gcd(n, 15), 11) - 2);
put x;
end;
run;
Explanation (for n=20):
data;
do n = 1 to 20;
g = gcd(n, 15);
m = mod(g, 11) - 2;
y = 'Fizz FizzBuzz Buzz' !! n;
x = scan(y, m);
put n= @10 g= @20 m= @30 y= @70 x=;
end;
run;
Variables:
gfrom greatest common divisor function gets :1,3,5,15,mfrom modulo function gets:-1,1,3,2,ygets:"Fizz FizzBuzz Buzz n"forn,xvalue is scanned fromyon positionm(negativemmeans "scan backward").
SAS Log printout:
n=1 g=1 m=-1 y=Fizz FizzBuzz Buzz 1 x=1
n=2 g=1 m=-1 y=Fizz FizzBuzz Buzz 2 x=2
n=3 g=3 m=1 y=Fizz FizzBuzz Buzz 3 x=Fizz
n=4 g=1 m=-1 y=Fizz FizzBuzz Buzz 4 x=4
n=5 g=5 m=3 y=Fizz FizzBuzz Buzz 5 x=Buzz
n=6 g=3 m=1 y=Fizz FizzBuzz Buzz 6 x=Fizz
n=7 g=1 m=-1 y=Fizz FizzBuzz Buzz 7 x=7
n=8 g=1 m=-1 y=Fizz FizzBuzz Buzz 8 x=8
n=9 g=3 m=1 y=Fizz FizzBuzz Buzz 9 x=Fizz
n=10 g=5 m=3 y=Fizz FizzBuzz Buzz 10 x=Buzz
n=11 g=1 m=-1 y=Fizz FizzBuzz Buzz 11 x=11
n=12 g=3 m=1 y=Fizz FizzBuzz Buzz 12 x=Fizz
n=13 g=1 m=-1 y=Fizz FizzBuzz Buzz 13 x=13
n=14 g=1 m=-1 y=Fizz FizzBuzz Buzz 14 x=14
n=15 g=15 m=2 y=Fizz FizzBuzz Buzz 15 x=FizzBuzz
n=16 g=1 m=-1 y=Fizz FizzBuzz Buzz 16 x=16
n=17 g=1 m=-1 y=Fizz FizzBuzz Buzz 17 x=17
n=18 g=3 m=1 y=Fizz FizzBuzz Buzz 18 x=Fizz
n=19 g=1 m=-1 y=Fizz FizzBuzz Buzz 19 x=19
n=20 g=5 m=3 y=Fizz FizzBuzz Buzz 20 x=Buzz
Remarks:
- if you decide to uses
F,B, andFBfor Fizz, Buzz, and FizzBuzz it can be shortened to:
data;do n=1to 1e2;x=scan('F FB B'!!n,mod(gcd(n,15),11)-2);put x;end;run;
so 72, right? ;-)
- The
data;andrun;are mandatory keywords of every SAS 4GL data step, so if you thinking only about the "working code" (and have in mind the previous remark) you could say 63 bytes, right? ;-) ;-)
Observation
I dare to say that "FizzBuzz" is equivalent with "BuzzFizz", after all if a number is divisible by "3 and 5" it is also divisible by "5 and 3", isn't it?
In such case it can be golfed to 81 bytes:
data;
do n = 1 to 1e2;
t='Fizz Buzz';
x = scan(t!!t!!n, mod(gcd(n, 15), 11) - 2);
put x;
end;
run;
Until I get confirmation I'll keep it unofficial.
The 4th obsolete solution.
- The code (short)
data;do n=1to 1e2;f=^mod(n,3);b=^mod(n,5);put n@(4*^(f+b))"Fizz"+(-4*^f)"Buzz"+(-4*^b)4*" ";end;run;
- The "human readable" code
The Code:
data;
do n=1to 1e2;
f=^mod(n,3);
b=^mod(n,5);
put n@(4*^(f+b))"Fizz"+(-4*^f)"Buzz"+(-4*^b)4*" ";
end;
run;
Process:
- print
nand overprint it with Fizz, Buzz or FizzBuzz if divisibility occurs by shifting text with@()operator.
Remarks:
- if you decide to uses
F,Bfor Fizz and Buzz it can be shortened to:
data;do n=1to 1e2;f=^mod(n,3);b=^mod(n,5);put n@(4*^(f+b))"F"+(-^f)"B"+(-^b)" ";end;run;
so 89, right? ;-) ;-)
"Out-of-game 82"
This example "breaks" the rule because it uses F, B and X instead full words, that is why I only puts it as a interesting case. It is a variation on the cycle string idea. And I like it the most :-)
The code:
data;do n=1 to 100;x=coalescec(char("X F BF BF B",mod(n,15)+1),n);put x;end;run;
Human readable:
data;
do n = 1 to 100;
x = coalescec(char("X F BF BF B", mod(n, 15) + 1), n);
put x;
end;
run;
If you will to create a SAS format:
proc format;
value $ X (default=20)
"F" = "Fizz"
"B" = "Buzz"
"X" = "FizzBuzz"
;
run;
and modify the put statement to:
put x $X.;
you will see "full words" in the log.
The 3rd obsolete solution.
- The code (short)
data;do n=1to 100;x=ifc(mod(n,5)*mod(n,3),n,ifc(^mod(n,5),"Fizz","")!!ifc(^mod(n,3),"Buzz",""));put x;end;run;
- The "human readable" code
The Code:
data;
do n = 1 to 100;
x = /* create variable x and... */
ifc(mod(n,5)*mod(n,3) /* if n not divisible by 3 or 5 */
,n /* assign n to x, else... */
,ifc(^mod(n,5) /* if divisible by 5 add Fizz string to x */
,"Fizz"
,"")
!! /* and concatenate with... */
ifc(^mod(n,3) /* if divisible by 5 add Buzz string */
,"Buzz"
,"")
);
put x ; /* print value from x variable */
end;
run;
Comments:
- It looks like "concatenation" of four
mod(.,.)functions and threeifc()functions do the job even better.
Remarks:
- If the
FizzandBuzzphrases could be "replaced" byFandBthe code would be 6 bytes shorter, that's why I wrote 104 in brackets. :-) - The
data;andrun;are mandatory keywords of every SAS 4GL data step, so if you thinking only about the "working code" (and have in mind the previous remark) you could say 95 bytes, right? ;-) ;-)
The 2nd obsolete solution.
- The code (short)
data;do n=1to 100;select;when(^mod(n,15))put"FizzBuzz";when(^mod(n,5))put"Fizz";when(^mod(n,3))put"Buzz";otherwise put n;end;end;run;
- The "human readable" code
The Code:
data;
do n = 1 to 100;
x = ifc(mod(n,5)*mod(n,3)
,n
,ifc(^mod(n,5)
,"Fizz"
,"")
!!
ifc(^mod(n,3)
,"Buzz"
,"")
);
put x ;
end;
run;
Comments:
It looks like doing 3 times "negated modulo" (
^mod(.,.)) takes less keystrokes than previous "cycle string" approach.Remarks from the previous one stay, but with 120 and 111 accordingly. ;-) ;-)
The 1st obsolete solution.
- The code (short)
data;do n=1to 100;select(char("300102100120100",mod(n,15)+1));when(0)put n;when(1)put"Fizz";when(2)put"Buzz";when(3)put"FizzBuzz";end;end;run;
- The "human readable" code "step by step"
The Code:
data;
do n = 1 to 100;
select( char( "300102100120100", mod(n, 15) + 1) );
when(0) put n;
when(1) put "Fizz";
when(2) put "Buzz";
when(3) put "FizzBuzz";
end;
end;
run;
The process:
- the
do n = 1 to 100;makes the loop from 1 to 100, so if you want to play FizzBuzz for 1000 it is just 1 extra byte cost, "300102100120100"- the "cycle string" - when you realise the divisibility by 3 or 5 is cyclic modulo 15 you will see all "cases" repeating in a loop; you just have to put the last marker (3= divisible by 3 and 5) as the first on the list (since 15 modulo 15 is 0).char( "300102100120100", mod(n, 15) + 1)select "n-th modulo 15, plus 1" character from the "cycle string", do the test inwhen(), and print withput.
Remarks:
- If the
Fizz,Buzz, andFizzBuzzphrases could be "replaced" byF,B, andXthe code would be 13 bytes shorter, that's why I wrote 129 in brackets. :-) - The
data;andrun;are mandatory keywords of every SAS 4GL data step, so if you thinking only about the "working code" (and have in mind the previous remark) you could say 120 bytes, right? ;-) ;-)
Thunno 2 N, 11 bytes
ɦık+Ḋkg×Jn|
Add a trailing £ if you want it flagless.
Thunno 2, 18 17 bytes
ɦı35dḊʋ⁴ȥæÞ½×Jn|£
No questionable constants.
Explanation
ɦık+Ḋkg×Jn| # Full program
ɦ # Push 100
ı # Map over [1..100]:
k+ # Push [3, 5]
Ḋ # Divisible by [3, 5] (vectorises)
kg # Push ["Fizz", "Buzz"]
× # Multiply element-wise
J # Join by nothing
n| # Logical OR with the number
# N flag joins by newlines
# Implicit output
ɦı35dḊʋ⁴ȥæÞ½×Jn|£ # Full program
ɦ # Push 100
ı # Map over [1..100]:
35d # Push [3, 5]
Ḋ # Divisible by [3, 5] (vectorises)
ʋ⁴ȥæÞ # Push compressed string "FizzBuzz"
½ # Split in half to get ["Fizz", "Buzz"]
× # Multiply element-wise
J # Join by nothing
n| # Logical OR with the number
£ # Print the result
Desmos, 244 bytes
a=\left[1...100\right]
b\left(m\right)=\operatorname{mod}\left(a,m\right)
c\left(n\right)=\left\{b\left(n\right)=0:1,0\right\}
\left(a,1\right)Fizzc\left(3\right)
\left(a,0\right)Buzzc\left(5\right)
\left(a,0\right)${a}b\left(3\right)b\left(5\right)
Ungolfed
a=\left[1...100\right]sets a to be [1,2,3,4...100]b\left(m\right)=\operatorname{mod}\left(a,m\right)b(m)=mod(a,m)c\left(n\right)=\left\{b\left(n\right)=0:1,0\right\}if b(n)=0,output 1,otherwise 0\left(a,1\right)Fizzc\left(3\right)This is just points at (a,1) labeled with fizz, and opacity c(3)\left(a,0\right)Buzzc\left(5\right)Same with Buzz\left(a,0\right)${a}b\left(3\right)b\left(5\right)Points at (a,0) with label a, opacity b(3)b(5)
Vyxal, j, 65 bits1, 18 17 14 12 11 8.125 bytes
₁ƛ₍₃₅kF½*∑∴
Try it Online! (link is to bitstring)
I refuse to be beaten by Arn, Ash and Fig. I absolutely will not be beaten by any of those languages. Vyxal forever lads.
And yes, that really is 8.125 bytes. We have a fractional byte encoding system now. The 65-bit bitstring can be found at the online link.
The program is presented as SBCS for convenience.
Explained
₁ƛ₍₃₅kF½*∑∴
₁ # Push 100 to the stack
ƛ # Over the range [1, 100], map: (we'll call the argument n)
₍₃₅ # [n % 3 == 0, n % 5 == 0] (call this X)
kF # "FizzBuzz"
½ # ["Fizz", "Buzz"] # halve the string - split into two equal pieces
*∑ # sum(X * ↑)
∴ # max(↑, n)
# The -j flag joins on newlines before outputting
If you want it flagless:
Vyxal, 12 bytes
₁⟑₍₃₅kF½*∑∴,
See how inconsequential flags are?
Vyxal, 17 bytes
₁⟑35fḊ`₴ḟȦ↑`½*∑∴,
No questionable built-ins, no flags, just plain legitimate fizzbuzz.
vemf, 33 bytes
d↨╕{╞"Fizz""Buzz"‼╞αó35,X·x≈?x◘αⁿ
A new language, a new fizzbuzz. 5 bytes longer than the one in the repo.
Explained
d↨╕{╞"Fizz""Buzz"‼╞αó35,X·x≈?x◘αⁿ
d↨╕{ # To each number n in the range 1..100
αó35 # [n % 3 == 0, n % 5 == 0]
"Fizz""Buzz"‼ # ["Fizz" if n % 3 == 0, "Buzz" if n % 5 == 0]
, # flatten
X # and store in variable x
·x≈? # is there stuff in x?
x◘αⁿ # yes: return x, else: return str(n)
Julia 59 char, 59 bytes
Below works in the Julia REPL
(x->(t="Fizz"^(x%3<1)*"Buzz"^(x%5<1);t>"" ? t : x)).(1:100)
an alternative solution of same char/byte length in Julia REPL is
(x->(s=x%3<1;t=x%5<1;(x,"Fizz"^s*"Buzz"^t)[s|t+1])).(1:100)
In search of the 59 char/59 bytes solution which includes a print statement.
Typescript Type System + ts-arithmetic, 257 bytes
import{Mod,Add}from"ts-arithmetic"
type x<n extends 0>=`${Mod<n,3>extends 0?"Fizz":""}${Mod<n,5>extends 0?"Buzz":""}`
type c<n extends 0>=x<n>extends""?n:x<n>
type a<z,n=1>=`${c<n>}
${n extends z?"":a<z,Add<n,1>>}`
type _=`${a<33>}
${a<66,33>}
${a<100,66>}`
The output is in the _ type, not emitted to STDOUT because the TS type system doesn't have that.
I've done some golfing but this can still be golfed heavily, maybe below 200 with a slightly different technique.
Unfortunately, we can't have type _=a<100> because TS won't generate recursive types more than 45-ish layers deep, so it has to be separated into three segments
jq -nr, 43 bytes
Exploiting that out-of-bounds array access evaluates to null. Works with jq 1.5+
range(100)+1|["Fizz"][.%3]+["Buzz"][.%5]//.
Thunno H N, \$ 27 \log_{256}(96) \approx \$ 22.22 bytes
e1+D35d%0="FBiuzzzz"Zlz*Js~
Thunno H d, \$32 \log_{256}(96) \approx\$ 26.34 bytes
R{1+zt3%!"Fizz"*s5%!"Buzz"*+s~ZK
Explanations:
# The H flag implicitly pushes 100 to the stack
e1+ # Map over range(100) and add one each time:
D # Duplicate the number
35d # Push the digits of 35 - [3, 5]
%0= # Push [divisible by 3, divisible by 5]
"FBiuzzzz" # Push string "FBiuzzzz"
Zl # Uninterleave to get ["Fizz", "Buzz"]
z*J # Multiply element-wise and join
s~ # Swap and logical or with the number
# After the map, the N flag joins by newlines
# The H flag implicitly pushes 100 to the stack
R{ # Loop through range(100):
1+ # Add one
zt # Triplicate so it is on the stack three times
3%! # Is it divisible by 3?
"Fizz"* # Multiply this by the string "Fizz"
# i.e. push "Fizz" if it's divisible by 3, "" otherwise
s # Swap so the number is back on top
5%! # Is it divisble by 5?
"Buzz"* # Multiply this by the string "Buzz"
# i.e. push "Buzz" if it's divisible by 5, "" otherwise
+ # Add them togther, so we have "Fizz", "Buzz", "FizzBuzz", or ""
s~ # Swap and perform `or`, so we get the number if it's ""
ZK # Print with a newline
# After the loop, the d flag stops the implicit output
Pyt, 91 bytes
11`ŕĐĐ5%⇹3%?ŕ:ŕ8⬡2+ƇĐ2ᴇ5+Ƈ7⬠Ƈ5Ș;?ŕ:ŕ8⬡2+ƇĐ9⬠Ƈ6⬡Ƈ4Ș;ǰĐĐąɬɔĐƩ?ŕ⇹ą⇹*ǰ⇹ąɬą\ǰƖ⇹ƥ:ŕŕŕƖĐƥ;⁺Đ2ᴇ⁺<łĉ
| Code | Action |
|---|---|
| 1 | Pushes 1 |
| 1`ŕ...ł | Do... while top of stack is truthy |
| ĐĐ5%⇹3% | Gets n mod 5 and n mod 3 |
| ?ŕ:ŕ8⬡2+ƇĐ2ᴇ5+Ƈ7⬠Ƈ5Ș; | If n mod 3 is 0, push "Fizz" |
| ?ŕ:ŕ8⬡2+ƇĐ9⬠Ƈ6⬡Ƈ4Ș; | If n mod 5 is 0, push "Buzz" |
| ǰĐĐąɬɔĐƩ?ŕ⇹ą⇹*ǰ⇹ąɬą\ǰƖ⇹ƥ:ŕŕŕƖĐƥ; | If the stack contains any letters, print only the letters; otherwise, print the number |
| ⁺Đ2ᴇ⁺< | Is the number less than 100? |
| ĉ | Clears the stack |
Rattle, 54 44 bytes
Fizz&Buzz|!I=[g+bs%3[0b0b^0]g%5[0b1b^0]B]100
This [was] my first answer in my new programming language! (This answer has since been golfed, and works on my new online interpreter)
Eventually, this programming language might have a more concise way to solve this challenge.
^this ended up being true - after a couple updates, 10 bytes can be shaved off the original answer (without implementing trivial built-ins)
Explanation
Fizz&Buzz a variable containing the text Fizz and Buzz
| signals the end of the input
! is a flag to disable implicit printing at EOF
I splits the variable into parts and stores it in consecutive memory slots
= sets top of stack to 0
[ start outer loop
g+bs gets value at slot 3 (starts at zero), increments, appends it to a buffer, saves it to slot 3
%3 takes the current value on stack and pushes the value mod 3 to stack
[0b0b^0] if the value on stack is equal to 0, concatenates value from memory slot 0 ("Fizz") to a buffer and nullifies the 0th element of the buffer
g%5 pushes value from slot 3 to stack, takes the value and pushes the value mod 5 to stack
[0b1b^0] if the value on stack is equal to 0, concatenates the value from memory slot 1 ("Buzz") to the buffer and nullifies the 0th element of the buffer if not null already
B if the buffer is non-empty, prints buffer
]100 end outer loop - repeats 100 times
Thunno N, \$35\log_{256}(95)\$ ≈ 28.80921 bytes
aSR1+eD3 5ZP%0="FizzBuzz"2APz*JD!?K
Attempt This Online! (not yet though)
Thought I'd try my usual approach in Thunno to see how it turned out.
Explained
aSR1+eD3 5ZP%0="FizzBuzz"2APz*JD!?K
aSR1+ # The range [1, 100]
e # To each item:
D # Duplicate it
3 5ZP% # [% 3, % 5]
0= # == 0
"FizzBuzz"2AP # ["Fizz", "Buzz"]
z* # repeated element-wise
J # "".join
D!?K # if that's empty, leave the original number
# The N flag, of course, joins the output on newlines
Miled, 143127 bytes
I don't know if a language in alpha is allowed, but here it is.
-16 by myself. Yes. I was dumb.
join "\n" map fn cS "x" <: if:: div 15 x "FizzBuzz" else if:: div 3 x "Fizz" else if:: div 5 x "Buzz" else ->str x :> ..= 1 100
A little note on this language: it's created by me. The current release is the first release of the language and it's still in alpha, so expect bugs. I haven't encountered any yet, so I think, maybe the best way to test it is to make more people use it! So if you find bugs, please report it. And I'm just a hobbyist with few coding experiences, so please give me advices. Thanks!
Functional(), 314 310 288 277 273 269 bytes
0,1,=,:,$,&,$(X,& >($(I,T(>(a,b,c,d),b d(0,I)(= a,a(=,1)b,a b(=,1)c,a b(c,d))))1))(:(T,&(a,b,c,d))(X(T(b(d,a c)($(S,T(W()1 b()0()1()1 0(= b)b(= b)>()0 1()> >()0 1()> > 0,0)),=(:(t,t(S,1)))(0,&()(u()>()0,:(W,T(>(a 1),W))a b c d >()0)))0,W()1()1()0()0)),:(u,&()(W a b c d
Try it online!
Try the 273B version online!
Try the 277B version online!
Try the 288B version online!
Try the 310B version online!
Try the 314B version online!
in a more readable form ( ommited last )s are added ):
0,1,=,:,$,&,
$(X,& >(
$(I,T(
>(a,b,c,d),
b d (0,I)(= a,a(=,1)b,a b(=,1)c,a b(c,d))
)) 1
))(
:(T,&(a,b,c,d))(
X(
T(
b(d,a c)(
$(S,T(
W() 1 b () 0 () 1 () 1 0 (= b) b (= b) > () 0 1 () > > () 0 1 () > > 0,
0
)),
=(
:(t,t(S,1))
)(
0,
&()(
u() > () 0,
:(W,T(>(a 1),W)) a b c d > () 0
)
)
) 0,
W() 1 () 1 () 0 () 0
)
),
:(u,&()(W a b c d))
)
)
explanation
The key of this code is a executer func "X" like a pseudo Python code below;
def executer(f):
def incrementer(a,b=0,c=0,d=0):
f(a,b,c,d)
nextf = nullf if b==1 and d==1 else incrementer
# nullf is a function to do nothing
nextf(1^a,a^b,(a&b)^c,(a&b&c)|d)
incrementer(1)
Then, this realize a 10-length loop to evaluate f(1,0,0,0), f(0,1,0,0), f(1,1,0,0), ... , f(0,1,0,1) in this order. The parameters a,b,c,d describe 4 bits of 1 thru 10 ( the lowest bit first ).
Thus, the rough structure of this code is a double loop with "X" like below;
X(
T(
X(
T(
** main part
* print Fizz or Buzz or FizzBuzz or the sequence number
* and print a newline
)
),
** post process
* re-assign "u", a func to print the upper digit, for the next iteration
)
)
"T" is a "function template" and acts like a synonym of "&(a,b,c,d)" ( a user function template with 4 parameters a,b,c,d ) due to the assignment with ":" at the 8th line.
In addition to "X" and "T", I implemented "W" and "S" func for output.
"W" is for bit-sequence output. "W" returns "W" itself after printing bits so that "W 0 1 0 1 0 0 0 0" print a bit sequence ( a newline in this case ) continuously for example. And "W" takes a parameter as a bit to print, but is improved, for compressing bit streams, to print two bits of 11 at a time with ">" .
"S" is for "Fizz" ( against parameter (x,1) ) or "Buzz" ( against parameters (x,0) ) output with "W".
Other function "u" and "t" are variable over the double loop.
"u" is for printing the lower 4 bits of the upper digits, and is re-assigned in the post process of the outer loop.
"t" acts as a 3 state register, which holds 0, 1 and "S", and is re-assigned with ":(t,t(S,1))" on every loop iteration. When "t" is 0 or 1, it is re-assigned with 1 or "S" respectively. And when "t" is "S", it is re-assigned with 0 as a return value of "S" after printing "Fizz".
Klong [klongpy], 62 bytes
,/{Z:::[x!3;"";"Fizz"],:[x!5;"";"Buzz"];:[Z;Z;$x],:#10}'1+!100
A nifty little K-like language I found on reddit. Uses the klongpy interpreter rather than the official C Klong interpreter.
Explained
,/{...}'1+!100
' :" To each item (x) in...
1+!100 :" the range [0, 100) + 1 -> [1, 100]...
{...} :" map the function described in the next code block
,/ :" join into a single string
Z:::[x!3;"";"Fizz"],:[x!5;"";"Buzz"];:[Z;Z;$x],:#10
Z:: :" Define Z to be:
, :" The concatenation of:
:[x!3;"";"Fizz"] :" "Fizz" if x % 3 == 0, else "" (note that the condition isn't actually x % 3 == 0 - it'd need to be something like 0=x!3. The order of the truthy and falsey branches has been swapped to accomodate this)
:[x!5;"";"Buzz"] :" and "Buzz" if x % 5 == 0, else "" (same note applies as above)
;:[Z;Z;$x] :" if Z isn't empty, return whatever Z is, else str(x)
,:#10 :" And add a newline (chr(10)) to that
Python, 580 bytes
Here's a version that pre-computes the FizzBuzz table and then just returns a slice, which would be useful if you're running a worldwide FizzBuzz service. It'd be more interesting in a language that has slices as a first-class construct. Either way, a very unoptimized implementation:
from typing import List
class FizzBuzz:
def __init__(self, max_n=10**4):
self.max_n = max_n
self.data = [i for i in range(0, self.max_n)]
for r in range(0, self.max_n, 3):
self.data[r] = "Fizz"
for r in range(0, self.max_n, 5):
self.data[r] = "Buzz"
for r in range(0, self.max_n, 15):
self.data[r] = "FizzBuzz"
def fizzBuzz(self, n: int) -> List[str]:
if n > self.max_n or n < 1:
return None # Out of range, not permitted
return self.data[1:n]
s = FizzBuzz()
print(s.fizzBuzz(100))
```
Whitespace(v0.3 on ideone.com), 210 bytes
code visualized with replacing space,tab,newline to 's','t','n':
sssnnsssnssstntssssnsssststtstsstnsstttnnstnssstttstttststnssttstnnstntssnntstnsnstnstnsstnssststsnsnssnstnsstssntsstnttsnnnnnssnstssttnsnttsttnttssnsnssssttsssstntstttnsstnsssssttttstsnsnstnsstnsssssnnssssnntn
Notice: This code works fine on ideone.com, though, has a wrong result on tio.com because of a difference in behavior of "putc" with a large number ( > 255 ).
Show wrong result on tio.com
Without the rule "Nothing can be printed to STDERR", this code can be shortened to 207 bytes with omitting an "end"(nnn) instruction.
Here is the disassembled code ( created with my original tool ).
push +0(0b) # 0000: ss-s-n
mark +0(0b) # 0004: nss-s-n
push +1(1b) # 0009: ss-st-n
add # 0014: tsss
dup # 0018: sns
push +361(9b) # 0021: ss-ststtstsst-n
push -3(2b) # 0034: ss-ttt-n
call null # 0040: nst--n
push +1909(11b) # 0044: ss-stttstttstst-n
push -5(3b) # 0059: ss-ttst-n
call null # 0066: nst--n
mul # 0070: tssn
jzero -0(0b) # 0074: nts-t-n
dup # 0079: sns
puti # 0082: tnst
mark -0(0b) # 0086: nss-t-n
push +10(4b) # 0091: ss-ststs-n
dup # 0099: sns
dup # 0102: sns
putc # 0105: tnss
mul # 0109: tssn
sub # 0113: tsst
jneg +0(0b) # 0117: ntt-s-n
end # 0122: nnn
mark null # 0125: nss--n
copy +3(2b) # 0129: sts-stt-n
swap # 0136: snt
mod # 0139: tstt
jneg +0(1b) # 0143: ntt-ss-n
dup # 0149: sns
push +97(7b) # 0152: ss-sttsssst-n
mod # 0163: tstt
putc # 0167: tnss
putc # 0171: tnss
push +122(7b) # 0175: ss-sttttsts-n
dup # 0186: sns
putc # 0189: tnss
putc # 0193: tnss
push +0(0b) # 0197: ss-s-n
mark +0(1b) # 0201: nss-ss-n
ret # 0207: ntn
Assembly (MIPS, SPIM), 202 bytes
main:add$7 1
li$2 4
la$4 F
rem$6 $7 3
bnez$6 n
syscall
n:rem$5 $7 5
bnez$5 o
or$4 5
syscall
j e
o:beqz$6 e
abs$4 $7
li$2 1
syscall
e:li$2 11
li$4 10
syscall
bne$7'd'main
j$ra
.data
F:.asciiz"Fizz""Buzz"
Explanation
This does a lot of SPIM abuse 😏
This assumes the following features of an empty program:
$a3/$7is0.datais otherwise empty and therefore page-aligned (address ofFis0x10010000)
# initial SPIM state:
# $a0 ($4): argc
# $a1 ($5): argv
# $a2 ($6): envp
# $a3 ($7): 0
main:
add $a3, 1 # Increment accumultor (initially 0)
li $v0, 4 # v0 = PRINT STRING
la $a1, FizzBuzz # a1 = "Fizz\0Buzz\0"
test_fizz:
rem $a2, $a3, 3 # a2 = acc % 3
bnez $a2, test_buzz # skip if not multiple of 3
fizz:
syscall # print("Fizz")
test_buzz:
rem $a1, $a3, 5 # a3 = acc % 5
bnez $a1, test_num # skip if not multiple of 5
buzz:
or $a0, 5 # FizzBuzz is aligned, FizzBuzz | 5 == FizzBuzz + 5
syscall # print("Buzz")
j newline # print newline
test_num:
beqz $a2, newline # skip if acc % 3 == 0
num:
abs $a0, $a3 # abs is shorter than move for positive nums
li $v0, 1 # v0 = PRINT NUMBER
syscall # print(acc)
newline:
li $v0, 11 # v0 = PRINT CHARACTER
li $a0, '\n' # a0 = '\n'
syscall # print('\n')
bne $a3, 100, main # Loop if not 100 (I use 'd' to avoid a space)
j $ra # return
.data
FizzBuzz:
.asciiz "Fizz" # 0x10010000 = "Fizz\0"
.asciiz "Buzz" # 0x10010005 = "Buzz\0"
Pure Bash, 62+1=63 bytes
Filename is x, which is 1-byte penalty.
Outgolfed user100411's answer by one byte.
!
((++x%3))||Fizz
((x%5))||$_\Buzz
echo ${_:-$x}
((x>99))||. x
How it works
! # invoke no command so $_ (last command's last argument) is reset
# First time: $_ was random string
((++x%3))||Fizz # increase x. if x mod 5 is zero try to invoke Fizz
# if invoked $_ is Fizz
# ((expression)) is not a command
((x%5))||$_\Buzz # like previous but prefix $_
echo ${_:-$x} # try to output $_ but if $_ is empty output $x
((x>99))||. x # load myself if x is less than 100
# . x does not change $_
Phooey, 53 4847 bytes
[100+1@@@@%3{"Fizz">&<}&%5{"Buzz">&<}>{&$i}"
"]
Outgolfed the creator at his own language. 😏
[100 while cell is not 100
+1 increment cell
@@@@ push four copies to the stack
%3 set cell to cell mod 3
{ if cell is not zero
"Fizz" print fizz
>&< pop value into the next cell to mark it
} endif
& pop original value from stack
%5{"Buzz">&<} repeat for buzz
> move to the next cell
{ if neither fizz or buzz set the next cell
& Pop to the cell
$i print number
} endif
"\n" print newline
all paths popped the value to this cell, loop
] end
The stack and tape are all filled with a lot of junk (as in ~200 numbers on the stack 100 items on the tape) and at the end since I don't consistently move the pointer or pop the same amount of times, but I don't care. 😏
I may make fun of the interpreter, but it is a pretty nice language.
- -5 bytes: Use stack instead of tape, and don't restore the tape and stack
- -1 byte: Simplify the logic to avoid the extra pop (in exchange for double the stack usage 😛).
MediaWiki markup + WP templates, 142 bytes
{{for nowiki|<br>|<nowiki>{{If then show|{{#ifeq:{{mod|{{{1}}}|3}}|0|Fizz|}}{{#ifeq:{{mod|{{{1}}}|5}}|0|Buzz|}}|{{{1}}}}}</nowiki>|count=100}}
Explanation
This will only work on the English Wikipedia.
{{for nowiki <!-- Simple loop -->
|<br> <!-- seperator for each line -->
|<nowiki>{{If then show| <!-- main looping code, wrapped in <nowiki> tags to prevent processing except by {{for nowiki}} -->
{{#ifeq:{{mod|{{{1}}}|3}}|0|Fizz|}}{{#ifeq:{{mod|{{{1}}}|5}}|0|Buzz|}}|{{{1}}}}}</nowiki> <!-- {{{1}}} is substituted with the index -->
|count=100}}
Pascal, 162 B
See also Free Pascal.
This program, however, requires a processor supporting features of ISO standard 10206 “Extended Pascal”, specifically the :0 width specifier in conjunction with string/char values.
Usually, for numeric arguments the n in write(42:n) specifies a minimum width the decimal representation shall occupy.
With string values, however, it specifies the exact width, i. e. possibly zero.
program p(output);var i:1..100;begin for i:=1 to 100 do if 0 in[i mod 3,i mod 5]then writeLn('Fizz':4*ord(i mod 3=0),'Buzz':4*ord(i mod 5=0))else writeLn(i:1)end.
For sake of readability the ungolfed version of above code plus some explanatory comments:
program fizzBuzz(output);
var
i: integer;
begin
{ Remember, in Pascal `for`-loop limits are inclusive. }
for i := 1 to 100 do
begin
{ Create a `set of integer` and check membership of `0`: }
if 0 in [i mod 3, i mod 5] then
begin
writeLn('Fizz':4 * ord(i mod 3 = 0), 'Buzz':4 * ord(i mod 5 = 0))
end
else
begin
{ For numeric values `:0` would have the same effect as `:1`. }
{ Therefore this is in the `else` branch. }
writeLn(i:1)
{ The `:1` just ensures there are no leading blanks }
{ regardless of implementation (the compiler) used. }
end
end
end.
For a non-golfed version visit, for example, RosettaCode.
PowerShell, 78 68 61 54 51 Bytes
(-1 byte thanks to a person on Twitter that explicitly started following me just to tag me in a Tweet with a golf, because they don't use SE. I was able to improve on that with a bit more of a golf. But since it requires the new ternary operator in pwsh 7, I'm leaving the old versions present lower down.)
1..100|%{($x="Fizz"*!($_%3)+"Buzz"*!($_%5))?$x :$_}
Loops from 1 to 100, each time constructing $x by exploiting implicit Boolean conversion. That is, if $_%3 is 0, it gets converted to $true with the !, then the * re-converts it to a 1 so that we add on "Fizz" to $x. We encapsulate that construction in parens, so we can re-use it as the introductory query to the ternary operator, choosing to either output $x or $_, depending on whether $x is present.
Normally here is where I'd link it to Try It Online, but that's still on pwsh Core 6.2.3, so doesn't have the ternary operator.
Pre-pwsh 7
1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]}
Edit: Saved 10 bytes thanks to feersum
Edit2: Realized that with feersum's trick, I no longer need to formulate $t as a string-of-code-blocks
Edit3: Saved another 7 bytes thanks to Danko Durbić
Similar-ish in spirit to the stock Rosetta Code answer, but golfed down quite a bit.
Explanation
1..100|%{...} Create a collection of 1 through 100, then for-each object in that collection, do
(...,$_) create a new collection of two elements:
0) $t=... set the variable $t equal to a string;
$_our-current-number of the loop
"Fizz"*!($_%3) take our-current-number, mod it by 3, then NOT the result. Multiply "Fizz" by that, and add it to the string (and similar for 5). PowerShell treats any non-zero number as $TRUE, and thus the NOT of a non-zero number is 0, meaning that only if our-current-number is a multiple of 3 will "Fizz" get added to the string.
[!$t] indexes into the collection we just created, based on the value of the string $t -- non-empty, print it, else print our-current-number
Alternatively, also 54 bytes
1..100|%{'Fizz'*!($_%3)+'Buzz'*!($_%5)-replace'^$',$_}
Thanks to TesselatingHeckler
Similar in concept, this uses the inline -replace operator and a regular expression to swap out an empty string ^$ with our-current-number. If the string is non-empty, it doesn't get swapped.
Alternatively, also 54 bytes
1..100|%{($_,('Fizz'*!($_%3)+'Buzz'*!($_%5))|sort)[1]}
This is the same loop structure as above, but inside it sorts the pair (n, string), and relies on the fact that an empty string sorts before a number, but a FizzBuzz string sorts after a number. Then it indexes the second sort result.
Convex, 35 bytes
A²´{__3%!"Fizz"*\5%!"Buzz"*+\e|}%N*
Why must older golfing languages not having automatically vectorising operations?
Explained
A²´{__3%!"Fizz"*\5%!"Buzz"*+\e|}%N*
A²´{ }% e# to the range [1, 100]:
__ e# Triplicate the item
3%!"Fizz"* e# Repeat the string "Fizz" (!item % 3) times
\5%!"Buzz"* e# Repeat the string "Buzz" (!item % 5) times
+\e| e# Add the two strings together and logical or with the item
N* e# Join that on newlines
Fig, \$25\log_{256}(96)\approx\$ 20.578 bytes
#jeFcdn3n5a@2'D&=g"'+D&=_
Take that, Lyxal. Not so bad now, is it? Only 0.5 bytes longer than Jelly, and 3.5 longer than legit Vyxal.
#jeFcdn3n5a@2'D&=g"'+D&=_
a@2 # The range [1, 10^2]
n5 ' # For every 5th item
D&=g" # Replace with the compressed string for "Buzz"
n3 ' # For every 3rd item
+ # Prepend
D&=_ # The compressed string "Fizz"
eF # Filter out
cd # Digits
#j # Join on newlines
Fig, \$31\log_{256}(96)\approx\$ 25.517 bytes
jcnnna100 5'"Buzz"3'FOa9+"Fizz"
Hmm yes irrational bytes. "It'll be shorter" they said. "It's the future of golf".
8.5 bytes longer than legitimate vybuzz, 5.5 more than Jelly, 15.5 more than the optimal vybuzz/Fact fizzbuzz.
Explained
jcnnna100 5'"Buzz"3'FOa9+"Fizz"
na100 5'"Buzz" # Every 5th item of the range [1, 100] replaced with "Buzz"
n 3' # To every 3rd item of that:
+"Fizz" # Prepend the word "Fizz"
FOa9 # And remove all digits from it. This should just be FcD (because cD is allegedly all digits), but turns out that cD is [A-z0-9], which is allegedly what cN is supposed to be, but cN errors out. Thanks Seggan very cool.
jcn # Join all that on newlines
D, 90 bytes
import std;void main(){foreach(i;1..101)i.text.max("FizzBuzz"[i%3?4:0..i%5?4:8]).writeln;}
Dart, 88
main({i=0}){while(i<100)print(["FizzBuzz","Fizz","Buzz",++i][(i%3).sign*2+(i%5).sign]);}
Dart is somewhat hampered in the golfing by not having conversion between bool and int, but the sign getter on integers helps a little.
CATHY, 420 bytes
cathYcathycathyCathYcatHYCAthycATHyCatHYCAtHycaThYCAthycATHyCatHYcaThYCAthyCaTHYCatHYcathYCAtHycAThycAThYcathYCAtHycAtHYCatHyCatHYCathYcaTHYcathyCATHycathYcathycaThYCATHycaTHycaTHyCATHycathYcathYcaTHYCATHycAtHycAtHycAtHycatHycAThycathYcatHycatHyCATHycatHycAThYcAtHycAThYcATHycAtHyCatHyCAtHyCathYcATHycAtHyCatHyCatHYcathYCAtHycAThycAThYcathYCAtHycAtHYcathYcathycathyCathYcathyCATHycathycAThYCaTHYCatHycAThYcAtHyCathYCAThY
What have I done...
In normal form:
100⟑3τƒ:$5τƒ:5τJ:1$/*1$-;:⟑70C105C66C117C+++2/122C2*+*ƒ+;$⟑ƒ+;:1$/*1$-100⟑0C0*J;*+⟑,
=== Part 1: divisors ===
100⟑3τƒ:$5τƒ:5τJ:1$/*1$-;
100⟑ ; # Map 1...100 to...
3τƒ: # Convert to base 3 and get the last (dup-reduce)
$5τƒ: # Also convert to base 5 and get last (dup-reduce)
5τJ # Wrap in a list by converting to base 5 again, and concat
:1$/ # Duplicate and take reciprocal
* # Multiply, resolving 1+s to 1 and 0s to 0
1$- # Subtract from 1
# Leaving [divisible by 3, divisible by 5]
=== Part 2: Fizz and Buzz ===
:⟑70C105C66C117C+++2/122C2*+*ƒ+;
:⟑ ; # Duplicate previous and map to...
70C105C66C117C+++ # Construct string "FiBu"
2/ # Divide into two pieces
122C # chr(122) = z
2*+ # Double and append to each
*ƒ+ # Repeat by the above and concatenate
=== Part 3: Putting it together ===
$⟑ƒ+;:1$/*1$-100⟑0C0*J;*+⟑,
$⟑ƒ+; # Swap and sum each
:1$/*1$- # Turn 2s into 1s
100⟑ ; # Map 1...100 to...
0C0*J # Concatenate the empty string (stringify)
* # Repeat numbers by amounts
+ # Concatenate
⟑, # Over each, print
Cubestack, 178 162 bytes
M R2 f' M' S S' y S S' y2 M R' M' R E M r M' E2 M r2 M' E' U M R M' D E S R' b' R2 b r U2 r U2 S' E2 S R' B r l r U2 r U2 S' E' L S S' u S S' y2 M R' M' R F2 b y'
Final cube state:
Another fine addition to the collection of FizzBuzz I've written.
Explained
M R2 f' M' S S' y # For each item in the range [0, 100)
S S' y2 M R' M' R # Push that item + 1 to the stack
E M r M' E2 M r2 M' E' # Push the list [3, 5] to the stack
U # Calculate [(item + 1) % 3, (item + 1) % 5]
M R M' D # and check if each of those results is equal to 0
E ... E2 # Push the list ["Fizz", "Buzz"] to the stack
L S S' u # and multiply the strings with the modulo equality list.
# This implements the ("Fizz" * (item % 3 == 0)) + ("Buzz" * (item % 5 == 0))
# I use in my other fizzbuzzes to concisely do the multiplicity check
S S' y2 M R' M' R # Push the item + 1 to the stack again. Needed because there's no DUP yet
F2 b # Logically or that with the FizzBuzz string and print with a newline.
# If the item isn't divisible by 3 or 5, then the fizzbuzz string will be empty
# meaning the logical or here will return the number. Otherwise it'll return whatever word is needed.
y' # End the loop
Kustom, 72 bytes
This somehow gets a decent score for what it is?
I'm not sure if this language even has an official name, but it's used in a few Android customization apps (KLWP, KWGT, and KLCK). Kustom function documentation for those curious
$fl(1,100,"i+1","if(i%3=0&i%5=0,FizzBuzz,i%3=0,Fizz,i%5=0,Buzz,i)","
")$
and a bit more readable:
$fl(
1,
100,
"i+1",
"if(
i%3 = 0 & i%5 = 0,
FizzBuzz,
i%3 = 0,
Fizz,
i%5 = 0,
Buzz,
i
)",
"
"
)$
Squirrel, 131 bytes
for(local i=0;i++<100;)if(i%15==0)print("FizzBuzz\n")else if(i%5==0)print("Buzz\n")else if(i%3==0)print("Fizz\n")else print(i+"\n")
This is the original code that I created:
function fizzBuzz(n) {
for (local i = 1; i <= n; i += 1) {
if (i % 15 == 0)
print ("FizzBuzz\n")
else if (i % 5 == 0)
print ("Buzz\n")
else if (i % 3 == 0)
print ("Fizz\n")
else {
print (i + "\n")
}
}
}
fizzBuzz(100);
rSNBATWPL, 57 bytes
for{i=1;i<101}$print{(("Fizz"*1>i%3)+"Buzz"*1>i%5)or++$i}
RSNBATWPL, or Radvylf Should Not Be Allowed To Write Programming Languages, is a "practical" programming language I've designed over the last week or so. It aims to be a sort of "super-JS/PHP/C++": a language that seems practical to the uninitiated and allows writing nice code, but deep down, is horribly cursed.
This is a significantly golfed version of my more readable FizzBuzz program:
n = cast.int{input{"Input: "}};
for {i = 1; i <= n; ++$i} {
cond {(i % 3) and (i % 5)} {
print{i};
} {
s = "";
if {not{i % 3}} {
s += "Fizz";
};
if {not{i % 5}} {
s += "Buzz";
};
print{s};
};
};
It uses a few interesting golfs, like replacing function calls (with {}) with the $ operator (which calls a function with an argument). It also relies on rSN's weird parsing order, with things like +"Buzz"*1>i%5 only being possible because rSN is always parsed right-to-left. In this case, we also make use of multiplying a string by a bool, a type hack similar to what you'd see in JS.
V (vlang.io), 137 bytes
fn main(){for i in 1..101{if i%15==0{println('FizzBuzz')}else if i%3==0{println('Fizz')}else if i%5==0{println('Buzz')}else{println(i)}}}
Ungolfed code:
fn main () {
mut i := 1
for i < 101 {
match true {
i % 15 == 0 {
println('FizzBuzz')
} i % 3 == 0 {
println('Fizz')
} i % 5 == 0 {
println('Buzz')
} else {
println(i)
}
}
i++
}
}
SQLite, 183 bytes
WITH F AS(SELECT 1 AS N UNION ALL SELECT N+1 FROM F WHERE N<100)SELECT CASE WHEN N%15=0 THEN'FizzBuzz'WHEN N%5=0 THEN'Buzz'WHEN N%3=0 THEN'Fizz'ELSE CAST(N AS VARCHAR)END AS F FROM F;
Ungolfed code:
WITH F AS(
SELECT
1 AS N
UNION ALL
SELECT
N + 1
FROM
F
WHERE
N < 100
)
SELECT
CASE WHEN N % 15 = 0 THEN 'FizzBuzz' WHEN N % 5 = 0 THEN 'Buzz' WHEN N % 3 = 0 THEN 'Fizz' ELSE CAST(N AS VARCHAR) END AS F
FROM
F;
Prolog (SWI), 225 229 165 bytes
f(N,'FizzBuzz'):-N mod 15<1. f(N,'Fizz'):-N mod 3<1,N mod 5>0. f(N,'Buzz'):-N mod 3>0,N mod 5<1. f(N,N):-N mod 3>0,N mod 5>0. :-between(1,100,X),f(X,Y),\+writeln(Y).
Thanks to @JoKing (redundant init and h), I lost 64 bytes!
:-initialization m. f(N,'FizzBuzz'):-N mod 3=:=0,N mod 5=:=0. f(N,'Fizz'):-N mod 3=:=0,N mod 5=\=0. f(N,'Buzz'):-N mod 3=\=0,N mod 5=:=0. f(N,N):-N mod 3=\=0,N mod 5=\=0. m:-between(1,100,X),f(X,Y),write(Y),nl,fail,h(0). m:-h(1).
Morse Code, 1777 bytes
.---- / ..--- / ..-. .. --.. --.. / ....- / -... ..- --.. --.. / ..-. .. --.. --.. / --... / ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / .---- .---- / ..-. .. --.. --.. / .---- ...-- / .---- ....- / ..-. .. --.. --.. -... ..- --.. --.. / .---- -.... / .---- --... / ..-. .. --.. --.. / .---- ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ..--- ..--- / ..--- ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ..--- -.... / ..-. .. --.. --.. / ..--- ---.. / ..--- ----. / ..-. .. --.. --.. -... ..- --.. --.. / ...-- .---- / ...-- ..--- / ..-. .. --.. --.. / ...-- ....- / -... ..- --.. --.. / ..-. .. --.. --.. / ...-- --... / ...-- ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / ....- .---- / ..-. .. --.. --.. / ....- ...-- / ....- ....- / ..-. .. --.. --.. -... ..- --.. --.. / ....- -.... / ....- --... / ..-. .. --.. --.. / ....- ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ..... ..--- / ..... ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ..... -.... / ..-. .. --.. --.. / ..... ---.. / ..... ----. / ..-. .. --.. --.. -... ..- --.. --.. / -.... .---- / -.... ..--- / ..-. .. --.. --.. / -.... ....- / -... ..- --.. --.. / ..-. .. --.. --.. / -.... --... / -.... ---.. / ..-. .. --.. --.. / -... ..- --.. --.. / --... .---- / ..-. .. --.. --.. / --... ...-- / --... ....- / ..-. .. --.. --.. -... ..- --.. --.. / --... -.... / --... --... / ..-. .. --.. --.. / --... ----. / -... ..- --.. --.. / ..-. .. --.. --.. / ---.. ..--- / ---.. ...-- / ..-. .. --.. --.. / -... ..- --.. --.. / ---.. -.... / ..-. .. --.. --.. / ---.. ---.. / ---.. ----. / ..-. .. --.. --.. -... ..- --.. --.. / ----. .---- / ----. ..--- / ..-. .. --.. --.. / ----. ....- / -... ..- --.. --.. / ..-. .. --.. --.. / ----. --... / ----. ---.. / ..-. .. --.. --.. / -... ..- --.. --..
Pascal (FPC), 180 bytes
program f(o);var i:integer;begin for i:=1to 100do if i mod 15=0then writeln('FizzBuzz')else if i mod 3=0then writeln('Fizz')else if i mod 5=0then writeln('Buzz')else writeln(i)end.
Nim, 72 bytes
for i in 1..100:echo max(["Fizz",""][i*i%%3]&["Buzz",""][ord i%%5>0],$i)
JavaScript (code.golf), 62 56 bytes
for(i=0;++i<101;print(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
This is a code.golf version, which allows usage of print instead console.log.
Here is the un-code.golfed version:
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
Fortran (GFortran), 187 bytes
DO I=1,100
IF(MOD(I,3)==0.AND.MOD(I,5)==0)THEN;PRINT'(A)','FizzBuzz'
ELSEIF(MOD(I,3)==0)THEN;PRINT'(A)','Fizz'
ELSEIF(MOD(I,5)==0)THEN;PRINT'(A)','Buzz'
ELSE;PRINT'(I0)',I
ENDIF;ENDDO;END
D, 115 bytes
import std;void main(){string x;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),writeln(x?x:i.to!string)){};}
Adapted from this code:
import std;void main(){auto fizzbuzz(in uint i){string r;if(i%3==0)r~="Fizz";if(i%5==0)r~="Buzz";if(r.length==0)r~=i.to!string;return r;}enum r=1.iota(101).map!fizzbuzz;r.each!writeln;}
Crystal, 114 bytes
1.upto(100)do|n|case when n%15==0;puts "FizzBuzz"when n%5==0;puts "Buzz"when n%3==0;puts "Fizz"else puts n end end
How it works:
First, it tells it to repeat the code 100 times, with the iteration as n.
If n mod 15 = 0, then output FizzBuzz.
If n mod 5 = 0, then output Buzz.
If n mod 3 = 0, then output Fizz.
If none of those are true, just output the iteration, n.
Aya, 37 bytes
[100,Y""y3%0="Fizz"?y5%0="Buzz"?+:P];
I recently discovered Aya (so this code is likely not optimal), but really want to spread the word.
How it works
First, here are all the relevant operators:
[<number>,<expression>] | performs a list comprehension
| by taking all numbers from 1 to <number> (inclusive)
| and applying the expression to that number
Y | copies the value at the top of the stack into y
"" | puts an empty string on the stack
<num a> <num b> % | pop the topmost two values, store a mod b on stack
<num a> <num b> = | pop the topmost two values, store a equals b on stack
<any a> <any b> ? | pop the topmost two values, if a is truthy: keep b on stack
<any a> <any b> + | pop the topmost two values, store concatenation of a and b on stack
<any a> :P | pop the topmost value, format a as string, perform println
; | pop the topmost value
The main "gimmick" here, is that + only operates on the topmost two values.
So by placing [y ""] on the stack first, any addition to the stack will push y out of the scope of +.
Conditionally adding "Fizz" and "Buzz" to the stack leaves us with 4 possible compositions when + is executed:
[y ""]- when y is not divisible by 3 or 5[y "" "Fizz"]- when y is divisible by 3 but not 5[y "" "Buzz"]- when y is not divisible by 3 but is divisible by 5[y "" "Fizz" "Buzz"]- when y is divisible by 3 and 5
The list comprehension captures anything that remains on the stack as elements of the list, so we can drop all of the junk with a single ; at the end.
For the curious, this is what remains in the list:
[ 3 5 6 9 10 12 15 "" 18 20 21 24 25 27 30 "" 33 35 36 39 40 42 45 "" 48 50 51 54 55 57 60 "" 63 65 66 69 70 72 75 "" 78 80 81 84 85 87 90 "" 93 95 96 99 100 ]
Quipu, 101 bytes
1&0&'F0&'B1&\n
++[]'i[]'u[]/\
1%3&'z5&'z6&0&
1&%%'z%%'z==??
%%3&/\5&/\0&
1&>> >>6&[]
>> ??/\
::
Ungolfed:
" 0 1 2 3 4 5 6"
"--------------------"
1& 0& 'F 0& 'B 1& \n
++ [] 'i [] 'u [] /\
1% 3& 'z 5& 'z 6& 0&
1& %% 'z %% 'z == ??
%% 3& /\ 5& /\ 0&
1& >> >> 6& []
>> ?? /\
::
Thread 0 increments the accumulator (acc) every iteration, stopping execution if acc == 101, then jumps to thread 1.
Thread 1 checks if (acc % 3) > 0. If so, it jumps to thread 3, otherwise it jumps to thread 2.
Thread 2 prints Fizz, then jumps to thread 3.
Thread 3 checks if (acc % 5) > 0. If so, it jumps to thread 5, otherwise it jumps to thread 4.
Thread 4 prints Buzz, then jumps to thread 6.
Thread 5 looks back to thread 1 to see if (acc % 3) == 0. If so, it jumps to thread 6, otherwise it prints acc, then jumps to thread 6.
Thread 6 prints a newline, then jumps back to thread 0.
I think this could probably be refactored to golf away some of the whitespace, but I'm not doing that since if I do, I'll likely get sucked in and do nothing else for ~8 hours or so. :/
Kotlin, 117 bytes
{for(i in 1..100){println("${if(i%3<1)"fizz" else ""}${if(i%5<1)"buzz" else ""}${if(!(i%3<1||i%5<1))"$i" else ""}")}}
as usual as it gets
edit: i hope the extra \n at the end is not a problem
Python, 108 102 bytes
Thanks to caird coinheringaahing for -6 bytes!
for x in range(1,101):
y=""
if x%3<1:y="Fizz"
if x%5<1:y+="Buzz"
y=y or x
print(y)
Vyxal, Hj, 25 19 12 bytes
-6 bytes thanks to Aaron
-7 bytes thanks to lyxal
Flagless 15 bytes
Longer than lyxal's answer, but uses a different technique
ƛ₃kf*n₅kb*+∴ stack is preset to a 100 because of the `H` flag
ƛ lambda map with variable n
₃ push 1 if n%3 == 0 (we'll call the return a)
kf push constant Fizz to the stack
* push a*kF
n push n
₅ push 1 if n%5 == 0 (we'll call it b)
kb push Buzz to the stack
* push b*kB
+ add last two elements of the stack ""/Fizz/Buzz
∴ push the maximum of n and ""/Fizz/Buzz/FizzBuzz
Vyxal prints out the last element of the stack by default (the `j` flag joins the list with new lines)
Apple Shortcuts, 9 actions
This creates a loop that runs 100 times. For each loop, it gets the iteration number and modulos it by 3. We then take the result and use regex replacement to change it to “Fizz” if it is 0. Then, we take the iteration number and use regex replacement to change it to “Buzz” if it ends in 0 or 5.
At this point, we have a value that is either “Fizz” or a number, and we have a value that is either “Buzz” or a number. We combine those two values together into a single string, and use regex replacement to remove any numbers. This leaves us with one of “Fizz”, “Buzz”, “FizzBuzz”, or an empty string. Finally, we use one more regex replacement to replace an empty string with the iteration number.
The final value left at the end of each iteration is added to the repeat results, so after the loop has finished running, we simply print the list of repeat results with a “show result” action, which automatically formats the list as a bunch of newline separated values.
For those who don’t want to/don’t know how to enter this code, here’s an iOS link that should hopefully maybe possibly work.
Apple shortcut language, 31 actions, 23580 bytes
Here's a link that'll open it in iOS. Warning: May brick your device, use with caution.
Here's a downloadable file that can be imported on MacOS. The size of this file is the score.
This was a huge pain, especially taking and combining all the screenshots for the above image. The language has several annoying bugs features though:
- The 'add to variable' action treats it as a list, even if it's a number
- There's no way to create a range
- There's one output, so you have to combine everything into that
- very basic list support only
- No way to do a while loop / break out of a loop
It's sorta equivalent to the pseudocode:
O = []
C = 0
repeat 100:
T = ''
C += 1
if C % 3 == 0:
T += 'Fizz'
if C % 5 == 0:
T += 'Buzz'
if T == '':
T = C
O += T
print '\n'.join(O)
Pip, 32 31 30 bytes
LhP J["Fizz""Buzz"]X!*Ui%^35|i
Here's the 31-byte equivalent in Pip Classic: Try it online!
Explanation
LhP J["Fizz""Buzz"]X!*Ui%^35|i
Preinitialized variables: h=100, i=0
Lh Loop 100 times:
^35 Split 35 into a list of digits: [3 5]
Ui Pre-increment i (thus starting at 1, not 0)
% Mod (vectorizing); our list is now [i%3 i%5]
!* Map logical not to that list (1 if mod was 0, else 0)
["Fizz""Buzz"] List containing Fizz and Buzz
X Repeat string (vectorizing)
Our two items are now:
"Fizz" if i is divisible by 3, "" otherwise
"Buzz" if i is divisible by 5, "" otherwise
J Join that list into a single string
P |i Logical OR with i, and print
jq, 78 bytes
range(1;101)|. as $n|[(select(.%3==0)|"Fizz"),(select(.%5==0)|"Buzz")]|add//$n
RickRoll-Lang, 185 bytes
takemetourheart
give a up [*range(1,101)[::-1]]
togetherforeverandnevertopart
give i up a.pop()
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1)
ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n"
Explanation:
RickRoll-Lang keywords do not need spaces between them
takemetourheart -- main() function declaration
give a up [*range(1,101)[::-1]] -- set a to reverse of int range [1, 101)
togetherforeverandnevertopart -- infinite loop
give i up a.pop() -- pop last element of a and store in i
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1) -- string multiplcation to form fizzbuzz depending on modulus remainders
ijustwannatelluhowimfeeling [str(i),s][s>""]+"\n" -- print i if s is empty else s and a newline
-- implicit "say goodbye" (end block) at the end
-- another say goodbye
Pure Bash, 70 bytes 69 bytes 68 bytes 63 + 1 = 64 bytes
The following program must be saved as x, which is for 1 byte of penalty.
''
((++x%3))||Fizz
((x%5))||$_\Buzz
echo ${_:-$x}
((x>99))||. x
aussie++, 223 190 187 bytes
G'DAY MATE!
I RECKON x IS A WALKABOUT FROM[1TO 100]<YA RECKON x %15<1?<GIMME "FizzBuzz";>WHATABOUT x %5<1?<GIMME "Buzz";>WHATABOUT x %3<1?<GIMME "Fizz";>WHATABOUT ?<GIMME x;>>CHEERS C***!
Fair dinkum, this was hard yakka cause there's no way to golf the whitespace because the parser seems to be strict. I coulda sworn it never worked when I tried to remove whitespace.
-33 thanks to @Bubbler
-3 thanks to @JoKing
Wanna hear what it actually sounds like? Wonder no more: https://youtu.be/ewu1CmjZcmQ
Dash and utils, 89 bytes
f(){ [ $((i%$1)) = 0 ]&&j=$2zz$j;};for i in `seq 100`;do(f 5 Bu;f 3 Fi;echo ${j-$i});done
As a bonus this is partially obfuscated, containing neither Fizz nor Buzz (even saved 2 bytes in doing so).
88 bytes (with caveats)
f(){(: $((0/(i%$1))))||j=$2zz$j;};for i in `seq 100`;do(f 5 Bu;f 3 Fi;echo ${j-$i});done
This solution was an attempt to reduce the bytes used by the conditional. In the end it saved only 1 byte, but it spams STDERR, which actually looks OK on TIO because it separates the streams. Even so I’m not sure it’s a proper solution due to the spam, but honestly I’m quite proud of the trickery involved. We could suppress the errors with a redirect but that eats up precious bytes :)
EDIT: the trickery probably bears an explanation as the mechanism may not be immediately obvious.
Most of this explanation applies to the 89 byte, the only change is the conditional.
f(){
Define function f, easy enough.
(: $((0/(i%$1))))
This is the (most) sneaky bit
( begin a subshell, use : 'true' to perform some maths $(( in which we take 0 and divide / by the result of (i%$1), end the maths )) and end the subshell ).
This whole construct returns exit code 0 when the result of i % $1 is non-zero, otherwise it returns 1.
This works because when the i % $1 operation results in a zero we get a "division by zero" error terminating the subshell and causing it to return exit code 1.
This trumps the : "true" that the maths is running behind.
In all other instances we are taking zero and dividing it by a non-zero i % $1 result, which is obviously always zero by definition but the key thing is that it doesn't error the shell (thus the : stands) and from this we can catch the "division by zero" without the whole script bombing out.
||j=$2zz$j;};
Catch the error from the subshell via || and set j= to the value of $2 appending zz (to complete our Fizzes and Buzzes) and prepending the whole thing to $j (the prepend action stems from an earlier iteration and only remains so because there's no advantage in making it an append. Even more so now I've done this explanation), then just finish up the function ;};.
NB j lives and dies inside another subshell which calls this function, and is assumed to always start empty (but we'll get to that later).
for i in `seq 100`;do
As it appears, for loop through 1-100.
(f 5 Bu;f 3 Fi;echo ${j-$i})
The second (very mildly) sneaky part -- we start a subshell ( and for every number in the sequence, we call f twice. Once each for the FizzBuzz numbers 5, 3 (to be used in the i % $1 statement) and the corresponding two prefix letters which get used in making j. We then print the value of j or, if it's empty, insert the current $i value.
When we close the subshell, j gets reset to its starting value (empty, assuming we started in a clean room).
;done
Yes, I do believe we are.
XML + XSLT, 1282 635 bytes
output.xml
<?xml-stylesheet type="text/xsl" href="s.xsl"?><n></n>
s.xsl
<x:stylesheet version="1.0" xmlns:x="http://www.w3.org/1999/XSL/Transform"><x:output method="text" /><x:template match="n"><x:text>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
</x:text></x:template></x:stylesheet>
Hardcoding it is shorter than doing it the fun way :(
So here's the old way for posterity
1282 bytes
output.xml
<?xml-stylesheet type="text/xsl" href="s.xsl"?><n><N>1</N><N>2</N><N>3</N><N>4</N><N>5</N><N>6</N><N>7</N><N>8</N><N>9</N><N>10</N><N>11</N><N>12</N><N>13</N><N>14</N><N>15</N><N>16</N><N>17</N><N>18</N><N>19</N><N>20</N><N>21</N><N>22</N><N>23</N><N>24</N><N>25</N><N>26</N><N>27</N><N>28</N><N>29</N><N>30</N><N>31</N><N>32</N><N>33</N><N>34</N><N>35</N><N>36</N><N>37</N><N>38</N><N>39</N><N>40</N><N>41</N><N>42</N><N>43</N><N>44</N><N>45</N><N>46</N><N>47</N><N>48</N><N>49</N><N>50</N><N>51</N><N>52</N><N>53</N><N>54</N><N>55</N><N>56</N><N>57</N><N>58</N><N>59</N><N>60</N><N>61</N><N>62</N><N>63</N><N>64</N><N>65</N><N>66</N><N>67</N><N>68</N><N>69</N><N>70</N><N>71</N><N>72</N><N>73</N><N>74</N><N>75</N><N>76</N><N>77</N><N>78</N><N>79</N><N>80</N><N>81</N><N>82</N><N>83</N><N>84</N><N>85</N><N>86</N><N>87</N><N>88</N><N>89</N><N>90</N><N>91</N><N>92</N><N>93</N><N>94</N><N>95</N><N>96</N><N>97</N><N>98</N><N>99</N><N>100</N></n>
s.xsl
<x:stylesheet version="1.0" xmlns:x="http://www.w3.org/1999/XSL/Transform"><x:output method="text" /><x:template match="n"><x:for-each select="N"><x:if test=".mod 3=0">Fizz</x:if><x:if test=".mod 5=0">Buzz</x:if><x:if test=".mod 3*.mod 5!=0"><x:value-of select="."/></x:if><x:text> </x:text></x:for-each></x:template></x:stylesheet>
W...why did I do this to myself?
Example output (using Firefox + privacy.file_unique_origin = false):
Explaination
The XML
XSLT/XML doesn't (afaik) have a nice easy way of generating ranges...so I have to manually place all the numbers in tags so I can use for-each later on.
The XSLT
<x:stylesheet version="1.0"
xmlns:x="http://www.w3.org/1999/XSL/Transform"> <!-- Define the XSL namespace to be "X" for brevity -->
<x:output method="text" /> <!-- Textual output -->
<x:template match="n"> <!-- Match the root tag n -->
<x:for-each select="N"> <!-- For each N, which is a number in the range 1...100 -->
<x:if test=".mod 3=0">Fizz</x:if> <!-- If N % 3 == 0, write "Fizz" -->
<x:if test=".mod 5=0">Buzz</x:if> <!-- If N % 5 == 0, write "Buzz" -->
<x:if test=".mod 3*.mod 5!=0"> <!-- If N isn't divisible by either 3 or 5, write the number -->
<x:value-of select="."/>
</x:if>
<x:text> </x:text> <!-- Add a newline -->
</x:for-each>
</x:template>
</x:stylesheet>
jq, 98 82 bytes
range(1;101)|if.%15<1then"FizzBuzz"elif.%3<1then"Fizz"elif.%5<1then"Buzz"else. end
Yet to golf it!
Removed superfluous spaces thanks to @DLosc.
Fact, 11 bytes (SBCS)
ef̀|3 5^ŹFh̃õ
Explanation
e 1e2 (i.e. 100)
f̀ for i in 1:100
|3 5 Divisibility by [3, 5] (vectorizes)
^ String repeat by (vectorizes):
ŹF "FizzBuzz"
h̃ Halved (i.e. ["Fizz", "Buzz"])
õ Logical OR with i
(in Fact, lists are false when all items are "" or 0
or when the list is empty)
Implicit grid (smash inner lists and join outer list by newline)
Fact, 15 bytes
ef̀|3 5^'b̀M̀b̀Ò'h̃õ
No "FizzBuzz" builtin, simply uses string compression
><>, 68 66 65 64 63 bytes
1\2+2fooo o"Buzz"<
o>:::3%:?!\$5%:?!/*?n1+:aa*)?;a
o.!o"Fizz"/o
The only trick is to multiply remainders as a condition to number printing. That way, if one of them is 0 we won't print the number.
You can try it here.
Saved one byte thanks to Sp3000, another thanks to randomra, and a last one thanks to Jacklyn. Thanks a lot!
Javastack, 123 bytes
100 times context 1 add "Buzz"context 1 add 5 mod 0 equal repeat "Fizz"context 1 add 3 mod 0 equal repeat add logicor print
Context is everything. This is different to Wasif's Javastack answer because it uses a loop instead of a map, as well as extensive use of the context variable (totally not inspired by a certain golfing language made by a certain cg user with Flowey as his pfp).
Roughly equivalent to:
100ʁ ( n 1+ `Fizz` n 1+ 3 ḋt ¬ẋ `Buzz` n 1+ 5 ḋt ¬ẋ + ⟇, )
in vyxal.
You don't know how nice it was to write a Javastack answer without restrictions after 13 rounds of C&R.
Javastack, 145 bytes
100 range map 1 add duplicate 3 mod 0 equal "Fizz"swap repeat swap 5 mod 0 equal "Buzz"swap repeat swap add swap 1 add swap logicor end "\\n"join
-17 thanks to exedraj -22 thanks to new mod builtin
05AB1E, 25 bytes
тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,
I figured I'd add a fourth 05AB1E answer to this challenge. This uses my favourite "vectorise is-divisible and then repeat the fizbuzz list accordingly" approach.
Explained
тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,
тL # The range 1 .. 100
v # For each N in that range:
”FizzÒÖ”# # Push the list ["Fizz", "Buzz"]
y3 5‚Ö # Push N % [3, 5] == 0 (vectorised)
Ï # "Multiply" the two lists as you would in Vyxal
J # And concatenate that into a single string
y‚ # And pair that with N
é # Sorting that by length, so that the value we want is always last
θ, # And print it with a newline
PostScript, 73 bytes
Using binary encoding:
000000 31 88 01 88 64 7b 2f 69 92 3e 92 33 28 46 69 7a
000010 7a 42 75 7a 7a 29 69 88 0f 28 42 75 7a 7a 29 69
000020 20 35 28 46 69 7a 7a 29 69 88 03 33 7b 92 6a 30
000030 92 3d 7b 2f 69 92 3e 92 33 7d 7b 92 75 7d 92 55
000040 7d 92 83 69 20 3d 7d 92 48
Try it online! (thanks to tail spark rabbit ear, ignore TIO's character count).
This is a straight-forward encoding of the following 101 byte program (in binary encoding, 136 n is a signed 8-bit integer and 146 n is command n from the system name encoding list in appendix F of the PostScript language reference).
1 1 100{/i exch def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =}for
The non-binary encoded version can be reduced to 98 bytes if we don't mind leaving /i on the stack.
/i 1 1 100{def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =/i}for
Perl 5 (ppencode-compatible), 1232 690 bytes
Today I learned that and has higher precidence than or or xor; I suffered from making a proper control flow
eval q y eval q x ord or return cos while chop and chop and chop x and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y xor eval q y print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos if length q q s s q eq chr ord reverse length or not chr ord reverse length y or eval q x print length unless length q q s s q eq chr ord reverse length or not chr ord reverse length x xor print chr hex qw q and q while s qq q and length ne ord qw q eq
How it works
# fizz part
eval q y
# if(length%3==0)
eval q x
# instead of length or return 1
ord or return cos
while
# instead of s/...//
chop and chop and chop
x and
# print 'Fizz'
print chr ord uc qw q for q and
print chr ord q tie gt and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# for truthy
return cos
for
# instead of $_
uc
y
xor
# buzz part
eval q y
# print 'Buzz'
print uc chr ord q dbmopen and and
print chr ord q dump and and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# for truthy
return cos
if
# instead of length%5, /[05]$/
length q q s s q eq chr ord reverse length or
not chr ord reverse length
y
or
# this block is done when length%15==0 or length%3&&length%5
eval q x
print length
unless
# instead of length%5
length q q s s q eq chr ord reverse length or
not chr ord reverse length
x
xor
# newline
print chr hex qw q and q
while
s qq q and
# ord qw q eq == 101
length ne ord qw q eq
Previous
eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or print length xor print chr length q q x x x x eq while s qq q and length ne ord qw q eq
Explained
# fizzbuzz part
eval q y
# length%15==0?
eval q k
ill and length or return cos
while
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and o
k and
# then print FizzBuzz, as in first ppencode
print chr ord uc qw q for q and
print chr ord q tie gt and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
print uc chr ord q dbmopen and and
print chr ord q dump and and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# cos is for TRUTHY
return cos
# don't change $_ outside
for uc
# buzz part, like above
y or eval q y
eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# fizz part, like above
y or eval q y
eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# no special strings
y or print length
# print LF
xor print chr length q q x x x x eq
# pretty familiar, isn't it?
while s qq q and length ne ord qw q eq
Python 3, 59 bytes
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or-~i)
C++20, 202 bytes
this is uncompetitive, but this was so fun I couldn't help but post it here.
#include <bits/stdc++.h>
using namespace std;auto f=[](int i){return i%15?(i%5?(i%3?to_string(i):"Fizz"):"Buzz"):"FizzBuzz";};int main(){for(auto i:views::iota(1,100)|views::transform(f))cout<<i<<endl;}
Squire, 92 bytes
n=N whilst C>n{t=""n=n+I if!(n%3){t="Fizz"}if!(n%V){t=t+"Buzz"}proclaim((t||arabic(n))+"
")}
Hear ye, hear ye! Unbeknownst to some, Sampersand hath also created Squire, a companion language to ye lowly language Knight. Squire hath many possessions, but alas, it doth not golfeth as well as its brethren. Thou shalt check it out as well, though.
I cannot provideth thee with a demo link yet as the interpreter is a very lengthy incantation.
Ungolfeth:
# Createth a variable known by most as "n",
# He shalt begin his journey as a mere
# peasant with naught but the value zero.
# (Behold! Squire permits thee to write numbers
# in Roman numerals)
n = N
# Loop thine program unto n approacheth 100
whilst C > n {
# Lo! I spotteth another variable,
# who goes by the name of "t".
# It shall start off as a lonely empty string.
t = ""
# Increase n's wealth by bestowing upon it the number one
n = n + I
# If n divideth evenly into 3...
if !(n % 3) {
# Replaceth t with the string "Fizz"
t = "Fizz"
}
# If n also divideth evenly into 5...
if !(n % V) {
# Accompany t with the string "Buzz"
t = t + "Buzz"
}
# Proclaim to ye standard output...
proclaim(
# Either...
(
# t if it is not a lonely empty string...
t
# or n, converteth to ye foreign Arabic
# number system, used in lands afar.
|| arabic(n)
)
# Appendeth upon it a newline to start
# another journey.
+ "\n"
)
}
A more favorable program is as follows:
n=N whilst C>n{t=""n=n+I if!(n%III){t="Fizz"}if!(n%V){t=t="Buzz"}proclaim((t||string(n))+"
")}
This program useth Roman numerals, but nay, thine great quest beseecheth that one must outputeth thy program using this unusual number system.
Knight, 50 48 43 bytes
;=n 0W>101=n+1nO|+*"Fizz"!%n 3*"Buzz"!%n 5n
-2 bytes: use string multiplication instead of IF
-5 bytes: I completely overlooked |, I assumed it had C semantics.
Ungolfed:
# start with n at 0
; = n 0
# increment n and loop while less than 101
: WHILE > 101 (= n + 1 n)
# outlined from the output for clarity
# concatenate:
; = fizzbuzz +
# Fizz if n % 3 == 0
: * "Fizz" ! (% n 3)
# Buzz if n % 5 == 0
: * "Buzz" ! (% n 5)
# If fizzbuzz is not empty, output it, otherwise output n
: OUTPUT | fizzbuzz n
Pinecone, 90 bytes
i:1|i<101|i:i+1@(i%3+i%5=0?print:"FizzBuzz"|i%3=0?print:"Fizz"|i%5=0?print:"Buzz"|print:i)
PPL, 164 bytes
declarex=0
loop100{
x=x+1
ifx%15<1{
printLine("FizzBuzz")
}
ifx%3<1&&x%5>0{
printLine("Fizz")
}
ifx%5<1&&x%3>0{
printLine("Buzz")
}
ifx%3>0&&x%5>0{
printLine(x)
}
}
Yes... 164 bytes.
The problem with my language is that it's almost impossible to golf, because:
- the newline is the only separator
- all variables must be declared with the
declarekeyword - no shorthands like
+=or%= - no ternary operators
falseis the only falsey value- long function name:
printLine - no bitwise
and
The good thing is that because of my sloppy lexer, we can mash together expressions. You would never see ifx%15<1 or loop100 in Python, for example. [it's not a bug, it's a feature ...?]There also happens to be no documentation for PPL at the moment.
Branch, 98 bytes
\^//C//70/105/122Z/zc\/66/117/z/za1O[/ob3^%Vc/v?[./]b5^%Wc\w?[./]a/vbw^*/0bo^?[#0]a10.o}O/;b101^-]
Try it on the online Branch interpreter!
Explanation
The first part basically loads "Fizz" and "Buzz" along the left branches of two trees, so it looks like:
0
/ \
0 0
/| / \
F 0 B 0
/ /
i u
/ /
z z
/ /
z z
Then, start the value at 1. Each time, load the value to the left child and 3 to the right child, modulo, move that to the left fork, and branch on condition. If it's 0, it goes to the left branch with "Fizz" and otherwise to the right branch with just 0. [./] keeps printing as a character and moving to the left child so long as the value is not 0, so this prints "Fizz" if it's a multiple of three, and nothing happens otherwise.
Then, do the same thing but with 5 and move to the "Buzz" branch. Finally, load the results of both modulos (using registers to save and move these values) and multiply them. Loading 0 to the left child and the current value into the right branch, using ? on the product will go to the 0 if either modulo was 0, and to the value otherwise. Then, [#0] keeps outputting the value and zeroing it if it is not zero; in other words, if the modulo product was 0, it skips this, and otherwise, it outputs the current value as a number once.
Finally, output a newline, increment the current value, and check if it's high enough to end the program, and if so, exit the main loop.
Turing Machine Code, 5743 bytes
Should note that Turing Machine Code doesn't process newlines/carriage returns. So everything is necessarily on one line. Thus this may not be, by strict interpretation of the rules, a competing answer due to the nature of the language.
0 * * * 1
1 * 1 r #
# * # * f
f * * l f
f 1 1 l !
f 2 2 l "
f 3 3 l £
f 4 4 l $
f 5 5 l %
f 6 6 l ^
f 7 7 l &
f 8 8 l `
f 9 9 l (
f 0 0 l )
f F F l f
f i i l f
f z z l f
f B B l f
f u u l f
) 1 1 * ¬
) 2 2 * -
) 3 3 * =
) 4 4 * +
) 5 5 * {
) 6 6 * }
) 7 7 * [
) 8 8 * ]
) 9 9 * :
! _ _ r '
! 1 1 r @
! 2 2 * ~
! 3 3 r \
! 4 4 r /
! 5 5 * ,
! 6 6 r .
! 7 7 r <
! 8 8 * >
! 9 9 r ?
" _ _ r a
" 1 1 * b
" 2 2 r c
" 3 3 r d
" 4 4 * e
" 5 5 r ƒ
" 6 6 r g
" 7 7 * h
" 8 8 r ï
" 9 9 r j
£ _ _ r k
£ 1 1 r l
£ 2 2 r m
£ 3 3 * n
£ 4 4 r o
£ 5 5 r p
£ 6 6 * q
£ 7 7 r r
£ 8 8 r s
£ 9 9 * t
$ _ _ r ü
$ 1 1 r v
$ 2 2 * w
$ 3 3 r x
$ 4 4 r y
$ 5 5 * ž
$ 6 6 r A
$ 7 7 r Ɓ
$ 8 8 * C
$ 9 9 r D
% _ _ r E
% 1 1 * Ϝ
% 2 2 * G
% 3 3 * H
% 4 4 * I
% 5 5 * J
% 6 6 * K
% 7 7 * L
% 8 8 * M
% 9 9 * N
^ _ _ r O
^ 1 1 r P
^ 2 2 r Q
^ 3 3 * R
^ 4 4 r S
^ 5 5 r T
^ 6 6 * U
^ 7 7 r V
^ 8 8 r W
^ 9 9 * X
& _ _ r Y
& 1 1 r Z
& 2 2 * α
& 3 3 r β
& 4 4 r γ
& 5 5 * δ
& 6 6 r ε
& 7 7 r ζ
& 8 8 * η
& 9 9 r θ
` _ _ r ι
` 1 1 * κ
` 2 2 r λ
` 3 3 r μ
` 4 4 * ν
` 5 5 r ξ
` 6 6 r ο
` 7 7 * π
` 8 8 r ρ
` 9 9 r ς
( _ _ r σ
( 1 1 r τ
( 2 2 r υ
( 3 3 * φ
( 4 4 r χ
( 5 5 r ψ
( 6 6 * ω
( 7 7 r Α
( 8 8 r Β
( 9 9 * Γ
@ * * r @
@ # _ r Δ
Δ _ 1 r Ε
Ε _ 2 r F
' * * r '
' # _ r 2
2 _ 2 r #
~ * * r ~
~ 2 _ r ~
~ 1 _ r ~
~ # _ r Ζ
Ζ _ 2 r 2
\ * * r \
\ # _ r Η
Η _ 3 r 2
/ * * r /
/ # _ r Θ
Θ _ 4 r Ε
, * * r ,
, 5 _ r ,
, 1 _ r ,
, # _ r Ι
Ι _ 5 r 2
. * * r .
. # _ r Κ
Κ _ 6 r 2
< * * r <
< # _ r Λ
Λ _ 7 r Ε
> * * r >
> 8 _ r >
> 1 _ r >
> # _ r Μ
Μ _ 8 r 2
? * * r ?
? # _ r Ν
Ν _ 9 r 2
a * * r a
a # _ r Ξ
Ξ _ 3 r F
3 _ 3 r #
b * * r b
b 1 _ r b
b 2 _ r b
b # _ r Ο
Ο _ 1 r 3
c * * r c
c # _ r Π
Π _ 2 r 3
d * * r d
d # _ r Ρ
Ρ _ 3 r Ξ
e * * r e
e 4 _ r e
e 2 _ r e
e # _ r Σ
Σ _ 4 r 3
ƒ * * r ƒ
ƒ # _ r Τ
Τ _ 5 r 3
g * * r g
g # _ r Υ
Υ _ 6 r Ξ
h * * r h
h 7 _ r h
h 2 _ r h
h # _ r Φ
Φ _ 7 r 3
ï * * r ï
ï # _ r Χ
Χ _ 8 r 3
j * * r j
j # _ r Ψ
Ψ _ 9 r Ξ
k * * r k
k 3 _ r k
k # _ r 4
4 _ 4 r #
Ω _ 4 r F
l * * r l
l # _ r ¤
¤ _ 1 r 4
m * * r m
m # _ r ¥
¥ _ 2 r Ω
n * * r n
n 3 _ r n
n # _ r ¦
¦ _ 3 r 4
o * * r o
o # _ r ¨
¨ _ 4 r 4
p * * r p
p # _ r ©
© _ 5 r Ω
q * * r q
q 6 _ r q
q 3 _ r q
q # _ r ª
ª _ 6 r 4
r * * r r
r # _ r «
« _ 7 r 4
s * * r s
s # _ r ®
® _ 8 r Ω
t * * r t
t 9 _ r t
t 3 _ r t
t # _ r °
° _ 9 r 4
ü * * r ü
ü # _ r ±
± _ 5 r B
v * * r v
v # _ r ²
² _ 1 r ³
³ _ 5 r Ƒ
5 _ 5 r #
w * * r w
w 2 _ r w
w 4 _ r w
w # _ r ¶
¶ _ 2 r ±
x * * r x
x # _ r ·
· _ 3 r ±
y * * r y
y # _ r ¸
¸ _ 4 r ³
ž * * r ž
ž 5 _ r ž
ž 4 _ r ž
ž # _ r ¹
¹ _ 5 r ±
A * * r A
A # _ r »
» _ 6 r ±
Ɓ * * r Ɓ
Ɓ # _ r ¼
¼ _ 7 r ³
C * * r C
C 8 _ r C
C 4 _ r C
C # _ r ½
½ _ 8 r ±
D * * r D
D # _ r ¾
¾ _ 9 r ±
E * * r E
E # _ r ¿
E 5 _ r E
¿ _ 6 r F
6 _ 6 r #
Ϝ * * r Ϝ
Ϝ 1 _ r Ϝ
Ϝ 5 _ r Ϝ
Ϝ # _ r À
À _ 1 r 6
G * * r G
G 2 _ r G
G 5 _ r G
G # _ r Á
Á _ 2 r 6
H * * r H
H 3 _ r H
H 5 _ r H
H # _ r Â
 _ 3 r ¿
I * * r I
I 4 _ r I
I 5 _ r I
I # _ r Ã
à _ 4 r 6
J * * r J
J 5 _ r J
J # _ r Ä
Ä _ 5 r 6
K * * r K
K 6 _ r K
K 5 _ r K
K # _ r Å
Å _ 6 r ¿
L * * r L
L 7 _ r L
L 5 _ r L
L # _ r Æ
Æ _ 7 r 6
M * * r M
M 8 _ r M
M 5 _ r M
M # _ r Ç
Ç _ 8 r 6
N * * r N
N 9 _ r N
N 5 _ r N
N # _ r È
È _ 9 r ¿
O * * r O
O 6 _ r O
O # _ r 7
7 _ 7 r #
É _ 7 r F
P * * r P
P # _ r Ê
Ê _ 1 r 7
Q * * r Q
Q # _ r Ë
Ë _ 2 r É
R * * r R
R 3 _ r R
R 6 _ r R
R # _ r Ì
Ì _ 3 r 7
S * * r S
S # _ r Í
Í _ 4 r 7
T * * r T
T # _ r Ï
Ï _ 5 r É
U * * r U
U 6 _ r U
U # _ r Ð
Ð _ 6 r 7
V * * r V
V # _ r Ñ
Ñ _ 7 r 7
W * * r W
W # _ r Ò
Ò _ 8 r É
X * * r X
X 9 _ r X
X 6 _ r X
X # _ r Ó
Ó _ 9 r 7
Y * * r Y
Y # _ r 8
8 _ 8 r #
Z * * r Z
Z # _ r Ô
Ô _ 1 r Õ
Õ _ 8 r F
α * * r α
α 2 _ r α
α 7 _ r α
α # _ r Ö
Ö _ 2 r 8
β * * r β
β # _ r ×
× _ 3 r 8
γ * * r γ
γ # _ r Ø
Ø _ 4 r Õ
δ * * r δ
δ 5 _ r δ
δ 7 _ r δ
δ # _ r Ù
Ù _ 5 r 8
ε * * r ε
ε # _ r Ú
Ú _ 6 r 8
ζ * * r ζ
ζ # _ r Û
Û _ 7 r Õ
η * * r η
η 8 _ r η
η 7 _ r η
η # _ r Ü
Ü _ 8 r 8
θ * * r θ
θ # _ r Ý
Ý _ 9 r 8
ι * * r ι
ι # _ r Ā
Ā _ 9 r F
9 _ 9 r #
κ * * r κ
κ 1 _ r κ
κ 8 _ r κ
κ # _ r Ă
Ă _ 1 r 9
λ * * r λ
λ # _ r Ą
Ą _ 2 r 9
μ * * r μ
μ # _ r Ć
Ć _ 3 r Ā
ν * * r ν
ν 4 _ r ν
ν 8 _ r ν
ν # _ r Ĉ
Ĉ _ 4 r 9
ξ * * r ξ
ξ # _ r Ċ
Ċ _ 5 r 9
ο * * r ο
ο # _ r Đ
Đ _ 6 r Ā
π * * r π
π 7 _ r π
π 8 _ r π
π # _ r Ē
Ē _ 7 r 9
ρ * * r ρ
ρ # _ r Ĕ
Ĕ _ 8 r 9
ς * * r ς
ς # _ r Ė
Ė _ 9 r Ā
Č _ 0 r #
σ * * r σ
σ # _ r Ę
σ 9 _ r σ
Ę _ 1 r Ď
Ď _ 0 r B
τ * * r τ
τ # _ r Ě
Ě _ 2 r Ď
υ * * r υ
υ # _ r Ĝ
Ĝ _ 3 r Ğ
Ğ _ 0 r Ƒ
φ * * r φ
φ 3 _ r φ
φ 9 _ r φ
φ # _ r Ġ
Ġ _ 4 r Ď
χ * * r χ
χ # _ r Ģ
Ģ _ 5 r Ď
ψ * * r ψ
ψ # _ r Ĥ
Ĥ _ 6 r Ğ
ω * * r ω
ω # _ r Ħ
ω 6 _ r ω
ω 9 _ r ω
Ħ _ 7 r Ď
Α * * r Α
Α # _ r Ĩ
Ĩ _ 8 r Ď
Β * * r Β
Β # _ r Ī
Ī _ 9 r Ğ
Γ * * r Γ
Γ 9 _ r Γ
Γ # _ r Ĭ
Ĭ _ B r Į
Į _ u r İ
İ _ z r IJ
IJ _ z r halt
Ĵ _ 1 r #
Ķ _ 1 r F
¬ * * r ¬
¬ 1 _ r ¬
¬ 0 _ r ¬
¬ # _ r Ĺ
Ĺ _ 1 r Ĵ
- * * r -
- 2 _ r -
- 0 _ r -
- # _ r Ļ
Ļ _ 2 r Ķ
= * * r =
= 3 _ r =
= 0 _ r =
= # _ r Ľ
Ľ _ 3 r Ĵ
+ * * r +
+ 4 _ r +
+ 0 _ r +
+ # _ r Ŀ
Ŀ _ 4 r Ĵ
{ * * r {
{ 5 _ r {
{ 0 _ r {
{ # _ r Ł
Ł _ 5 r Ķ
} * * r }
} 6 _ r }
} 0 _ r }
} # _ r Ń
Ń _ 6 r Ĵ
[ * * r [
[ 7 _ r [
[ 0 _ r [
[ # _ r Ň
Ň _ 7 r Ĵ
] * * r ]
] 8 _ r ]
] 0 _ r ]
] # _ r Ņ
Ņ _ 8 r Ķ
: * * r :
: 9 _ r :
: 0 _ r :
: # _ r Ŋ
Ŋ _ 9 r Ĵ
F _ F r i
i _ i r ȥ
ȥ _ z r ź
ź _ z r #
Ƒ _ F r í
í _ i r ż
ż _ z r ƶ
ƶ _ z r B
B _ B r u
u _ u r z
z _ z r ź
M4, 115 bytes
Also TIL that ifelse can have more than four arguments.
define(f,`ifelse($1,101,,`ifelse(eval($1%15),0,fizzbuzz,eval($1%5),0,buzz,eval($1%3),0,fizz,$1)
f(incr($1))')')f(1)
M4, 143 bytes, SUSv2-compatible.
define(f,`ifelse(`$1',101,,`g(`$1',ifelse(eval($1%3),0,fizz)`'ifelse(eval($1%5),0,buzz))
f(incr($1))')')define(g,`ifelse(len($2),0,$1,$2)')f(1)
I am not familiar with M4, but I tried some bests. What quotations can be removed?
With comments
dnl def f(n): return "" if n==101 else g(n,("fizz" if n%3==0 else "")+("buzz" if n%5==0 else "")+"\n"+f(n+1))
define(f,`ifelse(`$1',101,`',`g(`$1',ifelse(eval($1%3),0,fizz)`'ifelse(eval($1%5),0,buzz))
f(incr($1))')')dnl
dnl def g(n,s): return n if len(s)==0 else n
define(g,`ifelse(len($2),0,$1,$2)')dnl
f(1)
C#, 95 91 bytes
for(int x=0;x++<100;)System.Console.WriteLine((x%3<1?"Fizz":"")+(x%5<1?"Buzz":x%3<1?"":x));
I do not take credit for this solution. I merged two solutions together:
- C#, 97 bytes from mattnewport using the new C# 9 top level statements.
C# using LINQ, 186 from Bill Tür using old fashioned C# but with Linq.- Java, 130 bytes from Geobits which he actually coded in java, but part of it works in C# too.
This solution requires C# 9, but does not use Linq.
Excel, 82 79 Bytes
=LET(x,ROW(1:100),a,IF(MOD(x,3),"","Fizz")&IF(MOD(x,5),"","Buzz"),IF(a="",x,a))
This wasn't valid when the question was asked.
Stax, 21 bytes
åS╬╕▌≡º$)ö;▀├Xè¶XΔ£≈♀
Not sure why recursive's solution from the tutorial hasn't been posted here yet. Probably the most minimal fizzbuzz possible in stax.
Deadfish~, 3299 bytes
{iiiii}dc{dddd}ic{iiii}c{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iic{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiic{dddd}dddddc{iiii}iiiiiic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}dcc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}dciic{dddd}dc{iiii}dciiic{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}dciiiiic{dddd}ddddc{iiii}dciiiiiic{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}dc{i}ddc{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}cc{dddd}c{iiii}cic{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}ciiiic{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}ciiiiiic{dddd}ddddddc{iiii}c{i}dddc{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}icddc{dddd}ic{iiii}icdc{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}icic{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iciiiic{dddd}dddddc{iiii}iciiiiic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iicdddc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iicdc{dddd}dc{iiii}iicc{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiciic{dddd}ddddc{iiii}iiciiic{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiciiiiic{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiicdddc{dddd}c{iiii}iiicddc{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiicic{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiciiic{dddd}ddddddc{iiii}iiiciiiic{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiicdddddc{dddd}ic{iiii}iiiicddddc{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiicddc{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiicic{dddd}dddddc{iiii}iiiiciic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiicddddddc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiicddddc{dddd}dc{iiii}iiiiicdddc{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiicdc{dddd}ddddc{iiii}iiiiicc{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiciic{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiicddddddc{dddd}c{iiii}iiiiiicdddddc{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiiicddc{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiicc{dddd}ddddddc{iiii}iiiiiicic{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiiii}dddc{d}iic{dddd}ic{iiiii}dddc{d}iiic{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}dddcdddddc{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}dddcddc{dddd}dddddc{iiiii}dddcdc{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc
Oof.
Pxem, Filename: 96 81 bytes + Content: 0 bytes = 96 81 bytes.
Thanks, Neil, for providing a workaround for -15 bytes!
- Filename (some are escaped):
\020.z.t.m\005.%\001.yXXbuzz.a.m\003.%\001.yXXfizz.a.c.c.z.m\017.-.nXX@.a.c@.z.pXX.a.s\n.o.m\001.+.ct.a - Content: empty.
Try it online! (with pxem.posixism)
With comments
XX.z
.a\020.zXX.z # push 16; while :; do
.a.tXX.z # heap = pop!
.a.m\005.%\001.yXXbuzz.aXX.z # while 1>heap%5; do push "buzz"; break; done
.a.m\003.%\001.yXXfizz.aXX.z # while 1>heap%3; do push "fizz"; break; done
.a.c.c.z.m\017.-.nXX@.aXX.z # if empty?; then print(heap-15); push "@"; fi
# this is how while empty?; do something; done works:
# ".c.c.z bla bla bla .a"
# NOTE: Fail on pxemi dot 7z and RPxem
# They need some patches before installing
# Implementation needs to be document-compliant
# PS. RPxem v0.0.7 fixed dotC
.a.c@.z.pXX.aXX.z # if top!="@"; then print pop all!; fi
.a.sXX.z # pop!
.a\n.oXX.z # print "\n"
.a.m\001.+XX.z # push heap; add one to it
.a.ct.aXX.z # break if equal to 116
.a
Note
- In Pxem, unlike other stack-based languages, subtraction and division does NOT rely on positions of two items;
.-doespush(abs(pop-pop)),.$and.%stand forx=pop; y=pop; push(int(x>y?x/y:y/x))andx=pop; y=pop; push(int(x>y?x%y:y%x))respectively. Thus, when you try to do something like13/17or13%17, you need to check which are greater first. - To avoid the specification, the program loops from 16 to 115.
Old version
Kotlin, 95 bytes
fun main(){(1..100).map{i->println(when(0){i%15->"FizzBuzz";i%3->"Fizz";i%5->"Buzz";else->i})}}
Factor, 145 142 122 bytes
As usual, @Bubbler nailed it. Go upvote one of his answers!
100 [1,b] [ dup [ 3 mod 0 = dup [ "Fizz"write ] when ] [ 5 mod 0 = dup [ "Buzz"write ] when ] bi or [ nl ] [ . ] if ] each
Old version:
1 [ dup 100 > ] [ dup [ 3 mod 0 = dup [ "Fizz"write ] when ] [ 5 mod 0 = dup [ "Buzz"write ] when ] bi or [ ""print ] [ dup . ] if 1 + ] until
Amazingly, until now no one posted a Factor answer. It is not really golfed much, probably can be improved.
Excel VBA, 81 Bytes
Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window.
For i=1To 100:o=IIf(i Mod 3,"","Fizz")+IIf(i Mod 5,"","Buzz"):?IIf(o="",i,o):Next
Ungolfed
For i=1To 100 '' iterate from 1 to 100
o=IIf(i Mod 3,"","Fizz") '' set the out var to `Fizz` if i Mod 3 = 0, else empty
+IIf(i Mod 5,"","Buzz") '' append `Buzz` to out var if i Mod 5 = 0
?IIf(o="",i,o) '' If out var is non-empty, output the out var
'' else output i
Next
Worksheet Version, 95 Bytes
Anonymous VBE immediate window function that takes no input and outputs to the range [A1:A100]
[A1]="=Let(r,Row(1:100),s,If(Mod(r,3),"""",""FIZZ"")&If(Mod(r,5),"""",""BUZZ""),If(s="""",r,s))
CSASM v2.1.2.1, 325 bytes
func main:
push 1
pop $a
.lbl a
clf.o
push $a
push 15
rem
push 0
comp
push $f.o
brtrue e
push $a
push 3
rem
push 0
comp
push $f.o
brtrue b
push $a
push 5
rem
push 0
comp
push $f.o
brtrue d
push $a
print.n
br c
.lbl b
push "Fizz"
print.n
br c
.lbl d
push "Buzz"
print.n
br c
.lbl e
push "FizzBuzz"
print.n
.lbl c
clf.o
inc $a
push $a
push 101
comp
push $f.o
brfalse a
ret
end
Commented and Ungolfed:
func main:
; Initilize the counter in the accumulator
push 1
pop $a
.lbl loop
; Reset the Comparison flag
clf.o
; $a % 15 == 0
push $a
push 15
rem
push 0
comp
; Jump to label "printFizzBuzz" if the Comparison flag is true
push $f.o
brtrue printFizzBuzz
; $a % 3 == 0
push $a
push 3
rem
push 0
comp
; Jump to label "printFizz" if the Comparison flag is true
push $f.o
brtrue printFizz
; $a % 5 == 0
push $a
push 5
rem
push 0
comp
; Jump to label "printBuzz" if the Comparison flag is true
push $f.o
brtrue printBuzz
; None of the above were true. Just print the number itself
push $a
print.n
br checkCounter
.lbl printFizz
; Print "Fizz"
push "Fizz"
print.n
br checkCounter
.lbl printBuzz
; Print "Buzz"
push "Buzz"
print.n
br checkCounter
.lbl printFizzBuzz
; Print "FizzBuzz"
push "FizzBuzz"
print.n
.lbl checkCounter
; Clear the Comparison flag
clf.o
inc $a
; $a == 101
push $a
push 101
comp
push $f.o
; Keep looping until the above is false
brfalse loop
ret
end
```
Dash, with these restrictions
- with SUSv2-compatible utilities
- no built-in loops, no built-in branches, no variables
- 1 pipeline
- no awk
- no LF in pattern space in sed
- no hold space in sed
Dash, 103 bytes, 5 utilities.
echo ,,fizz,,buzz,fizz,,,fizz,buzz,,fizz,,,fizzbuzz|sed -n ':x
p
bx'|tr , \\n|sed '/./b
=
d'|head -n100
Dash, 124 121 bytes, 9 utilities.
echo xx|sed -n ':x
p
bx'|sed s/\$/fizz/|tr x \\n|paste - - - - -|sed s/\$/buzz/|tr \\t \\n|sed -n '/./p
/^$/='|head -n100
Dash, 133 132 bytes, 10 utilities.
echo|sed -n ':x
p
bx'|paste - - -|sed s/\$/fizz/|tr \\t \\n|paste - - - - -|sed s/\$/buzz/|tr \\t \\n|sed -n '/./p
/^$/='|head -n100
With comments
echo | sed -n '
:x
p
bx
' | # yes ''
paste - - - | sed s/\$/fizz/ | tr \\t \\n | # if NR%3==0; then $0="fizz";
paste - - - - - | sed s/\$/buzz/ | tr \\t \\n | # if NR%5==0; then $0=$0 "buzz";
sed -n '
/./p
/^$/=' | # = is to output line number
head -n 100
sed 4.2.2 -r, 94 bytes
G
:
s/\n.?$/&0&1&2&3&4&5&6&7&8&9/m
t
s/\w.{8}/&Fizz /g
G
s/ *\w[05]|$/Buzz/2g
s/^0*\n*| .*//mg
This is my old solution from anarchy golf, minus 5 backslashes gained by -r.
The loop generates 00 to 99 preceded by newlines. Next, we prepend Fizz to lines 03, 06, ... taking advantage of the fact that the entry points are all separated by 9 characters. Then we handle instances of Buzz by looking for suffix of 0 or 5, plus an empty line to stand in for 100, and skipping the first match 00. The last line cleans up the garbage on the ends of Fizz-but-not-Buzz lines along with leading 0s and the first two lines.
Note: The behavior of mixing 2 and g flags in s is unspecified by POSIX but well-defined in GNU sed.
sed 4.2.2 (no -r), 98 bytes (based on a solution by tails)
s/\S\?/ 123456789/
s//&1 &2 &3 &4 Buzz &6 &7 &8 &9 Buzz /g
s/\([1 ]\S* .\S* \)[0-9]*/\1Fizz/g
L0
d
Using a quite different approach, this solution wins by 1 byte when -r is not used. Thanks to @tails for sharing this approach with me!
The first two lines generate 1 to 100 separated by spaces with suitable Buzz replacements, along with an extra residual space before 11. To match for Fizz replacements, special care is needed to skip Buzz in multiples of 15 without skipping Buzz in 3k + 1 spots. We can do this by starting the pattern with a space, except that this does not work for the very first match, so [1 ] is used instead. The . in line 3 compensates for the extra space before 11, which is masked in the final output by L0.
L is a GNU-specific line formatting command that was "considered a failed experiment" and removed in later versions of sed.
C#, 97 bytes
for(int x=0;x++<100;)System.Console.WriteLine(x%3*x%5>0?x+"":"FizzBuzz"[x%5>0?..4:x%3>0?4..:..]);
Requires C# 9 for top level statements and range syntax.
Burlesque, 72 bytes
,1 100r@{JJ3.%0=="Fizz"j.*j5.%0=="Buzz"j.***Jr&0=={vv}j{jvv}jie}m[\[Sush
Do you see that at the end? Sus?!? Does that mean this program is the impostor!!!
This is why I need to stop fizzbuzzing at 10pm at night. I'll explain this tomorrow if I remember how it works.
Retina, 47 bytes
100*
L$`_
$.>`
4,5,m`^
Buz
2,3,m`^
Fiz
z\d*
zz
Try it online! Explanation: Much simpler than @MartinEnder's approach, although I did copy his zz trick to save two bytes.
100*
L$`_
$.>`
List the numbers from 1 to 100.
4,5,m`^
Buz
Prefix Buz to every fifth number.
2,3,m`^
Fiz
Prefix Fiz to every third number.
z\d*
zz
Double the zs, and also delete the number after Fizz or Buzz.
jq, 45 bytes
range(100)+1|(1-.%3)*"fizz"+(1-.%5)*"buzz"//.
# explanation
range(100)+1| # for each number in range 0-99 + 1
. % 3 ) # the current number modulo 3
( 1 - # the important thing is this gives 1 for 0 and an invalid
# number (0 or negative) for any positive number
*"fizz"# "fizz" repeated that many times. For a negative or 0 number
# this returns null
+ ..."buzz" # concatenated with the same thing but for buzz.
# null + anything is that thing, so for a number not divisible by
# 3 or 5 this returns null
// . # if the result is null, the number itself
# implicit output
For best results run with jq -rn '...' | less.
///, 235 bytes
/(/\/\///%/111()/\\\\(p/1\/(x/%%%1(t/xxxxxxxxxx(>p^=)=^!)=$)vvt&@
^^!)=^=)=^^$v)v^|^^v)v1^v)av^^v)av^v)v^>(^/\(/>(>t/%&/&%(1&/1(%11@/@%11(1@/1(&p&(@p@(&/Fizz(@/Buzz(|p001(|(/0x/1\0(0p_1(0_/_(1p2(22/4(42/6(44/8(2p3(4p5(6p7(8p9(_(/=\=(==
There is already a /// answer, but it is pretty boring. I thought I would try to make a more algorithmic one, even though it is a little longer ;)
Ungolfed: Try it online!
JavaScript: 76 bytes
for(i=1;i<101;i++)console.log(i%3<1?'fizz'+(i%5<1?'buzz':''):i%5<1?'buzz':i)
Not the best solution we have, but not the worst either...
The "nested" ternary operator adds either buzz or nothing to the fizz part depending on the results of the divisibility test.
GNU sed 4.2.2, 126 bytes
This answer is in response to the bounty offered by @user41805 to golf further his sed script for this challenge.
s/^/@@,/;h
:
y/@123456789';,/123456789@;,'/
/@.$/!{x;G;s/..\n.//}
h
s/[@5].$/&Buzz/
s/.*,/Fizz/
s/.*\WB/B/
s/\W*//gp
g;/@@/d
t
The trick was to notice that no '0' will be printed, so I replaced it with '@' to be able at line 9 to refer to the extra characters [0';] as \W, thus shaving 3 bytes. Please check his description on how the code works.
Java 94 92 91 Bytes (loop without class declaration or main function) by Alex North
small optimizations by Alexander Lemieux
first the fully golfed/optimized code (the best I could do)
for(int i=0;i++<100;System.out.println(i%3<1|i%5<1?(i%3<1?"fizz":"")+(i%5<1?"buzz":""):i));
for reference here is what he posted to wiki.c2 (exactly copied and pasted from there)
for(int i = 0; i < 100; i++, System.out.println(i % 3 == 0 || i % 5 == 0 ? ((i % 3) == 0 ? "fizz" : "")
first I removed all of the spaces and changed the logical "or" to a bitwise "or" (changed || to |)
for(int i=0;i<100;i++,System.out.println(i%3==0|i%5==0?((i%3)==0?"fizz":"")+((i%5)==0?"buzz":""):i));
then I changed i%3==0 and i%5==0 to i%3<1 and i%5<1 ( I also removed unnecessary parenthesis),
for(int i=0;i<100;i++,System.out.println(i%3<1|i%5<1?(i%3<1?"Fizz":"")+(i%5<1?"Buzz":""):i));
lastly, I changed the loop from
(int i=0;i<100;i++)
to
(int i=0;i++<100;)
how it works
for(int i=0;i++<100;
regular java for loop
System.out.println(
print statement
(i%3<1|i%5<1?(i%3<1?"Fizz":"")+(i%5<1?"Buzz":""):i));
this is a little more complicated, it's roughly equivalent to the pseudo code:
if i is evenly divisible by 3 or 5 then if i is evenly divisible by 3 then "Fizz" + if i is evenly divisible 5 then "Buzz" else i
hope that wasn't too confusing.
THIS IS NOT MY CODE, I JUST CHANGED A FEW CHARACTERS, ALL CREDIT SHOULD GO TO ALEX NORTH!
my current best for FizzBuzz using java is 94 characters that can be found here I did this because I thought his code deserved to be shown off because it is a smart solution.
ThumbGolf, 49 bytes
Machine code (little endian pairs):
2100 3101 0008 dec0 d003 b908 a303 de03
004a de6a b922 a305 de03 e003 6946 7a7a
b100 de21 de3a 2964 d1eb 4770 7542 7a7a
00
Commented assembly:
// Include the ThumbGolf wrapper macros
.include "thumbgolf.inc"
.globl main
.thumb_func
main:
// Start the counter with zero and increment first.
// It aligns better than incrementing at the bottom.
movs r1, #0
.Lloop:
adds r1, #1
.Lthree:
// r0 = r1 % 3
movs r0, r1
umodi r0, 3 // udf #0300; .short 0xd003
// if r0 == 0
cbnz r0, .Lten
// if so print "Fizz"
adr r3, .Lfizz
puts r3 // udf #0003
.Lten:
// do the same for Buzz
// r2 = (r1 * 2) % 10, a.k.a. r1 % 5
// we do this because umod.10 is a special narrow instruction :)
lsls r2, r1, #1
umod.10 r2 // udf #0152
cbnz r2, .Lnum
adr r3, .Lbuzz
puts r3 // udf #0003
// jump to the newline
b .Lnoprint
// Normally, "Fizz" and "Buzz" are 5 byte strings due to the null
// terminator, which SUCKS. This is because Thumb instructions MUST
// be 2 byte aligned, and pool loads that are not 4 byte aligned are
// annoying wide instructions.
//
// However, I have a trick up my sleeve.
//
// CBZ is encoded as so:
// |15 14 13 12|11|10| 9| 8| 7 6 5 4 3 |2 1 0|
// | 1 0 1 1| 0| 0| i| 1| imm5 | Rn |
// Let's focus on bits 0-7, which, since ARM is little endian, appear
// first.
//
// imm5 is the offset in opcodes relative to 4 bytes after the current
// instruction (a.k.a. where the PC is for dumb reasons). Technically,
// there is a 6th bit in bit 9, but that is only for larger offsets.
//
// .Lnoprint is exactly 4 bytes after the instruction, so the offset
// is zero:
// 0 0 0 0 0 r r r
// Now, for the register argument, if we set it to r0...
// 0 0 0 0 0 0 0 0
// Behold. A free null terminator.
//
// This is great, as it not only lets us cheat a byte in Fizz, but also,
// it makes everything align perfectly so we don't need any wide adr
// instructions. We can just put Buzz at the bottom of the file and it
// will be 4 byte aligned as well.
.Lfizz:
.ascii "Fizz" // null terminated by cbz encoding
.Lnum:
// was r1 % 3 not zero (meaning did we not print Fizz?)
cbz r0, .Lnoprint
// if so, print r1 as an integer
puti r1 // udf #0041
.Lnoprint:
// putspc is a narrow instruction that prints one of 8 special characters,
// one of which includes \n.
putspc '\n' // udf #0072
// loop while r1 != 100
// replace with a register for variable length
cmp r1, #100
bne .Lloop
// return
bx lr
.Lbuzz:
.asciz "Buzz"
My second submission in my brand new WIP ThumbGolf language, an ISA extension to Thumb-2.
It shows off both the new I/O instructions and the modulo instructions (with the special narrow encoding for 10).
That little hack by null terminating with cbz saves a lot, and it was really fun to figure out.
As mentioned in my cat program, this can be run on ARM Linux or QEMU by linking the ThumbGolf runtime. I don't have an online interpreter yet (and I doubt I could afford hosting one lul)
Java, 100 98 95 94 Bytes (only loop, full code is 136 bytes, see bottom)
for(int i=0;i++<100;){var s=i%3<1?"Fizz":"";s=i%5<1?s+"Buzz":s;System.out.println(s==""?i:s);}
Try it here. Probably could be a lot smaller. I just started to learn java a few days ago (although I do have experience in other languages), this is the best I can do. Breakdown of how it works. Sorry if I get some terms wrong or explain stuff poorly:
for(int i=0;i++<100;)
Just the loop - starts at 1 goes to 100:
{var s=i%3<1?"Fizz":"";
Making a variable called "s", equal to a value, if "i" is divisible by 3 with a remainder of less than 1 (1 character/byte smaller than checking ==0), set "s" equal to "buzz". If it isn't, set it equal to "".
s=i%5<1?s+"Buzz":s;
Set s equal to a value: if i is divisible by 5 with a remainder of less than 1, set s equal to s + "buzz", if it isn't, set it equal to itself.
System.out.println(s==""?i:s);}
System.out.println is just a simple print statement. Inside it, check if s is equal to "" (if s wasn't divisible by 3 or 5, it would be "") print i (the number), otherwise print s.
Feedback is greatly appreciated. Edit: 94 bytes for just the loop, below is what I think the full script would be, 136 bytes : (
interface f{static void main(String[]a){for(int i=0;i++<100;){var s=i%3<1?"Fizz":"";s=i%5<1?s+"Buzz":s;System.out.println(s==""?i:s);}}}
Whispers v2, 150 bytes
> 100
>> (1]
> "Fizz"
> "Buzz"
>> 3+4
> 0
>> Then 5 6 6 3 6 4 3 6 6 3 4 6 3 6 6
>> 7ⁿR
>> Each 8 2
>> L∨R
>> Each 10 9 2
>> Output L
>> Each 12 11
Maybe it could be improved, but programming in Whispers is driving me crazy. I'm starting to hear voices...whispering...in my head
Explanation
In Whispers, numbers in lines beginning with >> refer to line numbers. Here is what each line is computing:
> 100 1:100
>> (1] 2:[1,2,...,100]
> "Fizz" 3:"Fizz"
> "Buzz" 4:"Buzz"
>> 3+4 5:"FizzBuzz"
> 0 6:0
>> Then 5 6 6 3 6 4 3 6 6 3 4 6 3 6 6 7:["FizzBuzz",0,0,"Fizz",0,"Buzz","Fizz"...]
(FizzBuzz without numbers for values 0 to 15)
>> 7ⁿR 8:Modular indexing function into the previous array
>> Each 8 2 9:[0,0,"Fizz",0,"Buzz","Fizz",...]
(FizzBuzz without numbers for values 1 to 100)
>> L∨R 10:OR function
>> Each 10 9 2 11:Zip with OR the arrays in lines 9 and 2
(Complete list of FizzBuzz values)
>> Output L 12:Print function
>> Each 12 11 13:Print each value in line 11
JavaScript, 69 68 bytes
-1 byte: inspired by this answer
for(i=0;++i<101;)console.log(i%3?i%5?i:"Buzz":i%5?"Fizz":"FizzBuzz")
In a readable form:
for (i = 0; ++i < 101; ) { // iterates from 1 to 100
console.log(
i % 3 != 0
? i % 5 != 0 // if i is not divisible by 3 ...
? i // ... and not divisible by 5, print i
: "Buzz" // ... but divisible by 5, print Buzz
: i % 5 != 0 // if i is divisible by 3 ...
? "Fizz" // ... but not divisible by 5, print Fizz
: "FizzBuzz" // ... and divisible by 5, print FizzBuzz
)
}
Omit all != 0 comparison and unnecessary whitespaces.
Myddin, 157 bytes
use std
var p=std.put
const main={
for var i=1;i<101;i++
match(i%3,i%5)
|(0,0):p("FizzBuzz\n")
|(0,_):p("Fizz\n")
|(_,0):p("Buzz\n")
|(_,_):p("{}\n",i)
;;;;}
Javascript, 99 bytes
This isn't a good, or small solution, but it works:
for(let i=1;i<101;i++){console.log((i%3==0&&i%5==0)?"FizzBuzz":(i%3==0)?"Fizz":(i%5==0)?"Buzz":i);}
Explanation:
for (let i=1;i<101;i++) // Loop through, until reaching 100
{
console.log(
(i%3==0 // If I is a multiple of 3
&& // And
i%5==0 // If I is a multiple of 5
)?"FizzBuzz": // Print "FizzBuzzz"
(i%3==0)?"Fizz": // If I isn't either of those, check whether I is a multiple of 3, if so, print "Fizz"
(i%5==0)?"Buzz" // If I isn't a multiple of 3, check whether I is a multiple of 5, if so, print "Buzz"
:i // Else, just print i
);
}
Mouse-83/Mouse-2002, 73 bytes
1F:(F.Z4*1+<^0A:F.3\0=["Fizz"1A:]F.5\0=["Buzz"A.1+A:]A.0=[F.!]"!"F.1+F:)$
Try it online! Yet another fizzbuzz. Polyglots both versions listed and beats the current answer. The funny thing is that I came up with this independently of the other answer and managed to use the same approach.
BRASCA, 81 bytes
1b1[x0aB:b3%0=[x`zziF`oooo1a0]xB:b5%0=[x`zzuB`oooo0A1+a]xA0=[xB:bn0]xB1+:bH1+<lo]
There'll be an explanation coming soon. The tio link is the interpreter split over the header and footer in such a way that the program can be entered into the code box.
GNU AWK, 1 input byte + 60 bytes = 61 bytes
An approach different from Cabbie407's, that golfed 2 bytes off thanks to the more flexible parsing of the GNU's implementation. Still needs one EOF input.
END{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}
END # starts after commanding the EOF (Ctrl+D).
{
for(;
++n<101; # the _n_ variable is started here on the conditional, at the value 1.
print i?i:n # in the end of each loop, prints _i_ if non-null, or _n_.
)
i=(n%3?e:"Fizz")(n%5?e:"Buzz")
# two ternary conditionals that concatenates Fizz and Buzz accordingly.
# by the way, _e_ is a not assigned variable, which will return a null string ("").
# if n != 0 (mod 15), then _i_ will return null at the print statement above.
}
For no input, use the BEGIN pattern instead (62 bytes total):
BEGIN{for(;++n<101;print i?i:n)i=(n%3?e:"Fizz")(n%5?e:"Buzz")}
Python 3, 88 85 77 73 bytes
i=0
exec("i+=1;print(i%3*i%5and i or(i%3<1)*'Fizz'+(i%5<1)*'Buzz');"*100)
Canvas, 31 bytes
A2^{w3%0≡Fizz×y5%0≡Buzz×+:?O]yO
Okay seriously guys why is it that both ascii-art focused languages didn't already have a FizzBuzz? This uses my favourite FizzBuzz approach found in the Vyxal answer.
FALSE, 86 bytes
[\100*\/$100$@\/*-0=]m:1[$100>~][0\$3m;![\%1\"Fizz"]?$5m;![\%1\"Buzz"]?\0=[$.]?10,1+]#
Explanation
[\100*\/$100$@\/*-0=]m: Define Modulo Function
[\100*\/ Divide number * 100 by the divisor to get decimals
$100$@/* Get truncated result
-0= Subtract to get decimal, if equal to 0, then the modulo is zero and return true. If not, return false as we don't care about the result
1 Put counter on stack
[$100>~] Check if number is greater than 100
[0\$3m;![\%1\"Fizz"]?$5m;![\%1\"Buzz"]?\0=[$.]?10,1+]# Do FizzBuzz if not
[0\ Number to see if both % 3 and % 5 failed
$3m;! Number % 3
[\%1\"Fizz"]? If yes, do what is in brackets
[\%1\ Set number to 1
"Fizz"]? Print Fizz
$5m;! Number % 5
[\%1\"Buzz"]? If yes, do what is in brackets
[\%1\ Set number to 1
"Buzz"]? Print Buzz
\0= Check if both modulo functions failed
[$.]? If yes, do what is in brackets
[$ Duplicate our counter so it doesn't get destroyed
.]? Print the counter
10, Print ASCII character 10 (line break)
1+]# Increment counter
Could most likely be way better.
uBASIC, 106 96 bytes
Improved syntax, and fixed a bug
0ForI=1To100:S$="":IfIMod3=0ThenS$="Fizz"
1IfIMod5=0ThenS$=S$+"Buzz"
2IfS$=""Then?I,
3?S$
4NextI
05AB1E, 37 bytes
т>GN3ÖUi"Fizz"?}N5ÖVi”ÒÖ”?}XY~_iN?}¶?
т>GN3ÖUi"Fizz"?}N5ÖVi”ÒÖ”?}XY~_iN?}¶? # full program
G # for N in [1, 2, ...,
т # ..., 99...
> # plus 1]...
i # if...
N # variable...
Ö # is divisible by...
3 # literal...
? # then output without trailing newline...
"Fizz" # literal
} # end if
i # if...
N # variable...
Ö # is divisible by...
5 # literal...
? # then output without trailing newline...
”ÒÖ” # "Buzz"
} # end if
i # if...
U V XY # N is...
_ # not...
U V XY # divisible by...
~ # either...
U X # 3...
~ # or...
V Y # 5...
? # then output without trailing newline...
N # variable
} # end if
? # output without trailing newline...
¶ # newline
# implicit end loop
Alternatively, you can replace ¶? with õ,: Try it online!
, # output with trailing newline...
õ # empty string
Japt -R, 27 bytes
Finally came up with a shorter way!
Lõ@"FiBu"ò úz4 ËpXv°EÑÄìªX
Lõ@"FiBu"ò úz4 ËpXv°EÑÄìªX
L :100
õ :Range [1,L]
@ :Map each X
"FiBu" : Literal string
ò : Partitions of length 2
úz4 : Right pad each with "z" to length 4
Ë : Map each element at 0-based index E
p : Repeat
Xv : Test X for divisibility by (result will be 1 or 0)
°E : Prefix increment E
Ñ : Multiply by 2
Ä : Add 1
à : End map
¬ : Join
ªX : Logical OR with X
:Implicit output, joined with newlines
Kakoune, 57 bytes
!seq 100
%s[05]$
Ab<esc>%s(\w+\n){3}
<a-h>s\d+
cFizz<esc>%s\d*b
cBuzz
Explanation:
!seq 100 Call the external sh command `seq 100`, insert the output (numbers 1-100)
d ! inserts a trailing newline, delete it
%s[05]$ Select all lines ending with 0 or 5, which is equivalent to being divisible by 5
Ab<esc> Append a b to these lines, signifying that they should be buzzed later on
%s(\d+b?\n){3} Select every third line
<a-h>s\d+ Select every third number (unselecting the b's)
cFizz<esc> Replace with Fizz
%s\d*b Select (including 0) digits followed by a b
cBuzz Replace with Buzz
Arn -hm, 27 22 18 bytes
─=█BƒHXåõÝü»ÝÑÕ=!&
Explained
Unpacked: "Fizz"^!%3|`#&`^!%5||
Set STDIN to the range [1, 100]
"Fizz" Literal string
^ Repeat
! NOT
_ Implied variable
% Modulo
3
| Concatenated with
`#&` Compressed string "Buzz"
^
!
_ Implied
%
5
|| OR
_ Implied
Mapped over STDIN with key`_
I wasn't going to update this, but might as well.
!@#$%^&*()_+, 378 bytes
No TIO link, since the language has been updated to include the = command.
^!!($!!!!(!_++_^^^_$_^_$!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_++!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_+++!!_+^_$+_)+!!_+^$!!_+$(+$_^_$!!_+)+!_++$!_++(zziF@@@@ &!_+%!_+)+!!(!_++_^^^^^_$_^_$!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_++!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_+++!!_+^_$+_)+!!_+^$!!_+$(+$_^_$!!_+)+!_++$!_++(zzuB@@@@ &!_+%!_+)+ &($!#$!_+)
@^%$!_++!d_+!!_+^$!!_+$(+$_^_$!!_+)+!_++!!_+^_$+_$^$)
There are unprintables in this code. Here's an xxd dump:
00000000: 5e21 2128 2421 2121 2128 215f 2b2b 5f5e ^!!($!!!!(!_++_^
00000010: 5e5e 5f24 5f5e 5f24 2121 5e5e 5f2b 3d21 ^^_$_^_$!!^^_+=!
00000020: 215f 2b5e 2421 215f 2b24 282b 245f 5e5f !_+^$!!_+$(+$_^_
00000030: 2421 215f 2b29 2b21 5f2b 2b21 215e 5e5f $!!_+)+!_++!!^^_
00000040: 2b3d 2121 5f2b 5e24 2121 5f2b 2428 2b24 +=!!_+^$!!_+$(+$
00000050: 5f5e 5f24 2121 5f2b 292b 215f 2b2b 2b21 _^_$!!_+)+!_+++!
00000060: 215f 2b5e 5f24 2b5f 292b 2121 5f2b 5e24 !_+^_$+_)+!!_+^$
00000070: 2121 5f2b 2428 2b24 5f5e 5f24 2121 5f2b !!_+$(+$_^_$!!_+
00000080: 292b 215f 2b2b 2421 5f2b 2b28 7a7a 6946 )+!_++$!_++(zziF
00000090: 4040 4040 0026 215f 2b25 215f 2b29 2b21 @@@@.&!_+%!_+)+!
000000a0: 2128 215f 2b2b 5f5e 5e5e 5e5e 5f24 5f5e !(!_++_^^^^^_$_^
000000b0: 5f24 2121 5e5e 5f2b 3d21 215f 2b5e 2421 _$!!^^_+=!!_+^$!
000000c0: 215f 2b24 282b 245f 5e5f 2421 215f 2b29 !_+$(+$_^_$!!_+)
000000d0: 2b21 5f2b 2b21 215e 5e5f 2b3d 2121 5f2b +!_++!!^^_+=!!_+
000000e0: 5e24 2121 5f2b 2428 2b24 5f5e 5f24 2121 ^$!!_+$(+$_^_$!!
000000f0: 5f2b 292b 215f 2b2b 2b21 215f 2b5e 5f24 _+)+!_+++!!_+^_$
00000100: 2b5f 292b 2121 5f2b 5e24 2121 5f2b 2428 +_)+!!_+^$!!_+$(
00000110: 2b24 5f5e 5f24 2121 5f2b 292b 215f 2b2b +$_^_$!!_+)+!_++
00000120: 2421 5f2b 2b28 7a7a 7542 4040 4040 0026 $!_++(zzuB@@@@.&
00000130: 215f 2b25 215f 2b29 2b00 2628 2421 2324 !_+%!_+)+.&($!#$
00000140: 215f 2b29 0a40 5e25 2421 5f2b 2b21 645f !_+).@^%$!_++!d_
00000150: 2b21 215f 2b5e 2421 215f 2b24 282b 245f +!!_+^$!!_+$(+$_
00000160: 5e5f 2421 215f 2b29 2b21 5f2b 2b21 215f ^_$!!_+)+!_++!!_
00000170: 2b5e 5f24 2b5f 245e 2429 +^_$+_$^$)
Alternatively, here's a version with no unprintables (387 bytes):
^!!($!!!!(!_++_^^^_$_^_$!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_++!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_+++!!_+^_$+_)+!!_+^$!!_+$(+$_^_$!!_+)+!_++$!_++(zziF@@@@!!_+&!_+%!_+)+!!(!_++_^^^^^_$_^_$!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_++!!^^_+=!!_+^$!!_+$(+$_^_$!!_+)+!_+++!!_+^_$+_)+!!_+^$!!_+$(+$_^_$!!_+)+!_++$!_++(zzuB@@@@!!_+&!_+%!_+)+!!_+&($!#$!_+)
@^%$!_++!d_+!!_+^$!!_+$(+$_^_$!!_+)+!_++!!_+^_$+_$^$)
Notes
There's likely still room for golfing. I decided to approach this by manually calculating mod 3 and mod 5 for each integer from 1 to 100, whereas an approach by maintaining separate counters for mod 3 and mod 5 might save tons of bytes. This was more of a proof of concept.
I made this snippet using a templating language of my own creation, which I will publish at some point. Here's the metaprogram:
;let ~ !!_+^$!!_+$(+$_^_$!!_+)+!_++
;let DROP !_++
;let omx !!_+^_$+_
^
!!
(
$
!!
!!(
DROP
_ 3{^} _
$ _ 1{^} _
$
-2=~-2=~+ omx
)+~$DROP
(
@"Fizz"
0&!_+%
!_+
)+
!!(
DROP
_ 5{^} _
$ _ 1{^} _
$
-2=~-2=~+ omx
)+
~$DROP
(
@"Buzz"
0&!_+%
!_+
)+
0& ($!#$!_+)
10@
^%
$ DROP !
-100 +~omx
$^$
)
LolCode, 392 383 353 bytes
This LolCode follows the 1.3 standard used by the lci interpreter.
Unfortunately, no online interpreter.
Not the best language to golf with, but it's fun!
Update 1: changed for loop to while loop
Update 2: removed newlines in favor of commas (soft command break)
HAI 1.3,CAN HAS STDIO?,I HAS A v ITZ 1,IM IN YR s,BOTH SAEM 0 AN MOD OF v AN 15,O RLY?,YA RLY,VISIBLE "FizzBuzz",NO WAI,BOTH SAEM 0 AN MOD OF v AN 3,O RLY?,YA RLY,VISIBLE "Fizz",NO WAI,BOTH SAEM 0 AN MOD OF v AN 5,O RLY?,YA RLY,VISIBLE "Buzz",NO WAI,VISIBLE v,OIC,OIC,OIC,BOTH SAEM v AN 100,O RLY?,YA RLY,GTFO,OIC,v R SUM OF v AN 1,IM OUTTA YR s,KTHXBYE
Forth (gforth), 95 bytes
: f 'e 1 DO 1 i 3 mod 0= if ." Fizz"0 then i 5 mod 0= if ." Buzz"0 then if i . then cr LOOP ; f
With help from @Bubbler, it's shorter than the other forth answer. Explanation coming soon.
AppleSoft BASIC, 112 bytes
0A$(1)="FIZZ":A$(2)="BUZZ":A$(3)="FIZZBUZZ":FORN=1TO100:A$(0)=STR$(N):?A$((N/3=INT(N/3))+(N/5=INT(N/5))*2):NEXT
Verified on https://www.calormen.com/jsbasic/
Spaghetti, 522 bytes
main:0"n"goto store goto l l:100"n"goto retrieve goto areEqual"EOF"goto jumpIfTrue"n"goto retrieve 1 2 goto add"n"goto store 15"n"goto retrieve 2 goto modulus 0 goto areEqual"f"goto jumpIfTrue 3"n"goto retrieve 2 goto modulus 0 goto areNotEqual"b"goto jumpIfTrue"Fizz"1 goto print goto b t:3"n"goto retrieve 2 goto modulus 0 goto areEqual"l"goto jumpIfTrue"n"goto retrieve 1 goto print goto l b:5"n"goto retrieve 2 goto modulus 0 goto areNotEqual"t"goto jumpIfTrue"Buzz"1 goto print goto l f:"FizzBuzz"1 goto print goto l
Requires a newline at the end, cause otherwise the interpreter throws a hissy fit.
Spaghetti is a stack based language that promotes using goto extensively. That means, every single operation you use requires a goto statement along with it.
That being said, this took a while.
Commented version is at the Spaghetti examples.
Try it on the online interpreter! (Code must be pasted in)
><>, 59 bytes
0v!oo:oo"Fiz"\
1<oan?*/!?%5$\!?%3;?)*aa::::::+
o"Buzz"/$0oo
Prints a trailing newline
How it works
0v...
.<... Initialises the stack with 0
.....
.....
1<................;?)*aa::::::+ Increment the counter and duplicate it a looooot
..... End the program if the counter is larger than 100 (10*10)
0..oo:oo"Fiz"\
.............\!?%3... Check if the counter is divisible by 3 and print Fizz if so
..... Also push a 0 to the stack
.......o Swap the pushed 0 if it exists (otherwise it swaps two copies of the counter)
......./!?%5$... Check if the counter is divisible by 5 and print Buzz if so
o"Buzz"/$0oo Also push a 0 to the stack
.......... Multiply the top two values of the stack.
..oan?*... If the counter was divisible by 5 or 3 print the number
.......... Print a newline and loop around again
As time goes, the stack fills up, with an extra copy of the counter for each Fizz or Buzz (and two for FizzBuzzes). This is due to the extra copy(s) of the counter that don't end up being printed.
R, 68 66 bytes
for(i in 1:100)write(max(i,paste0("Fizz"[!i%%3],"Buzz"[!i%%5])),1)
I must be missing something here because this is way too simple. I know that you really shouldn't use loops in R but like this is a bit smaller than the first R one I saw so yeah.
Edited about a day after the original: you can get rid of the curly braces to save 2 characters.
MineFriff, 240 bytes
0,`
>I1,+:a*a1,=?;`~ o,aC <
>:f,%?`Ca*c2,:a*b7,7*e,a*c2,:f*7,a*7,oooooooo^
>:5,%?`Ca*c2,:a*b7,6*b,oooo ^
>:3,%?`Ca*c2,:f*7,a*7,oooo ^
>:o ^
What it actually looks like:
Haskell, 84 82 bytes
main=mapM putStrLn[show n`max`map("FizzBuzz"!!)[6-2*gcd 3n..2+gcd 5n]|n<-[1..100]]
The expressions work out like this:
n 6-2*gcd(3,n) 2+gcd(5,n)
=============================
1 4 3
2 4 3
3 *0 3
4 4 3
5 4 *7
6 *0 3
7 4 3
8 4 3
9 *0 3
10 4 *7
11 4 3
12 *0 3
13 4 3
14 4 3
15 *0 *7
16 ... ...
We use them as start and end points for slicing the string. For example, when n == 5, then map("FizzBuzz"!!)[4..7] == "Buzz".
For non-divisible numbers, the range [4..3] is empty, so the result of map is "", and max (show n) replaces that result.
Old 84 byte answer
main=mapM f[1..100]
f n|d<-drop.(*4).mod n=putStrLn$max(show n)$d 3"Fizz"++d 5"Buzz"
d = drop.(*4).mod n is key here: d 3 "Fizz" is drop (n`mod`3 * 4) "Fizz". This is "Fizz" when n `mod` 3 is 0 and "" otherwise.
Other stuff
I got here via this 85:
main=mapM putStrLn[max(show n)$drop(6-2*gcd 3n)$take(3+gcd 5n)"FizzBuzz"|n<-[1..100]]
Here is another interesting 85:
f n=cycle[show n,"Fizz","Buzz",f 3++f 5]!!div(gcd 15n)2
main=mapM(putStrLn.f)[1..100]
The world record is 80 bytes by henkma.
Add++, 89 bytes
l:100
Fl,`f,i%3,f=0,"Fizz"*f,`b,i%5,b=0,"Buzz"*b,`p,f+b,p="",Ip,,Oi,`c,f+b,`P,p=0,IP,,Oc,
"But there's a shorter Add++ answer" I hear you say. Well, this is flagless and doesn't have a Lambda, so I'd thought I'd post it for comparison.
Add++ -i, 46 bytes
L,100Rdd3€Ω%€!"Fizz"€*$5€Ω%€!"Buzz"€*z£+z£obUn
The flag simply invokes the function for us and outputs its return value, so we don't have to include the invocation in the program.
How it works
L, ; Anonymous function
100R ; Push [1 2 3 4 ... 99 100] STACK = [[1 2 ... 99 100]]
dd ; Triplicate STACK = [[1 2 ... 99 100] [1 2 ... 99 100] [1 2 ... 99 100]]
€ € ; Over the first, check ...
3 Ω% ! ; divisibility by 3 STACK = [[1 2 ... 99 100] [1 2 ... 99 100] [0 0 ... 1 0]]
"Fizz"€* ; Replace 1 with "Fizz" and 0 with "" STACK = [[1 2 ... 99 100] [1 2 ... 99 100] ["" "" ... "Fizz" ""]
$ € € ; Over the second, check ...
5 Ω% ! ; divisibility by 5 STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" ""] [0 0 ... 0 1]]
"Buzz"€* ; Replace 1 with "Buzz" and 0 with "" STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" ""] ["" "" ... "" "Buzz"]]
z£+ ; Zip and concatenate STACK = [[1 2 ... 99 100] ["" "" ... "Fizz" "Buzz"]]
z£o ; Replace "" with the right number STACK = [[1 2 ... "Fizz" "Buzz"]]
bUn ; Join with newlines STACK = ["1\n2\nFizz\n...\n98\nFizz\nBuzz"]
; Return the top of the stack "1\n2\nFizz\n...\n98\nFizz\nBuzz"
Charcoal, 37 29 bytes
E…¹¦¹⁰¹∨⁺×Fizz¬﹪ι³×Buzz¬﹪ι⁵Iι
How there isn't a charcoal answer yet amazes me. -8 bytes thanks to @Neil
MAWP 2.0, 60 bytes
[!3%<"Fizz":1=M>`!5%<"Buzz":1=M>`M1-{/!:\}`0=M10;!100-?.`1+]
Explanation:
[ start of loop
!3% is top of stack divisible by 3?
<"Fizz":1=M>` if yes, print "Fizz" and set variable M to 1
!5% is top of stack divisible by 5?
<"Buzz":1=M>` if yes, print "Buzz" and set variable M to 1
M1- push value of M and subtract 1
{/!:\}` if not 0 then print the current number
0=M set variable M to 0
10; print a newline
!100-?.` if current number is 100 then terminate program
1+ add 1 to current number
] end of loop
LiveScript, 57 bytes
I noticed nobody had done LiveScript. This may not be the shortest possible answer, but it's my best attempt.
for i to 99
console.log \Fizz *!(++i%3)+\Buzz *!(i%5)||i
Integral, 416 Bytes
⌡1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz⌡[j
Integral doesn't have very many ways of doing this challenge yet, so this'll have to do for now.
I'll update it once there's a better way.
Python 2, 73 77 bytes, link
edit:
Even shorter, thanks to @Dingus + removing parenthesis:
for n in range(1,101):print[[n,"Buzz"],["Fizz","FizzBuzz"]][n%3<1][n%5<1]
original:
Here's my matrix-inspired approach:
for n in range(1,101):
print([[n,"Buzz"],["Fizz","FizzBuzz"]][n%3<1][n%5<1])
It avoids double checking modularity for 15. Written out a bit more elaborately, this becomes
for n in range(1,101):
matrix=[[n ,"Buzz" ],
["Fizz","FizzBuzz"]]
print(matrix[n%3==0][n%5==0]) # checking ==0 adds 1 byte versus <1.
MAWP, 120 bytes
[!!3P3WA<75W2W;73W5W;65W2W1M2W;65W2W1M2W;~0~>%!!5P5WA<92M6W;94M9W;65W2W1M2W;65W2W1M2W;~0~>%~{~!:~}~!554WWA?.%1M25W;~(%)]
Created this while testing my new online interpreter!
Explanation:
[ Start loop
!!3P3WA Is divisible by 3? (Homemade modulo
function)
< If top of stack is not 0 (number is
not divisible), then jump to its >
75W2W;73W5W;65W2W1M2W;65W2W1M2W; Print 'Fizz'
~0~ Add 0 to the bottom of stack by
double reversing
> End conditional
% Remove modulo function result
!!5P5WA<92M6W;94M9W;65W2W1M2W;65W2W1M2W;~0~>% Do the same for 'Buzz'
~ Reverse stack
{ If there are no 0 on the top of
stack (not 'Fizz' nor 'Buzz' was
printed),
~!:~ then print the current number
}~ End conditional and reverse stack
!554WWA?.% If the number is 100, then terminate
program
1M25W; Print newline
~(%) Remove all 0 from bottom of stack
] End of loop
International Phonetic Esoteric Language, 61 60 bytes
{2T}1ɑeb3ⱱɐbʌɔ|a|"Fizz"u|a|q5ⱱɐbʌɔ|b|"Buzz"u|b|ɞʌue1sø"\n"uɒ
Explanation:
{2T}1 (push loop bounds 1 to 2T == 101 base36)
ɑ (start loop)
eb (push and dup loop index)
3ⱱɐbʌɔ|a|"Fizz"u|a| (print if fizzy)
q (OVER)
5ⱱɐbʌɔ|b|"Buzz"u|b| (print if buzzy)
ɞʌu (else print the number)
e1sø (increment loop index)
"\n"u (print a newline)
ɒ (end loop)
-1 byte for using base 36 for 101.
Windows Batch, 149 bytes
@for /l %%N in (1 1 100)do @(set s=&set/a1/(%%N%%3^)||set s=Fizz&set/a1/(%%N%%5^)&&(if defined s (echo Fizz)else echo %%N)||call echo %%s%%Buzz)2>nul
The SET /A statements test the modulo 3 and 5 without using IF by intentionally dividing by zero and using && and || conditional command concatenation. Of course stderr must be disabled, but it still saves bytes vs an IF statement.
Windows Batch (unusual cmd.exe configuration, and environment assumption), 166 165 133 bytes
My original answer used delayed expansion, but the code to enable delayed expansion takes 32 bytes all on its own. However, some people have their cmd.exe configured to have delayed expansion enabled by default. For the small minority of people that configure cmd.exe this way, then the following is significantly shorter.
@for /l %%N in (1 1 100)do @(set 1=&set/a1/(%%N%%3^)||set 1=Fizz&set/a1/(%%N%%5^)||set 1=!1!Buzz&>nul set 1&&echo !1!||echo %%N)2>nul
Besides relying on an unusual cmd.exe configuration, it is also reliant on the absence of any environment variable names that begin with 1. This is normally safe because batch treats something like %1var% as batch parameter %1 followed by a string constant var - the trailing % would get stripped. So people are taught to never begin variable names with a digit.
W n, 22 21 bytes
Seems like nobody ties with Dennis. Just 1 byte away...
♥:jΓƒ¢D╦Γ%%lOvhI♣BAE§
Uncompressed:
3m!?SY%?*?SZ%?a5m!*+a|2^N
Explanation
2^N For Each: 1 to 100
3m! Repeat whether current item is divisible by 3
?SY%?* Repeat that bool by the compressed "Fizz"
?SZ%?a5m!* Do that for "Buzz" too
+ Join the results
a| If the result is empty,
turn it to the current item value.
Flag: n Join the resulting list with newlines
Implicit output
```
Erlang (escript), 166 bytes
i(A,B,C,D)->if A==B->C;1<2->D end.
f(X)->i(X rem 3,0,"Fizz","")++i(X rem 5,0,"Buzz","").
z(0)->"";z(X)->z(X-1)++"~n"++i(f(X),"",integer_to_list(X),f(X)).
z()->z(100).
Symja, 140 134 128 bytes
For(i=1,i<101,i++,If(Mod(i,5)==0,s=s<>"Fizz");If(Mod(i,3)==0,s=s<>"Buzz");If(Mod(i,5)*Mod(i,3)!=0,s=s<>ToString(i));s=s<>"\n");s
Just a standard fizzbuzz approach. This is tweetable BTW, so there's that too.
Keg, 58 40+4 43 bytes
1(d|0&:3%[|`Fizz`,⑹]:5%[|`Buzz`,⑹]&[|:.]
,⑨
-14 bytes thanks to @EdgyNerd and then -1 byte due to using register
Answer History
58 bytes
1(d|:\“%0=[`FizzBuzz`|:5%0=[`Buzz`|:3%0=[`Fizz`|:⅍]]],
,⑨)
String compression and string formatting are both useless here. Just a standard implementation of Fizzbuzz in Keg.
Stax, 27 bytes
éeO├φ☻mRàzΦ╛`φ#2àáÿ²øΔ=L←§b
Unpacked and Uncompressed
A2#F~;3%z"Fizz"?;5%z"Buzz"?+cz=,a?P
Visual Basic Script, 123 bytes
For i=1To 100
S=""
If i Mod 3=0Then
S="Fizz"
End If
If i Mod 5=0Then
S=S+"Buzz"
End If
If S=""Then
S=i
End If
MsgBox S
Next
Sorry @Taylor Scott but I basically copied your MY-BASIC solution
W d, 29 23 bytes
&ó╞╟↨5O╓46N☻»½_49ƒZÄ▬«Σ
A raw source is here.
After decompression:
2^ E % Foreach in the 1..100 range
a3m! % If the current item is divisible by 3:
"Fizz" * % Return "Fizz"
"Buzz"a5m!* % If the current item | 3 -> "Buzz".
+ % Join those results
a| % Logical OR this result with the current item
% Implicit print
Javascript 78 (but kinda 58) bytes
Produces the required string, then prints it. The function that produces the string is 58 bytes, another 20 are used to call console.log.
z=n=>n?z(n-1)+((n%3?'':'Fizz')+(n%5?'':'Buzz')||n)+'\n':'';console.log(z(100))
Javascript 72 71 bytes (thanks, Jo King!)
Prints the required lines as it goes. Interweaving console.log with the logic creates a shorter, though less elegant, program.
z=n=>n&&(z(n-1),console.log((n%3?'':'Fizz')+(n%5?'':'Buzz')||n));z(100)
It can also be written like the following, to the same effect and byte count.
z=n=>n&&console.log((z(n-1),(n%3?'':'fizz')+(n%5?'':'buzz')||n));z(100)
De-golfed version:
z = n => // take n as argument
n && ( // if n is not falsey (e.g. if it is not 0)
z(n-1), // use the comma operator to call the previous fizzbuzz
console.log( // then print a line
(n%3 ? '' : 'Fizz') // 'Fizz' if n is a multiple of 3, otherwise empty
+ (n%5 ? '' : 'Buzz') // Concatenated with 'Buzz' if multiple of 5
|| n // Or just the number n if the previous string is empty, which implies that n is not divisible by 3 or 5
)
);
z(100) // Run fizzbuzz from 100
Rust, 114 bytes
It's not the shortest one available (on code-golf.io someone managed to somehow solve it in 99 bytes, but I have no idea how).
fn main(){(1..101).for_each(|i|println!("{}",["FizzBuzz","Fizz","Buzz",&i.to_string()][1.min(i%5)+2.min(i%3*2)]))}
First off, the obvious part
fn main() {/*..*/}
Then we iterate from 1 to 100 (inclusive) and println! an element of the array
(1..101).for_each(|i| println!("{}", ["FizzBuzz", "Fizz", "Buzz", &i.to_string()][/*..*/]))
To choose the right index, we use the following, where i is the current number
1.min(i % 5) + 2.min((i % 3) * 2)
The first part is 0 if i is a multiple of 5. Otherwise it's 1.
The second part is 0 if i is a multiple of 3. Otherwise it's 2.
Examples:
1.min(1 % 5) + 2.min((1 % 3) * 2) == 1 + 2 == 3 => "1"
1.min(3 % 5) + 2.min((3 % 3) * 2) == 1 + 0 == 1 => "Fizz"
1.min(4 % 5) + 2.min((4 % 3) * 2) == 1 + 2 == 3 => "4"
1.min(5 % 5) + 2.min((5 % 3) * 2) == 0 + 2 == 2 => "Buzz"
1.min(15 % 5) + 2.min((15 % 3) * 2) == 0 + 0 == 0 => "FizzBuzz"
This way, if both parts produce 0, we get the string FizzBuzz.
If the sum is 1 we get Fizz, if it's 2 Buzz, if it's 3 we get &i.to_string() (the stringified number).
sed 4.2.2, 129 bytes
A 400-rep bounty for those who outgolf this solution https://codegolf.meta.stackexchange.com/a/18428/
s/^/00,/;h
:
y/0123456789';,/1234567890;,'/
/0.$/!{x;G;s/..\n.//}
h
s/[05].$/&Buzz/
s/.*,/Fizz/
s/.*\WB/B/
s/[0';]*//gp
g;/00/d
t
s/^/00,/;h
Each number is stored as three characters, the first two store the two-digit padded decimal number, and the last character stores its modulo 3.
: ... t
In a loop,
y/0123456789';,/1234567890;,'/
the modulo is cycled, and the number is incremented using transliteration. Each digit is increased modulo 10, then
/0.$/!{x;G;s/..\n.//}
a simple conditional corrects the first digit on the number if necessary, using the fact each number is stored with exactly 3 characters.
h
This incremented form is stored in the hold space.
s/[05].$/&Buzz/
Buzzs are added by looking at the last base-10 digit of the number.
s/.*,/Fizz/
Fizzs are added by looking at the modulo-3.
s/.*\WB/B/
There is some cleanup of the number, remove the base-10 digits if needed and
s/[0';]*//gp
remove leading 0s and the modulo-3 so that it is print-ready, and print it.
g;/00/d
Finally retrieve the number from the hold space and exit if 00 is present, i.e. 100 has been reached
APL, 52 chars/bytes
generate integers from 1 to n
⍳
b is a 2 by n boolean matrix highlighting multiples of 3 and 5
b←0=3 5∘.|⍵
c is a boolean vector highlighting multiples of either 3 or 5
c←∨⌿b
format each integer into a character vector
⍕¨⍵
where a number is a multiple of either 3 or 5...
@{c}
...put either Fizz or Buzz (i.e. discard the last 4, the first 4 or no character at all from the string "FizzBuzz" according to b)
(↓∘'FizzBuzz'¨¯4 4+.×c/b)
transform the nested vector into a matrix
↑
DIVSPL, 22 bytes
1..100
fizz=3
buzz=5
MC6000 ASM (Shenzhen I/O), 133 Bytes
add 1
mov acc x3
mov 51 x2
mov acc x2
mov 3 x2
teq x2 0
+mov 1 x1
mov 51 x2
mov acc x2
mov 5 x2
teq x2 0
+mov 2 x1
slp 1
mov -999 x1
Uses an MC4010 co-processor on x2, numeric display on x3, and a custom fizzbuzz display on x1.
"Hardware":
Custom LCD:
Technically doesn't follow the rules as MCxxxx don't have a STDOUT, but I did the best I could.
80386 machine code + DOS, 75 68 bytes
NOTE: This is a reply to @anatolyg's really clever 2015 answer, with a few tweaks to reduce the score by 7 bytes. I'm only submitting this as a separate answer because it wouldn't be possible to explain fully in a comment.
Changes:
- Use
SIto resetBXsince DOS setsSIinitially to100H(ref) instead of animm. (-1 byte) - Instead of using a 3/5 counter in
DH/DL, useAAMfor modulo operations on counter.AAMis a 2 byte instruction that's effectively a byte-lengthDIVthat can accept animmvalue as the divisor and also setsZFifAL mod n = 0. @Peter Cordes touches on this in his very brilliant post about FizzBuzz in assembly. (-5 bytes) - Instead of CR/LF, use LF/CR (the order doesn't matter to DOS). This translates to an instruction that does not modify the startup value of
AX(in fact it zeroes outAL) so we can eliminate thexor ax,axand save two bytes. It does come at a cost because0A 0Dis only a two-byte instruction so the rest of the24xxinstruction needs to be padded with one more byte. (-1 byte)
Unassembled:
0A 0D or cl, [di] ; LF and CR bytes (newline)
24 00 and al, 0 ; DOS string delim ('$') + pad byte
B1 64 mov cl, 100 ; set loop counter to 100
main_loop:
8B DE mov bx, si ; init bx to 100h
40 inc ax ; increment fizzbuzz counter
50 push ax ; save fizzbuzz counter
50 push ax ; save ax from getting clobbered by AAM
D4 05 aam 5 ; AL = AL mod 5, ZF if AL = 0
58 pop ax ; restore ax
75 0A jnz short buzz_done ; jump if not a 'Fizz'
83 EB 04 sub bx, 4 ; offset for output string
66C707 7A7A7542 mov dword ptr [bx], 'zzuB'
buzz_done:
50 push ax
D4 03 aam 3 ; AL = AL mod 3, ZF if AL = 0
58 pop ax
75 0A jnz short fizz_done ; jump if not a 'Buzz'
83 EB 04 sub bx, 4
66C707 7A7A6946 mov dword ptr [bx], 'zziF'
fizz_done:
84 FF test bh, bh ; either a Fizz or a Buzz? (BX not changed)
74 0C jz short num_done ; if so, do not display a digit
decimal_loop:
D4 0A aam; ; AL = AL mod 10
04 30 add al, '0' ; convert to ASCII
4B dec bx
88 07 mov [bx], al
C1 E8 08 shr ax, 8 ; 'mov al, ah', ZF if AL = 0
75 F4 jnz decimal_loop
num_done:
8B D3 mov dx, bx ; set dx to output string pointer
B4 09 mov ah, 9
CD 21 int 21h
58 pop ax ; restore fizzbuzz counter
E2 C3 loop main_loop
C3 ret
xxd binary:
00000000: 0a0d 2400 b164 8bde 4050 50d4 0558 750a ..$..d..@PP..Xu.
00000010: 83eb 0466 c707 4275 7a7a 50d4 0358 750a ...f..BuzzP..Xu.
00000020: 83eb 0466 c707 4669 7a7a 84ff 740c d40a ...f..Fizz..t...
00000030: 0430 4b88 07c1 e808 75f4 8bd3 b409 cd21 .0K.....u......!
00000040: 58e2 c3c3 X...
Scala, 65 64 Bytes
1.to(100).map(n=>{print(s"\n$n"+(if(n%3==0)"fizz")+(if(n%5==0)"buzz"))})
I've just started golfing so any tips are appreciated (yes I have read this)
Python 3, 80 bytes
for x in range(1,101):print(("Fizz"if x%3==0else"")+("Buzz"if x%5==0else"")or x)
Wren, 78 bytes
It turns out that this is pretty hard to golf.
for(i in 1..100)System.print(i%15==0?"FizzBuzz":i%5==0?"Buzz":i%3==0?"Fizz":i)
Julia, 87 bytes
z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
println.(z.(1:100))
Or we could kind of cheat to drop 3 bytes and use show instead of println. Julia 83 bytes
z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)
show(z.(1:100))
or a more legible FP style, poor performing, 91 bytes
F(x)=foldl(*,["Fizz","Buzz"][x .%[3,5] .==0])
N(y)=F(y)=="" ? y : F(y)
println.(N.(1:100))
Julia isn't really made for this, but I had fun thinking about this a bit :).
Zsh, 105 78 68 66 61 bytes
for i ({1..100})(((i%3))||w=Fizz;((i%5))||w+=Buzz;<<<${w-$i})
-27 using simpler approach
-10 using parameter fallback
-2 thanks to @Dennis - kudos for the bash solution
-5 thanks to @GammaFunction
Original solution, using weird r flag... try it online
for ((;i++<100;));{f=$[i%3>0?0:4] b=$[i%5>0?0:4]
echo ${(r:$f::Fizz:)}${(r:$b::Buzz:)}`((f+b>0))||<<<$i`}
Hoon, 115 bytes
This is a Hoon say generator which can be used to write the output to a file from the dojo.
turn is Hoon's map, it takes a list from 1..100 generated via (gulf 1 100) and uses string interpolation and the 'null check' conditional rune ?~ to generate either "Fizz", "Buzz" or "FizzBuzz" according to the value of x. This is paired with the value of x as a string <x> and then - and + are used to select the fizzbuzz string if not empty, otherwise the number string from the pair.
:-
%say
|=
*
:-
%txt
%+
turn
(gulf 1 100)
|=
x=@
=>
"{?~((mod x 3) "Fizz" ~)}{?~((mod x 5) "Buzz" ~)}"^<x>
?~
-
+
-
Seed, 6015 bytes
186 83944644497775792185807323999861330742900673481712359255839929374667216476568023851764637813248013688693896717275687232066153870107749175160194707761486575005885313952906442913325967953944535811512056079183251514390746052490451307246213606447865255212286265116943188690839445165359981774554198082946825007384980162551436390435260155582466874315352220541140434954811560506556477075852586817070090764184077321583489797358147025926992986354865415277367374043398355163643621296927936732212800075642321038031920620549375319366961667358107695950468557182519902148699776620624078332688843597417318685229781090303723160175745852091928346724348001020777912570918121340035523698691520422590527296248455779012094897281946771732844646467975422651655880202725095981882371807518829844157636552230152953535332201239998966830698645115246907049972204010095894629001206397276344975636564553238199728981112245810583644580269593382612869323054013019350314231784293448249910440692956496060253971880373279161390518237118507378691330341470412624728172421405109963475552981299919837091765136501358887135317778357279769289706821629750840213676581513947891276551415821187603189444230553630205086966993211879390093045277089486589385876312541940492767981701353769007246001400130719416118275492304807198011860072050303044225722194337717896831470037434122578382321765362062455130027125953869723625862069785410531287781468150359623495258126317807476517184801674197008747267394632928708383370640309530427431150403028006421518064783676469959724647961395869176187323826585310379142853088186864023708457159764123364029018721951815248751431170413579315400528983481702298849209797951129827235189965388114007169146563257209800975334610910397591190300324319540160364733177122449656422045835924029442449258975425381755648345550014417207471617919736685787448764321614059138375253980386335770138273578332418379763049794151811098188219754733324389355566317376598492318359989945589480418455750455469859956801589082779968271578522034926104268403877968397758570110853038536860556853388613997493905742068279137736678857073233174739380697685907170886092925173057794582407478105690770633669349947638020604803238951194381273510993928897230197983256465537488284258216944902276278712201715008765995404107536372438956009631805114079400698265046614085687812688769068889878215788959245601084883372435344000194364054441952170474833494604130017222942459218768152451353838900515646024764453476453552863938005162079649698291854043301771100462916706520075039044805956181705047266329114921035274711980897862579454154525144505597823262540025190878917613039796282312555295659294071407630514652646787462515667390800389392114746442068094785615537685660298361617697365653764669207754605147347324074541222276275532258194690926246437097055706104108319469003781845674958634242078791475826910418111428349167152839025683587469305219626924263962611094845308744968793376752461012553325189830937237777556407663277494722334379175044299145527685100424059993166500276116324651034389342857099326382267792125696063602436504279969923412378117936327869017861642388185619118723658181098871790872093500520584752433465443515989483851486224923341213990357424279098636563794743080022540640677640107176034203326304825856510242291526956869439836743210321616337131260522898066320086593786007891762080406650341513081903510025534886914361255147039463158189995500627220823997958074917925862170348467342212390436963261050291735696261617106196786273505443408966191019872244618002281427523777003325474230066462489531195157755555344637353155356279454281010364750875012491070816465270498678197434494849001514802132418781410405222031814823702582955264273367316636558580379660009282902598817700470535664545017234816209988594892835104965686956867851308392004044845547855039571721575449154495443479356960829759209226823917197487855397504141411230632224369201022681688301238065753737278463677847356448662974398206270856674118500884955014781944009536761710654880983265123955150729759406311220705702903728217724237231225228243114081826682040349685205121446193821261139703572900811243143912445467975694459999888915923116875430564637390061881889161512304819029656014338113772447267072899546161543780769850725712979853265124144813517511575434597175140160445249538753447856073028845070404104820699013418827593400549228758486817648053770622330987136941236768786640613654490823959024174575959620155957372041756651311988259843620347948677131103848960623371212015137053539005334518693964703094514744873758157905983139622925587291886231049371800498250086745691716656644176053612172113439907334397406577774498757112425437339205922869531575921611548158798375762386782843394828401126984185115349224303420458491251207091698634206841378497320259972637725826224808114267917428717816623368840721796784587349258491132128347823644310226457190477267965710821892576687103122134712656694901146343938508484308662925632874468476850854977933467327214644382364732022885458172449643330918925157997124690072012401561398600599725096512808715148150880033416494352767432615596760722206416684175988533830899565642405659319720681197534141300323187308210290375660950200938389996580887564670049743784962037885099514826194024014058093062057706139814777110125812527054724707373942053107785831307633110641398607263726549612409340127167852023607787965086360296071952107945138419803900924977980375619565210182772121849111987355981226968062629667279278470647719759267716675652568099185449478479471691254158308189631416224208590609150412906273490206303890853713104183863050119383440553687111132467944761189779633340481533657859382354192428154204487886313458547651002779223927726608436086877353829832057341247094095114657693381028772025327489391112902949559367893876211447144802835381133403893955836438518252858893637260806405255643702579004661210305919494653119109150790218729956868835489222681506976514342204634574313468575534020458319909578144280137077342941741913678288702984697189445809519253013406175446129538246339672293879388869701830984873958965248
Julia, 87 Bytes
for i in 1:100;println(i%3<1 ? "Fizz"*(i%5<1 ? "Buzz" : "") : (i%5<1 ? "Buzz" : i));end
More readable:
for i in 1:100
if i%3 < 1
print("Fizz")
if i%5 < 1
println("Buzz")
else
println()
end
elseif i%5 < 1
println("Buzz")
else
println(i)
end
end
Not sure if there's already a Julia submission here. Also my first time golfing c:
Indirect thanks to @Najkin because I saw their reply to a C# submission saying that you can use <1 instead of ==0 and that helped me save 3 bytes over my previous 90-byte solution!
BTW if you see any "unnecessary" spaces, they're actually necessary as Julia would throw a syntax error without them. (Why?!)
SQL (Oracle), 112 108 bytes
SELECT NVL(DECODE(MOD(LEVEL,3),0,'Fizz')||DECODE(MOD(LEVEL,5),0,'Buzz'),LEVEL)FROM DUAL CONNECT BY LEVEL<101
db<>fiddle here
SNOBOL4 (CSNOBOL4), 137 121 114 bytes
I X =X + 1
O =EQ(REMDR(X,3)) 'Fizz'
O =O EQ(REMDR(X,5)) 'Buzz'
O =IDENT(O) X
OUTPUT =O
O =LT(X,100) :S(I)
END
Explanation:
;* uninitialized variables start as ''
;* which is coerced to 0 in computations
I X =X + 1 ;* Increment X
O =EQ(REMDR(X,3)) 'Fizz' ;* if X mod 3 == 0, O = 'Fizz'
O =O EQ(REMDR(X,5)) 'Buzz' ;* if X mod 5 == 0, concatenate O and 'Buzz'
O =IDENT(O) X ;* if O is IDENTical to the empty string,
;* set O to X
OUTPUT =O ;* print O
O =LT(X,100) :S(I) ;* set O to '' and if X < 100, goto I
END
Pip, 43 41 bytes
Fa1,101{i:0a%3?i:1O"FIZZ"a%5?i?PaPxP"BUZZ"}
Lh{i:0o%3?i:1O"FIZZ"o%5?i?PoPxP"BUZZ"++o}
33, 60 bytes
1asz'Fizz'{tlot}t[3rznpn1cztsl5rz"Buzz"npn1tlaz''nqtl1aztsi]
Explanation:
1asz (Initialise the counter with 1)
'Fizz'{tlot}t (Create function 'Fizz' to print current number)
[ (Start of loop)
3rz (Check if divisible by 3)
np (If so, print 'Fizz')
n1czts (Store result for later)
l (Load the counter back)
5rz (Check if divisible by 5)
"Buzz"np (If so, print 'Buzz')
n1tlaz (Check if divisible by neither by retrieving the value from earlier)
''nqt (If neither 'Fizz' nor 'Buzz' was printed, print the number)
l1azts (Restore our counter and increment it)
i] (Print a newline and repeat from the start of the loop)
APL (Dyalog Unicode), 37 bytesSBCS
↑{∨/d←4/0=3 5|⍵:d/'FizzBuzz'⋄⍕⍵}¨⍳100
⍳100 ɩndices 1…100
{…}¨ apply the following anonymous lambda to each of those:
⍵ the argument; e.g. 20
3 5| the division remainder when that is divided by 3 and 5; e.g. [2,0]
0= Boolean mask where that is equal to 0; e.g. [0,1]
4/ replicate those numbers for 4 copies of each; e.g. [0,0,0,0,1,1,1,1]
d← assign that to d
∨/…: if any of those are true (OR-reduction); e.g. true:
d/'FizzBuzz' use d to mask the characters of the string; e.g. "Buzz"
⋄ else:
⍕⍵ stringify the argument; e.g. "20"
↑ mix the list of strings into a matrix, so it prints right
05AB1E, 24 bytes
тÝ3Å€"Fizz"}5Å€á”ÒÖ”J}¦»
Explanation:
тÝ # range 0..100
3Å€ } # for every 3rd element...
"Fizz" # replace it with Fizz
5Å€ } # for every 5th element...
á # keep only letters...
”ÒÖ”J # and append "Buzz"
¦ # drop the first element
» # join with newlines
# implicit output
Or alternatively:
тÝ35vyÅ€á”FizzÒÖ”#NèJ]¦»
35vy iterates over the digits of 35, which avoids repeating Å€}. ”FizzÒÖ” is the string Fizz Buzz, and then #Nè selects the appropriate element.
Legacy 05AB1E doesn’t have Å€, so neither of those work for it. However, legacy à (set intersection) implicitly splits numbers, which lets us get a 26 that only works on legacy:
тLεDÑ35Ãvá”Fizz ÒÖ”#yèJ},
тLε # for y in 1..100
DÑ # divisors of y
35Ã # keep only those in [3, 5]
v } # for each...
á # keep only letters
”Fizz ÒÖ”#yèJ # append either Fizz or Buzz
, # print with newline
C, 98 94 bytes
i;main(){for(;++i<101;)i%3*i%5?printf("%d\n",i):printf("%s%s\n",i%3?"":"Fizz",i%5?"":"Buzz");}
Pretty simple stuff...
Thanks to Yoris Fresh for helping me save a couple bytes. Thanks to Jerry Jeremiah for pointing out a mistake in the ungolfed version.
Ungolfed:
i;
main() {
for (; ++i < 101;)
i % 3 && i % 5 ?
printf("%d\n",i) :
printf("%s%s\n", i % 3 ? "" : "Fizz", i % 5 ? "" : "Buzz");
}
Racket, 107 Bytes
(for{[x 100]}(define(f a b n)(if(=(modulo(+ 1 x)n)0)a b))(printf"~a~a\n"(f'Fizz""3)(f'Buzz(f""(+ 1 x)3)5)))
The inspiration for my answer comes from Luca H's post.
All I did afterwards was factor out the repetitive calls to (if (modulo ...) ...). Sadly, there are two copies of (+ 1 x) left that I couldn't factor out using less characters, so they remain.
Ungolfed (including removing f):
(for {[x 100]}
(printf "~a~a\n"
(if (= (modulo (+ x 1) 3) 0) 'Fizz "")
(if (= (modulo (+ x 1) 5) 0) 'Buzz
(if (= (modulo (+ x 1) 3) 0) "" (+ x 1)))))
Scheme, 118 bytes
(for-each(lambda(i)(printf"~a~a~%"(if(=(mod i 3)0)'Fizz"")(if(=(mod i 5)0)'Buzz(if(=(mod i 3)0)""i))))(cdr(iota 101)))
Ungolfed:
(for-each
(lambda (i)
(printf
"~a~a~%"
(if (= (mod i 3) 0) 'Fizz "")
(if (= (mod i 5) 0) 'Buzz
;; else
(if (= (mod i 3) 0) "" i))))
(cdr (iota 101)))
C++ 123 122 bytes
-1 thanks to JonathanFrech
#import<iostream>
#define s std::cout<<
main(){for(int i;100-i++;s(i%3?"":"Fizz")<<(i%5?"":"Buzz")<<'\n')i%3*i%5?s i:s"";}
JavaScript, 127 122 81 79 bytes
for(e=0;++e<101;)console.log(e%3||e%5?e%3==0?"Fizz":e%5==0?"Buzz":e:"FizzBuzz")
Another way, based on Taylor Scott's solution, is only 78 72 bytes
for(e=0;++e<101;)s=e%3?"":"Fizz",s+=e%5?"":"Buzz",console.log(""==s?e:s)
Java 8, 129 bytes
interface I{static void main(String[]s){for(int i=0;++i<101;)System.out.println(i%15<1?"FizzBuzz":i%3<1?"Fizz":i%5<1?"Buzz":i);}}
brainfuck, 628 499 bytes
+[>>+>>+++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[>>]<[>-[------->+<]>---.[--<+++>]<.-[---<+>]<-..<<<<[-]>>>>>>]<[-]<[-]<[-<+>]>+++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[>>]<[-[++++>---<]>-.++[-----<+>]<+.+++++..<<<<[-]>>>>>>]<[-]<[-]<[-<+>]<<<[[-]>>[-<+>>+<]>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<[-]<[-<+>]<[-]<<[->+<]<]++++++++++.>>[-<+>>+<]-[<-->-----]<++]
This took me WAY too long. It's an extremely naive implementation with two divmods and a printing bit for Fizz and Buzz, as well as an equality check for 100. All in all not really golfed. At all. Not even a little bit. But it was fun, as this was my first ever real brainfuck program.
I started this by purposely not looking at any of the other brainfuck answers, partly so I wouldn't get discouraged, and partly so I wouldn't even subconsciously use any other ideas.
Any feedback or shrinkings are appreciated!
Brachylog, 48 bytes
100⟦₁{f{∋15∧"FizzBuzz"|∋3∧"Fizz"|∋5∧"Buzz"|t}ẉ}ᵐ
Probably not golfed too well but it works.
Word VBA, 124 189 bytes
Sub f()
For i=1 To 100
r=""
If i Mod 3=0 Then r="Fizz"
If i Mod 5=0 Then r=r & "Buzz"
If r="" Then r=i
Debug.?r
Next
End Sub
The code breakdown is fairly simple (yay, BASIC).
Loop from 1 to 100
For i=1 To 100Set a variable to be an empty string
r=""Check the value on the counter to see if we should set the variable to Fizz
If i Mod 3=0 Then r="Fizz"Check the counter to see if we need to add Buzz (adding it to an empty string is the same as setting that variable to Buzz)
If i Mod 5=0 Then r=r & "Buzz"Check to see if the variable is still empty and therefore needs to be set to the counter value
If r="" Then r=iPrints the results to the immediate window
t = t & r & vbCr
EDIT: Used @Taylor-Scott's suggestions to tighten it up. Relies on the meta discussion about counting characters when your IDE forces whitespace. Specifically the conclusion that if you can paste the code from the answer into the IDE and run it without issues, then you don't have to count the results of autoformatting.
JavaScript (Node.js), 71 bytes
for(i=0;++i<101;)console.log((l=i%3<1?"Fizz":'')+(i%5<1?"Buzz":l?"":i))
BuzzFizz, 86 bytes
$a++
if3\$a:print"Fizz"
if5\$a:print"Buzz"
else:print$a
print"\n"
if100\$a:#
else:loop
Explanation
Despite being golfed, all you have to do is to add a bit of horizontal whitespace and a few comments to get possibly one of the clearest and most readable FizzBuzzes ever. (Vertical whitespace is significant in BuzzFizz, apart from (by popular demand) the trailing newline, so it's necessary even in a golfed program.)
# Counters start at 0. So $a will be increased to 1 on the first iteration.
# On subsequent iterations, it counts up by 1 each time.
$a++
# BuzzFizz supports only one operator: \, the "divides into" relational
# operator. So you'll be seeing that every time there's an if statement.
# It's pretty helpful for a fizzbuzz!
if 3\$a: print "Fizz"
if 5\$a: print "Buzz"
# The "else" statement attaches to *both* "if" statements simultaneously;
# it'll only run if neither of them did. "else" always attaches to all
# "if" statements since the preceding "else", so sometimes a dummy "else"
# statement is needed in order to clear the state. We don't need to
# resort to that for our FizzBuzz program, though.
else: print $a
# Now we've printed Fizz/Buzz/FizzBuzz/the number, print a newline.
print "\n"
# Our loop ends when $a becomes 100. 100 is the lowest positive integer
# that's divisible by 100, so we can use a divisibility test to find
# the end of the loop. We negate the test via the use of a comment as
# the body of the "if" statement (an "if" body cannot be empty in
# BuzzFizz, but a comment counts as a statement).
if 100\$a: # do nothing
# If $a is *not* divisible by 100, we have another iteration. So loop
# back to the start of the program.
else: loop
Discussion
In addition to the commands seen in the FizzBuzz program above, BuzzFizz also supports input (if you use an identifier like a with no leading $, the program will ask for its value; you can use a statement like clear a to reset the value so that the program asks for it again the next time it's used). Other than that, the above program shows off all the features of the language; in other words, we have a complete language built entirely out of the operations you need to write a simple FizzBuzz program (thus the name).
Despite its inspiration, BuzzFizz is not specialised merely for FizzBuzzes; you can take the FizzBuzz program apart, put it together in other ways, and solve a surprisingly large range of problems. For example, the Esolang page for the language has a primality tester and a program which adds two positive numbers. (The primality tester is simpler than the addition program; given BuzzFizz's choice of operator, this probably shouldn't be too surprising.)
That said, the language is (intentionally) not Turing-complete; the original inspiration of the language was to act as a counterexample to people who made claims of the form "any language that can do X must be Turing-complete", as the most common choices of X don't actually require it. On the other hand, it's also (intentionally) very powerful for a sub-Turing language; it's fairly hard to come up with simple problems that BuzzFizz can't solve and Turing-complete languages can.
Javascript, 80 bytes
for(i=1;i<101;i++){console.log(i%3==0?i%5==0?"FizzBuzz":"Fizz":i%5==0?"Buzz":i)}
JavaScript, 73 71 65 bytes
for(i=1;i<101;i++)console.log((i%3?"":"Fizz")+(i%5?"":"Buzz")||i)
Alchemist, 101 bytes
0x+f+b->Out__+x+b
0x+0f->Out_"Fizz"+2f+x
0x+0b+f->Out_"Buzz"+5b+x
x+0b->f
x+b+a->_+Out_"\n"!99a+2f+4b
Takes a few confusing shortcuts in order to reuse the Buzz for FizzBuzzs.
Explanation:
!99a+2f+4b # Initialise the program with
# 99a (overall counter)
# 2f (Fizz counter)
# 4b (Buzz counter)
# 1_ (num counter)
0x+f+b->Out__+x+b # If there's a Fizz and Buzz counter, print the current number
# Also decrement the Fizz counter
0x+0f->Out_"Fizz"+2f+x # If there's no Fizz counter, print Fizz
# And reset the Fizz counter
0x+0b+f->Out_"Buzz"+5b+x # If there's no Buzz counter and there is a Fizz counter, print Buzz
# Reset the Buzz counter
# And decrement the Fizz counter
# After we've printed any of these, set the x flag
x+0b->f # If there is also no Buzz counter, go back to the Buzz printer
# This is to ensure the Buzz check comes after the Fizz check
x+b+a->_+Out_"\n" # Otherwise, decrement the total counter
# Decrement the Buzz counter
# Increment the num counter
# And print a newline
Dart, 80 bytes
f({i=0}){for(;i++<100;)print((i%3>0?'':'Fizz')+(i%5>0?(i%3>0?'$i':''):'Buzz'));}
f({i=0}){for(;i++<100;)print("${i%3>0?'':'Fizz'}${i%5>0?(i%3>0?i:''):'Buzz'}");}
f({i=0}){for(;i++<100;)print(i%15<1?'FizzBuzz':i%5<1?'Buzz':i%3<1?'Fizz':'$i');}
Julia 1.0, 72 bytes
(n->println([n,"Fizz","Buzz","FizzBuzz"][sum(n.%[1,3,5,5].<1)])).(1:100)
Not the shortest solution possible, but I like the obfuscation. Try it online!
Explanation
We apply an anonymous function (n->...) itemwise .( ) to the range 1:100.
The function body does this (using sample input n=5):
n.%[1,3,5,5] # Modulo n by each of these numbers [0,2,0,0]
.<1 # Itemwise, is each remainder zero? [true,false,true,true]
sum( ) # Count number of trues in the array 3
# This will be 4 for multiples of 15, 3 for multiples
# of 5, 2 for multiples of 3, and 1 for other numbers
[n,"F","B","FB"][ ] # Index (1-based) into this array "Buzz"
println( ) # Print, with a newline
Bash, 85 81 78 74 72 71 bytes
for((;i++<100;j=i%3&2|i%5/4)){
o=($i Buzz Fizz FizzBuzz)
echo ${o[j]}
}
Thanks to @Neil for saving 4 bytes!
Thanks to @manatwork for saving 3 bytes!
Thanks to @primo for saving 2 bytes!
Pyth, 39 bytes
VS100J+?q0%N3"Fizz"k?q0%N5"Buzz"k?qJkNJ
There's probably an easier and shorter way. Also is(polishNotation, annoying).
This is roughly equivalent to:
for x in range(1,100):
a = "" + "Fizz" if x%3==0 else "" + "Buzz" if x%5==0 else ""
print(a if a!="" else x)
APL(NARS), 44, 43, 39 chars 78 bytes
⊃{⍱/z←0=3 5∣⍵:⍕⍵⋄∊z/'fizz' 'buzz'}¨⍳100
In practice I follow Adam suggest.
I had seen other APL solutions, so I copied the way. In the follow APL code, ←A here suppress the output of A.
←{⎕←∊{∨/j←0=3 5∣⍵:j/'fizz' 'buzz'⋄⍵}⍵}¨⍳100
{⎕←∊{∨/j←0=3 5∣⍵:j/'fizz' 'buzz'⋄⍵}⍵⋄⍬}¨⍳100
This above should return at end 100 void list, but it seems they are not showed at last here.
{⎕←{×+/j←0=3 5∣⍵:⊃,/j/'fiz' 'buz'⋄⍵}⍵⋄⍬}¨⍳100
This just above has one error because fiz and buz should be fizz and buzz
{⎕←{0<+/j←0=(3 5)∣⍵:⊃,/j/('fiz' 'buz')⋄⍵}⍵⋄⍬}¨⍳100
:for i:in⍳100⋄{0<+/j←0=(3 5)∣⍵:⊃,/j/('fiz' 'buz')⋄⍵}i⋄:endfor
K (oK), 49 46 43 bytes
Solution:
`0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100
Explanation:
`0:{$[a:,/$&`Fizz`Buzz!~5 3!'x;a;x]}'1+!100 / the solution
!100 / range 0..99
1+ / add 1
{ }' / apply lambda {} to each number
$[ ; ; ] / conditional, $[if;then;else]
5 3!'x / apply modulo (!) of each 5 and 3 to the input x
~ / not (0->1, anything else->0)
`Fizz`Buzz! / turn results into a dictionary
& / keys where true
$ / convert to strings
,/ / flatten
a: / save as a
a / result if a is not empty - so Fizz / Buzz
x / result if a is empty - so 1, 2, 4
`0: / print to stdout
Notes:
- -6 bytes thanks to @ngn with a new approach
C#, 119 bytes
class q{static void Main(){for(var i=0;i++<100;)System.Console.WriteLine(i%3*i%5>0?i+"":$"{i%3:;;Fizz}{i%5:;;Buzz}");}}
I was wondering how close I could get to the long standing 124 byte C# answer by Pierre-Luc, so I challenged myself to try. After unexpectedly beating it by just one byte (123 bytes, Try it online!), I took the advice from @LiamK's three year old comment and used string interpolation to shave off another 4 bytes. I'm genuinely surprised by how well this worked out!
R, 88 83 77 71 70 bytes
I'm sure that this can be improved ... and it was with credit to @flodel. A further couple of bytes saved thanks to a suggestion from @njnnja and another from @J.Doe
x=y=1:100;y[3*x]='Fizz';y[5*x]='Buzz';y[15*x]='FizzBuzz';write(y[x],1)
MathGolf, 24 22 bytes
♀{î╕Σ╠δ╕┌╠δ`+Γî35α÷ä§p
Explanation
♀ Push 100
{ Start block
î Push loop counter (1-indexed)
╕Σ╠δ Decompress "Σ╠" and capitalize to get "Fizz"
╕┌╠δ Decompress "┌╠" and capitalize to get "Buzz"
` Duplicate top 2 elements of stack
+ Add (creating "fizzbuzz")
Γ Wrap top 4 elements of stack in array
î Push loop counter (1-indexed)
3 Push 3
5 Push 5
α Wrap last 2 elements in array
÷ Check divisibility (implicit mapping)
ä Convert from binary to int
§ Get array item
p print
End block on code end, for loop implicit (100 iterations)
Groovy, 63 bytes
Stand-alone program, prints result to STDOUT.
100.times{n->s=(++n%3?'':'Fizz')+(n%5?'':'Buzz')
println s?s:n}
I'd have preferred to use (1..100).each{ instead of 100.times{, so that I didn't have to ++n at the start of each iteration, but this is golf and that saves me two bytes.
Other than that, a pretty standard truthy-based submission. 'Fizz' and 'Buzz' are added when remainder is 0 because 0 is falsy, and '' is a falsy string, so I can print n when the first line hasn't had either of 'Fizz' or 'Buzz' added.
Lua, 80 bytes
Can probably be improved:
s=("").sub for i=1,100 do r=s("Fizz",i%3*5)..s("Buzz",i%5*5)print(r..s(i,#r))end
Readable version:
s=("").sub
for i=1,100 do
r=s("Fizz",i%3*5)..s("Buzz",i%5*5)
print(r..s(i,#r))
end
12-BASIC, 73 55 50 bytes
FOR I=1TO 100?"FIZZ"*!(I%3)+"BUZZ"*!(I%5)OR I
NEXT
The first code golf program I've written in the language I'm creating.
I should probably avoid code golf while working on it though...
Python 2.7, 105 bytes
for i in range(1,101):
w=''
if i%3==0:w+='Fizz'
if i%5==0:w+='Buzz'
if w!='':print w
else:print i
I know this can be golfed a lot. But I don't know how though.
Brain-Flak, 474 470 446 438 420 412 bytes
-18 bytes thanks to Nitroden!
-8 thanks to Wheat Wizard
(((()()()()()){}){}){({}[(()())]((((())))))}{}{({}<>)<>({}<>)<>({}()()<>)<>}<>{}{}{([{}]())({()<(({}())()){(<{}>)((((()()()())())((((({}{}){})[()]){}){}()))){({}<>)<>}}{}{(<{}>)(((((()()()())({})){}())(({})({}())({}{})))){({}<>)<>}}>}{}[()]){([](<>))<>((()()()()()){}){(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}<>)<>{({}<>)(<>)}}{}(<>)<>}<>{}{{({}((((()()()){}){}){}){}<>)<>}({}(()()()()()){}<>)<>}<>{({}<>)<>}<>
Gosh, it's nice to finally check this off my to-do list.
Explanation:
Brain-Flak is obviously not very good at getting the modulo of numbers, so I bypassed this by pushing all the elements first.
(((()()()()()){}){}) Push 20
{ Loop 20 times
({}
[(()())] Push a 2 to represent a Buzz
((((())))) Push 4 1s
) And decrement loop counter
}{} Pop the excess 0
{ Loop over the list of numbers
({}<>)<>({}<>)<> Transfer two of the elements to the other stack
({}()()<>)<> And add 2 to the last one
}<>{}{} Pop the excess two elements
Now 1 represents normal numbers, 2 represents Buzz, 3 is Fizz and 4 represents FizzBuzz. Initially I just pushed the values that repeat every 15 numbers 7 times and popped the excess 5, but this way turned out to be slightly shorter.
{ Loop over each element
([{}]()) Subtract one from the current element
({ Fizz and/or Buzz if num is not 1
<(({}())()) Subtract 1 and push, twice
{ Push Buzz if num was not 3
(<{}>)((((()()()())())((((({}{}){})[()]){}){}()))){({}<>)<>}
}{}
{ Push Fizz if num is not 2
(<{}>)(((((()()()())({})){}())(({})({}())({}{})))){({}<>)<>}
}
>
()
}{}[()]) Push -1 if neither Fizz nor Buzz were pushed
{
([](<>)) Push length of list to other stack
<>((()()()()()){}) Push 10 as the mod
Div/mod algorithm
{(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}<>)<>
Pushes n%10 to output stack and n/10 to the list stack
{ If div is not 0
({}<>) Push it to the other stack
(<>) Push 0
}
}{} Pop excess 0
(<>)<> Push 0 to other stack to represent a newline
}<>{} Pop extra newline
{ Loop over values
{
({}((((()()()){}){}){}){}<>)<> Add 48 to every value
}
({}(()()()()()){}<>)<> Turn 0s into newlines
} Until there's two 0s in a row
<>{({}<>)<>}<> Reverse output
Whitespace, 307 bytes
[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T S S S _Add][S N
S _Duplicate][S N
S _Duplicate][S S S T T N
_Push_3][T S T T _Modulo][N
T S T N
_Jump_to_Label_FIZZ_if_0][N
S S S N
_Create_Label_RETURN_FIZZ][S N
S _Duplicate][S N
S _Duplicate][S S S T S T N
_Push_5][T S T T _Modulo][N
T S T T N
_Jump_to_Label_BUZZ_if_0][N
S S S S N
_Create_Label_RETURN_BUZZ][S S S T T S S T S S N
_Push_100][T S S T _Subtract][N
T S T T T N
_Jump_to_Label_EXIT_WITH_ERROR_if_0][N
S T T T T T N
_Call_Label_PRINT_INT][S S S T S T S N
_Push_10][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP][N
S S T
_Create_Label_FIZZ][S S S T S S S T T S N
_Push_70][T N
S S _Print_as_character][S S S T T S T S S T N
_Push_105][T N
S S _Print_as_character][S S S T T T T S T S N
_Push_122][S N
S _Duplicate][T N
S S _Print_as_character][T N
S S _Print_as_character][N
S N
S
_Return_to_Label_FIZZ_RETURN][N
S S T T N
_Create_Label_BUZZ][S S S T S S S S T S N
_Push_66][T N
S S _Print_as_character][S S S T T T S T S T N
_Push_117][T N
S S _Print_as_character][S S S T T T T S T S N
_Push_122][S N
S _Duplicate][T N
S S _Print_as_character][T N
S S _Print_as_character][N
S N
S S N
_Return_to_Label_BUZZ_RETURN][N
S S T T T T N
_Create_Label_PRINT_INT][S N
S _Duplicate][S S S T T N
_Push_3][T S T T _Modulo][N
T S S T N
_Jump_to_Label_LOOP_if_0][S N
S _Duplicate][S S S T S T N
_Push_5][T S T T _Modulo][N
T S S T N
_Jump_to_Label_LOOP_if_0][T N
S T _Print_as_integer][N
T N
_Return][N
S S S T N
_Create_Label_RETURN][N
T N
_Return]
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Can definitely be golfed. If-checks are rather annoying in Whitespace, and I still have to get used to them some more.
EDIT: Fixed TIO version. Will try to golf it some more later.
General explanation in Pseudo-code:
Integer i = 0
Start LOOP
Increase i by 1
If i modulo 3 is 0: Call function FIZZ()
If i modulo 5 is 0: Call function BUZZ()
If i is 100: Stop program
Call function PRINT_INT(i)
Print new-line
Go to next iteration of the LOOP
function FIZZ():
Print "Fizz"
Return
function BUZZ():
Print "Buzz"
Return
function PRINT_INT(integer i):
If i modulo 3 is 0: Return
If i modulo 5 is 0: Return
Print i
Return
Example run:
Command Explanation Stack STDOUT STDERR
SSSN Push 0 [0]
NSSN Create Label_LOOP [0]
SSSTN Push 1 [0,1]
TSSS Add (0+1) [1]
SNS Duplicate (1) [1,1]
SNS Duplicate (1) [1,1,1]
SSSTTN Push 3 [1,1,1,3]
TSTT Modulo (1%3) [1,1,1]
NTSTN Jump to Label_FIZZ if 0 [1,1]
NSSSSN Create Label_RETURN_FIZZ [1,1]
SNS Duplicate (1) [1,1,1]
SNS Duplicate (1) [1,1,1,1]
SSSTSTn Push 5 [1,1,1,1,5]
TSTT Modulo (1%5) [1,1,1,1]
NTSTTN Jump to Label_BUZZ if 0 [1,1,1]
NSSSSN Create Label_RETURN_BUZZ [1,1,1]
SSSTTSSTSSN Push 100 [1,1,1,100]
TSST Subtract (1-100) [1,1,-99]
NTSTTTN Jump to Label_EXIT if 0 [1,1]
NSTTTTTN Call Label_PRINT_INT [1,1]
NSSTTTTN Create Label_PRINT_INT [1,1]
SNS Duplicate (1) [1,1,1]
SSSTTN Push 3 [1,1,1,3]
TSTT Modulo (1%3) [1,1,1]
NTSSTN Jump to Label_RETURN if 0 [1,1]
SNS Duplicate (1) [1,1,1]
SSSTSTN Push 5 [1,1,1,5]
TSTT Modulo (1%5) [1,1,1]
NTSSTN Jump to Label_RETURN if 0 [1,1]
TNST Print as integer [1] 1
NTN Return [1]
SSSTSTSN Push 10 [1,10]
TNSS Print as character [1] \n
NSNN Jump to Label_LOOP [1]
SSSTN Push 1 [1,1]
TSSS Add (1+1) [2]
SNS Duplicate (2) [2,2]
SNS Duplicate (2) [2,2,2]
SSSTTN Push 3 [2,2,2,3]
TSTT Modulo (2%3) [2,2,2]
NTSTN Jump to Label_FIZZ if 0 [2,2]
NSSSSN Create Label_RETURN_FIZZ [2,2]
SNS Duplicate (2) [2,2,2]
SNS Duplicate (2) [2,2,2,2]
SSSTSTn Push 5 [2,2,2,2,5]
TSTT Modulo (2%5) [2,2,2,2]
NTSTTN Jump to Label_BUZZ if 0 [2,2,2]
NSSSSN Create Label_RETURN_BUZZ [2,2,2]
SSSTTSSTSSN Push 100 [2,2,2,100]
TSST Subtract (2-100) [2,2,-98]
NTSTTTN Jump to Label_EXIT if 0 [2,2]
NSTTTTTN Call Label_PRINT_INT [2,2]
NSSTTTTN Create Label_PRINT_INT [2,2]
SNS Duplicate (2) [2,2,2]
SSSTTN Push 3 [2,2,2,3]
TSTT Modulo (2%3) [2,2,2]
NTSSTN Jump to Label_RETURN if 0 [2,2]
SNS Duplicate (2) [2,2,2]
SSSTSTN Push 5 [2,2,2,5]
TSTT Modulo (2%5) [2,2,2]
NTSSTN Jump to Label_RETURN if 0 [2,2]
TNST Print as integer [2] 2
NTN Return [2]
SSSTSTSN Push 10 [2,10]
TNSS Print as character [2] \n
NSNN Jump to Label_LOOP [2]
SSSTN Push 1 [2,1]
TSSS Add (3+1) [3]
SNS Duplicate (3) [3,3]
SNS Duplicate (3) [3,3,3]
SSSTTN Push 3 [3,3,3,3]
TSTT Modulo (3%3) [3,3,0]
NTSTN Jump to Label_FIZZ if 0 [3,3]
NSST Create Label_FIZZ [3,3]
SNS Duplicate (3) [3,3,3]
SNS Duplicate (3) [3,3,3,3]
SSSTSSSTTSN Push 70 [3,3,3,3,70]
TNSS Print as character [3,3,3,3] F
SSSTTSTSSTN Push 105 [3,3,3,3,122]
TNSS Print as character [3,3,3,3] i
SSSTTTTSTSN Push 122 [3,3,3,3,122]
SNS Duplicate (122) [3,3,3,3,122,122]
TNSS Print as character [3,3,3,3,122] z
TNSS Print as character [3,3,3,3] z
NSNS Jump to Label_RETURN_FIZZ [3,3,3,3]
NSSSSN Create Label_RETURN_FIZZ [3,3,3,3]
SSSTSTN Push 5 [3,3,3,3,5]
TSTT Modulo (3%5) [3,3,3,3]
NTSTTN Jump to Label_BUZZ if 0 [3,3,3]
NSSSSN Create Label_RETURN_BUZZ [3,3,3]
SSSTTSSTSSN Push 100 [3,3,3,100]
TSST Subtract (3-100) [3,3,-97]
NTSTTTN Jump to Label_EXIT if 0 [3,3]
NSTTTTTN Call Label_PRINT_INT [3,3]
NSSTTTTN Create Label_PRINT_INT [3,3]
SNS Duplicate (3) [3,3,3]
SSSTTN Push 3 [3,3,3,3]
TSTT Modulo (3%3) [3,3,0]
NTSSTN Jump to Label_RETURN if 0 [3,3]
Stack contains additional leading [3, but we'll ignore it in this explanation
SSSTN Push 1 [3,1]
TSSS Add (3+1) [4]
SNS Duplicate (4) [4,4]
SNS Duplicate (4) [4,4,4]
SSSTTN Push 3 [4,4,4,3]
TSTT Modulo (4%3) [4,4,1]
NTSTN Jump to Label_FIZZ if 0 [4,4]
NSSSSN Create Label_RETURN_FIZZ [4,4]
SNS Duplicate (4) [4,4,4]
SNS Duplicate (4) [4,4,4,4]
SSSTSTN Push 5 [4,4,4,4,5]
TSTT Modulo (4%5) [4,4,4,4]
NTSTTN Jump to Label_BUZZ if 0 [4,4,4]
NSSSSN Create Label_RETURN_BUZZ [4,4,4]
SSSTTSSTSSN Push 100 [4,4,4,100]
TSST Subtract (4-100) [4,4,-96]
NTSTTTN Jump to Label_EXIT if 0 [4,4]
NSTTTTTN Call Label_PRINT_INT [4,4]
NSSTTTTN Create Label_PRINT_INT [4,4]
SNS Duplicate (4) [4,4,4]
SSSTTN Push 3 [4,4,4,3]
TSTT Modulo (4%3) [4,4,1]
NTSSTN Jump to Label_RETURN if 0 [4,4]
SNS Duplicate (4) [4,4,4]
SSSTSTN Push 5 [4,4,4,5]
TSTT Modulo (4%5) [4,4,4]
NTSSTN Jump to Label_RETURN if 0 [4,4]
TNST Print as integer [4] 4
NTN Return [4]
SSSTSTSN Push 10 [4,10]
TNSS Print as character [4] \n
NSNN Jump to Label_LOOP [4]
SSSTN Push 1 [4,1]
TSSS Add (4+1) [5]
SNS Duplicate (5) [5,5]
SNS Duplicate (5) [5,5,5]
SSSTTN Push 3 [5,5,5,3]
TSTT Modulo (5%3) [5,5,2]
NTSTN Jump to Label_FIZZ if 0 [5,5]
NSSSSN Create Label_RETURN_FIZZ [5,5]
SNS Duplicate (5) [5,5,5]
SNS Duplicate (5) [5,5,5,5]
SSSTSTN Push 5 [5,5,5,5,5]
TSTT Modulo (5%5) [5,5,5,0]
NTSTTN Jump to Label_BUZZ if 0 [5,5,5]
NSSTTN Create Label_BUZZ [5,5,5]
SSSTSSSSTSN Push 66 [5,5,5,66]
TNSS Print as character [5,5,5] B
SSSTTTSTSTN Push 117 [5,5,5,117]
TNSS Print as character [5,5,5] u
SSSTTTTSTSN Push 122 [5,5,5,122]
SNS Duplicate (122) [5,5,5,122,122]
TNSS Print as character [5,5,5,122] z
TNSS Print as character [5,5,5] z
NSNS Jump to Label_RETURN_FIZZ [5,5,5]
NSSSSN Create Label_RETURN_BUZZ [5,5,5]
SSSTTSSTSSN Push 100 [5,5,5,100]
TSST Subtract (5-100) [5,5,-95]
NTSTTTN Jump to Label_EXIT if 0 [5,5]
NSTTTTTN Call Label_PRINT_INT [5,5]
NSSTTTTN Create Label_PRINT_INT [5,5]
SNS Duplicate (5) [5,5,5]
SSSTTN Push 3 [5,5,5,3]
TSTT Modulo (5%3) [5,5,2]
NTSSTN Jump to Label_RETURN if 0 [5,5]
SNS Duplicate (5) [5,5,5]
SSSTSTN Push 5 [5,5,5,5]
TSTT Modulo (4%5) [5,5,0]
NTSSTN Jump to Label_RETURN if 0 [5,5]
... etc. etc.
SSSTN Push 1 [99,1]
TSSS Add (99+1) [100]
SNS Duplicate (100) [100,100]
SNS Duplicate (100) [100,100,100]
SSSTTN Push 3 [100,100,100,3]
TSTT Modulo (100%3) [100,100,1]
NTSTN Jump to Label_FIZZ if 0 [100,100]
NSSSSN Create Label_RETURN_FIZZ [100,100]
SNS Duplicate (100) [100,100,100]
SNS Duplicate (100) [100,100,100,100]
SSSTSTN Push 5 [100,100,100,100,5]
TSTT Modulo (100%5) [100,100,100,0]
NTSTTN Jump to Label_BUZZ if 0 [100,100,100]
NSSTTN Create Label_BUZZ [100,100,100]
SSSTSSSSTSN Push 66 [100,100,100,66]
TNSS Print as character [100,100,100] B
SSSTTTSTSTN Push 117 [100,100,100,117]
TNSS Print as character [100,100,100] u
SSSTTTTSTSN Push 122 [100,100,100,122]
SNS Duplicate (122) [100,100,100,122,122]
TNSS Print as character [100,100,100,122] z
TNSS Print as character [100,100,100] z
NSNS Jump to Label_RETURN_FIZZ [100,100,100]
NSSSSN Create Label_RETURN_BUZZ [100,100,100]
SSSTTSSTSSN Push 100 [100,100,100,100]
TSST Subtract (100-100) [100,100,0]
NTSTTTN Jump to Label_EXIT if 0 [100,100] error
brainfuck, 206 bytes
++>+++++>>>>>++++++++++[>+>>+>>+>+<<<[++++<-<]<,<,-<-<++<++++[<++>++++++>]++>>]>
[+[[<<]<[>>]+++<[<.<.<..[>]]<<-[>>>[,>>[<]>[--.++<<]>]]+++++<[+[-----.++++<<]>>+
..<-[>]]<[->>,>+>>>->->.>]<<]<[>+<<<,<->>>+]<]
Formatted:
++>+++++>>>>>
++++++++++[>+>>+>>+>+<<<[++++<-<]<,<,-<-<++<++++[<++>++++++>]++>>]
>
[
+
[
[<<]
<[>>]
+++<
[
Fizz
<.<.<..
[>]
]
<<-
[
>>>
[
,>>[<]
>[--.++<<]
>
]
]
+++++<
[
Buzz
+[-----.++++<<]
>>+..
<-
[>]
]
<[->>,>+>>>->->.>]
<<
]
<[>+< <<,<->>>+]
<
]
The memory layout is
0 a 122 105 70 b f 0 t d1 s d2 c d 10 0
where f cycles by 3, b cycles by 5, d1 is ones digit, d2 is tens digit, s is a flag for whether to print tens digit, d cycles by 10, c is copy space for d, t is working space that holds 0 or junk data or a flag for not-divisible-by-3, and a determines program termination by offsetting the pointer after Buzz has been printed 20 times.
Pyret, 150 bytes
d={(a,b):if num-modulo(a,b) == 0:if b == 3:"Fizz"else:"Buzz" end else:""end}
each({(y):q=d(y,3) + d(y,5)
print(if q == "":y else:q end)},range(1,101))
You can try this online by copying it into the online Pyret editor!
Pyret is a language designed with education in mind, so there's a couple things it enforces to keep things readable in normal programs. This explains why some of the operators are surrounded by spaces and the presence of newlines in the program.
The {(...): ...} syntax is shorthand for lambda expressions, which gives us the following ungolfed version:
d = lam(a,b):
if num-modulo(a,b) == 0:
if b == 3:
"Fizz"
else:
"Buzz"
end
else:
""
end
end
each(
lam(y):
q = d(y,3) + d(y,5)
print(
if q == "":
y
else:
q
end)
end,
range(1,101))
QB64, 102 94 bytes
FOR i=1TO 100
o$=MID$("Fizz",i*5MOD 15)+MID$("Buzz",i*5MOD 25)
IF""<o$THEN?o$ELSE WRITE i
NEXT
Doesn't work on actual QBasic; see below for why.
This program has one problem: QBasic/QB64 outputs to an 80x24 window, not a terminal, so the results can't be scrolled back. If you run the above code as-is, all you'll see is the lines from 78 onward. To prove that the code does 1 to 100 correctly, you can add the line SLEEP 1 right before NEXT for a 1-second delay on each iteration.
Ungolfed code and explanation
FOR i = 1 TO 100
index = 5 * (i MOD 3)
o$ = MID$("Fizz", index)
index = 5 * (i MOD 5)
o$ = o$ + MID$("Buzz", index)
IF "" < o$ THEN
PRINT o$
ELSE
WRITE i
END IF
NEXT
On each iteration, we put the appropriate fizzes and buzzes into the string o$, check if it's empty, and output o$ or the number accordingly. The main question is how to get "Fizz" when i is divisible by 3 and "" otherwise. Here are the approaches I tried:
IF i MOD 3THEN o$=""ELSE o$="Fizz"
o$="":IF i MOD 3=0THEN o$="Fizz"
o$=MID$("Fizz",5*(i MOD 3))
o$=MID$("Fizz",i*5MOD 15)
The approach with MID$ is much shorter. This function takes 3 arguments--string, start index, and number of characters--and returns the appropriate substring. When the third argument is omitted, it takes everything from the start index to the end of the string. Here, when i is exactly divisible, the start index is 0 and we get the whole string; otherwise, it's something larger that's past the end of the string, so MID$ gives "".1
The other tricky part is printing numbers according to the spec. QBasic's PRINT command outputs positive numbers with leading spaces, which is occasionally useful but usually just annoying. The WRITE command, however, does not add a leading space--perfect for our purposes here.
1 Strings are 1-indexed in QBasic--i.e., in the string "abcd", a is at index 1 and d is at index 4. This is why I'm multiplying the mod result by 5: MID$("Fizz",4) gives "z". In actual QBasic, 0 isn't a legal index and gives Illegal function call; but in QB64, MID$("Fizz",0) happily returns the whole string instead of complaining.
Common Lisp, 103 101 96 93 84 bytes
(dotimes(i 101)(format t"~v^~[Fizz~[Buzz~]~:;~[Buzz~:;~a~]~]
"i(mod i 3)(mod i 5)i))
It's shorter than other CL solution and it uses different method. Conditions are handled inside format function.
-5 bytes - shorter version of handling i=0
-3 bytes - ~^ with only one parameter seems to work as if second parameter was 0, which is saves 2 bytes. Last byte is saved by substituting ~% by <enter>
-9 bytes - by ASCII-only
Ada (GNAT), 196 bytes
procedure GNAT.IO.F is begin for I in Integer range 1..100 loop Put((if I mod 3=0 then"Fizz"else"")&(if I mod 5=0 then"Buzz"else""));if I mod 3*I mod 5/=0 then Put(I);end if;New_Line;end loop;end;
189 bytes if extraneous whitespace is allowed:
procedure GNAT.IO.F is begin for I in Integer range 1..100 loop Put(if I mod 3=0 then(if I mod 5=0 then"FizzBuzz"else"Fizz")else(if I mod 5=0 then"Buzz"else I'Image));New_Line;end loop;end;
ORACLE SQL (107 bytes)
select nvl(decode(mod(rownum,3),0,'Fizz')||decode(mod(rownum,5),0,'Buzz'),rownum)from xmltable('1 to 100')
Phooey, 57 bytes
&1[101>&0<@@%3{"Fizz">&1<}&%5{"Buzz">&1<}&>{<$i>}$c10<+1]
Explanation
&1 set current cell to 1
[101 until that cell is 101:
>&0< zero the cell to the right
@@ push two copies of the current cell to the stack
%3{"Fizz">&1<} if it's divisible by 3, print "Fizz"
&%5{"Buzz">&1<} if it's divisible by 5, print "Buzz"
& restore cell
>{<$i>} if it's not, print the restored cell
$c10 print a newline
<+1 increment the current cell
]
Go, 130 129 134 bytes
package main;import."fmt";func main(){for i:=1;i<101;i++{o:="";if i%3<1{o+="Fizz"};if i%5<1{o+="Buzz"};if o==""{Print(i)};Println(o)}}
I wish i had ternary operators...
Edit:
@Dust pointed out that I printed to stderr so my solution actually increased in size :(
Transact-SQL, 163 143 124 110 bytes
This requires SQL Server 2012+
(thanks MickyT for the unnamed variable and the IIF suggestions, changed to muqo's GOTO loop instead of WHILE)
declare @ int=1a:print iif(@%3*@%5>0,ltrim(@),iif(@%3=0,'Fizz','')+iif(@%5=0,'Buzz',''))set @+=1IF @<101GOTO a
Formatted and explained:
declare @ int=1 --@ is a valid variable name
a: --shorter than WHILE
print iif(@%3*@%5>0, ltrim(@), --ltrim is shorter than explicit cast
iif(@%3=0,'Fizz','') --nest the IIFs
+ iif(@%5=0,'Buzz',''))
set @+=1
IF @<101 GOTO a
Forth, 107 101 98 bytes
: f 101 1 do i 5 mod i 3 mod if dup if i . then else ." Fizz" then 0= if ." Buzz" then cr loop ; f
Ungolfed + close Python equivalent:
: f \ def f():
101 1 do \ for i in range(1, 101):
i 5 mod \ a = i % 5 # Not an actual variable, pushed onto the stack
i 3 mod \ b = i % 3
if \ if b: # b is popped
dup \ c = a
if \ if c:
i . \ print(i, end='')
then
else \ else:
." Fizz" \ print('Fizz', end='')
then
0= \ a = (a == 0)
if \ if a:
." Buzz" \ print('Buzz', end='')
then
cr \ print()
loop
;
f \ f()
Ada (GNAT), 298 bytes
with Ada.Text_IO;use Ada.Text_IO;procedure T is begin for I in Integer range 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz");elsif I mod 3 = 0 then Put_Line ("Fizz");elsif I mod 5 = 0 then Put_Line ("Buzz");else Put_Line (Integer'Image (I)(2 ..Integer'Image(I)'Last));end if; end loop; end T;
Ungolfed:
with Ada.Text_IO;use Ada.Text_IO;
procedure Test is begin
for I in Integer range 1 .. 100 loop
if I mod 15 = 0 then
Put_Line ("FizzBuzz");
elsif I mod 3 = 0 then
Put_Line ("Fizz");
elsif I mod 5 = 0 then
Put_Line ("Buzz");
else
Put_Line (Integer'Image (I)(2 .. Integer'Image(I)'Last));
end if;
end loop;
end Test;
Pretty vanilla, but I didn't see an Ada solution yet. Probably because Ada might just be the worst real-world language to golf with!
///, 198 bytes
/%/!"
//$/
"!//#/
Fizz"
//"/Buzz//!/
Fizz
/1
2!4$7
8%11!13
14#16
17!19$22
23%26!28
29#31
32!34$37
38%41!43
44#46
47!49$52
53%56!58
59#61
62!64$67
68%71!73
74#76
77!79$82
83%86!88
89#91
92!94$97
98!"
Jstx, 36 bytes
₧&0←+☺:@♥>ø↕₧K2→+◙♣>ø↕₧O2→+◙%↓2◙∟416
Explanation
₧& # Push literal 100
0 # Enter an iteration block over the first stack value and push the iteration element register at the beginning of each loop.
← # Push literal false
+ # Store the first stack value in the a register.
☺ # Push literal 1
: # Push the sum of the second and first stack values.
@ # Push three copies of the first stack value.
♥ # Push literal 3
> # Push the modulus of the second and first stack values.
ø # Push literal 0
↕ # Enter a conditional block if the top two stack values are equal.
₧K # Push literal Fizz
2 # Print the first stack value.
→ # Push literal true
+ # Store the first stack value in the a register.
◙ # End a conditional block.
♣ # Push literal 5
> # Push the modulus of the second and first stack values.
ø # Push literal 0
↕ # Enter a conditional block if the top two stack values are equal.
₧O # Push literal Buzz
2 # Print the first stack value.
→ # Push literal true
+ # Store the first stack value in the a register.
◙ # End a conditional block.
% # Push the value contained in the a register.
↓ # Enter a conditional block if first stack value exactly equals false.
2 # Print the first stack value.
◙ # End a conditional block.
∟ # Push literal null
4 # Print the first stack value, then a newline.
1 # End an iteration block.
6 # Ends program execution.
TIS, 573 + 48 = 621 bytes
Code (573 bytes):
@0
MOV ANY DOWN
MOV ANY RIGHT
@1
MOV ANY DOWN
ADD DOWN
MOV ANY DOWN
ADD DOWN
MOV ANY LEFT
MOV LEFT DOWN
ADD DOWN
@2
SUB 101
JLZ C
HCF
C:ADD 102
MOV ACC LEFT
@3
MOV ANY DOWN
MOV ANY UP
@4
MOV UP DOWN
MOV ANY UP
MOV UP DOWN
MOV ANY UP
MOV UP DOWN
MOV ANY UP
MOV UP DOWN
MOV ANY UP
MOV UP RIGHT
MOV ANY DOWN
MOV ANY UP
@5
MOV ANY DOWN
MOV ANY LEFT
@6
ADD UP
MOV 70 DOWN
MOV 105 DOWN
MOV 122 DOWN
MOV 122 DOWN
MOV 0 UP
@7
MOV UP ACC
JEZ N
MOV ACC DOWN
N:MOV -1 RIGHT
MOV 0 UP
@8
MOV ANY ACC
JLZ N
MOV 66 DOWN
MOV 117 DOWN
MOV 122 DOWN
MOV 122 DOWN
MOV 0 UP
JRO -7
N:MOV 10 DOWN
Layout (48 bytes):
3 3
CCCCCCCCC
O0 ASCII -
O1 NUMERIC -
O2 ASCII -
Explanation
I think my TIS emulator is ready for its debut! This is an emulator inspired by (and based on) the wonderful game TIS-100. However, where the game only emulates the 100 model of the TIS series, I have designed this emulator to reflect the full range of possibilities.
The code is in the format standardized by the game; we'll get to that in a bit. But first, the layout description just below that.
Layout
This is a specification for which model and configuration within the TIS range we desire. Whereas the model in the game (also called TIS-100) is only found in a 3 rows by 4 columns layout, for this solution I require something different.
I desire a 3 by 3 square instead. Since there are multiple types of nodes that can fall in each slot, I specify that all nine are Compute nodes (other types include e.g. stack memory).
In a TIS, the top row of nodes may read in input from above themselves (if so configured) and the bottom row may write below themselves to perform output (again, if so configured). For this challenge, no Inputs are needed, but I desire three different Outputs, corresponding to the three columns in this layout.
The first and third column outputs (O0 and O2) are each in ASCII mode; this means that they will translate the internal numeric type to an ASCII character when performing output. The center column (O1) is a NUMERIC output, meaning that the values sent to this output will instead be written out as a number. In all cases, we want the data to go to stdout (-).
Putting all this together gives the layout file seen above.
Code
TIS assembly code is stored in a flat file, as seen above. The code under the heading @0 will go in the first compute node, @1 in the second compute node, and so on. The layout in this solution looks like this:
0 1 2
3 4 5
6 7 8
Since each compute node only has capacity for 15 lines of code, my solution distributes the primary logic across 6 different nodes (the other three just bus data back and forth). Those 6 nodes are as follows:
Node @2, the top right, is the counter, counting 1 through 100, and terminating execution (HCF) upon reaching 101.
Node @1, the top center, sends every third number left (for Fizz), and all numbers down.
Node @6, the bottom left, produces "Fuzz" when given any number.
Node @4, the true center, sends every fifth number right (for Buzz), and all numbers down.
Node @8, the bottom right, produces "Buzz" when given a non-negative number and "\n" otherwise.
Node @7, the bottom center, produces a number if that number hasn't already been Fizzed or Buzzed (or both), and then requests a newline to be printed.
It is quite possible that this is not yet a fully optimal golf, but this is also the first golf I've done for TIS.
Hexagony, 77 76 bytes
=?3})"F\>%'5?\"\B;u;"}/4;d'%<>\g/"!{{\}.%<@>'...<>,}/${;;z;i;z;;$/<>?{$/"./_
Same side length as M L's solution, but a bit smaller.
Expanded:
= ? 3 } ) "
. \ > % ' 5 ?
\ F \ B ; u ; "
} " / ; d ' % < >
\ g 4 / ! { { \ } .
% < @ . > " ' . < > ,
} / $ { ; ; z ; i ;
z ; ; $ / < > ? {
$ / " . / _ . .
. . . . . . .
. . . . . .
Coloured 77 byte version (only difference is the bottom right corner):
- Green: The general outline of the loop
- Light Blue: "Fizz" printer
- Dark Blue: "Buzz" printer
- Yellow: Number printer
- Red: Terminator path
How it Works:
Memory Model:
- Num: The counter
- Mod: The number we are moduloing(?) with the counter
- Temp: Our calculation edge
- Check: The FizzBuzz check
Below I'll be referring to the instructions as they are executed, ignoring no-ops and direction changes.
At the start we execute =?3})"%< which increments the counter (initially 0) and checks whether it is divisible by 3. If so, we branch up and execute "F;i;z;;{ which prints "Fizz" in the check edge and returns to the temp edge.
}?5'%>: Now we check if the number is divisible by 5. If so, B;u;"z;; prints "Buzz" in the check edge (the " is out of place to prevent printing an excess character at termination). If not, we execute an extra instruction to switch to the check edge.
If Fizz and/or Buzz has been printed, the check edge has a leftover "z" in it, else it is 0. If it is a 0, we execute z{{!"'} which puts a z in the check edge and prints the number before returning to the check edge and executing the check again. Now the check edge has a "z" in it no matter what, so we branch to the ?{}g4; which prints a newline.
Finally, d'% checks if the number is divisible by 100. If so, it terminates. Otherwise, it moves to the start of the loop.
sed, 275 272 270 260 254 249 245 bytes
s/.*/t0u123456789/
:1
s/(tu?(.).*)/\1\n\2/
s/u(.)(t?)(.*)/\1\2u\3\1/
/9u/{s/t(.)/\1t/;s/u//;s/^/u/}
/99/!b1
s/$/\n10/
s/[0-9][05]/&Buzz/g
s/[0369]{2}/&Fizz/g
s/[147][258]/&Fizz/g
s/[258][147]/&Fizz/g
s/[0-9]+([FB])/\1/g
s/\n0/\n/g
s/[^\n]+\n//
q
This is a pure sed script which discards all input, if any, and then prints all the necessary output lines and quits.
Explanation
The script is divided into a sequence of three main parts: 1. Numeral generation; 2. "Fizz/Buzz/FizzBuzz" insertion; and 3. Formatting.
1. Numeral generation (lines 1 through 6)
The purpose of this part is to generate 99 lines containing the base 10 numerals corresponding to numbers 1 through 99. For that, we first set the entire pattern space to the following string:
t0u123456789
We will call the above string our state string. Next, we enter a loop in which each iteration goes like this:
- A newline is appended to the pattern space;
- A copy of the first numeral character after the "t" in the state string is appended to the pattern space;
- A copy of the first numeral character after the "u" in the state string is appended to the pattern space;
- The "u" in the state string is moved from its current position to the immediate right of the first numeral character after it or, if a "t" is already in said position, the "u" is instead moved to the immediate right of that "t";
- If the "u" in the state string is immediately at the right of the "9" in the state string, the "t" is moved from its current position to the immediate right of the first character after it, and the "u" is moved from its current position to the immediate left of the "0" in the state string;
- If there isn't a "99" anywhere in the pattern space (i.e., the loop has not finished its job of generating all the 99 lines), control goes back to line 2 (label :1) and so this enumeration of procedures is repeated from step 1; otherwise, control flow continues into the next line.
2. "Fizz/Buzz/FizzBuzz" insertion (lines 7 through 11)
The purpose of this part is to append "Fizz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 3 but not of 5; to append "Buzz" immediately after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of 5 but not of 3; and to append "FizzBuzz" after each two-digit numeral in the pattern space which corresponds to a number which is a multiple of both 3 and 5. This is how the computations go:
- We append a newline followed by "10" to the pattern space.
- Next, we search for all substrings of the pattern space formed by a digit between 0-9 on the left and either a 0 or a 5 on the right. We insert "Buzz" into the pattern space immediately after each such substring;
- Finally, we insert "Fizz" into the pattern space immediately after each substring which matches either of the following criteria:
- Substrings formed by two digits which may be 0, 3, 6, or 9;
- Substrings formed by a digit which is either 1, 4 or 7 on the left and a digit which is either 2, 5 or 8 on the right;
- Substrings formed by a digit which is either 2, 5 or 8 on the left and a digit which is either 1, 4 or 7 on the right.
3. Formatting (lines 12 through 15)
This part is straight forward. Here we remove all of the following substrings from the pattern space:
- Every contiguous sequence of numeral characters on the immediate left of a "F" or a "B";
- All 0's on the immediate right of a newline character;
- All characters from the beginning of the pattern space up to and including the first newline character (remember that the state string is still there and there's a newline immediately before the first output numeral).
And then sed just prints the final contents of the pattern space and calls it quits.
Husk, 35 bytes
m§Ysλṁ!⁰₇ḣ3)ḣ100
¶Σfm%⁰NC2¨¶¶¶⌈iΩZu
I feel like I'm missing some opportunities for cleverness here. Like, I'm not really pleased with that lambda sitting there on the first line and having to be manually closed. But anyway, here we are.
Explanation
I'll explain the second line first. It's a function TNum -> [[TChar]] that maps
1 -> []
2 -> ["","","Fizz"]
3 -> ["","","","","Buzz"]
It works like this:
¶Σfm%⁰NC2¨¶¶¶⌈iΩZu
¨¶¶¶⌈iΩZu --The compressed string "\n\n\n\nFiBuzz"
C2¨¶¶¶⌈iΩZu --cut; the list ["\n\n", "\n\n", "Fi", "Bu", "zz]
m%⁰N --nats mod input, i.e, with input 3, [1,2,0,1,2,...]
fm%⁰NC2¨¶¶¶⌈iΩZu --filter;so grab (1) nothing, (2) pairs 135, (3) pairs 1245
Σfm%⁰NC2¨¶¶¶⌈iΩZu --concat;now at (1) [] (2) ["\n\nFizz"] (3) ["\n\n\n\nBuzz"]
¶Σfm%⁰NC2¨¶¶¶⌈iΩZu --split by newlines to return claimed result
Next, the lambda in the first line. It has type TNum -> [TChar]; given an integer, it returns "", "Fizz", "Buzz", or "FizzBuzz" as appropriate. In detail:
λṁ!⁰₇ḣ3)
ḣ3 --heads; the list [1,2,3]
₇ḣ3 --call 2nd line with map overflow: [[],["","","Fizz"],["","","","","Buzz"]]
ṁ!⁰₇ḣ3 --index the lambda argument to each list (modularly) and concat the results
And pulling it together:
m§Ysλṁ!⁰₇ḣ3)ḣ100
λṁ!⁰₇ḣ3) --"","Fizz","Buzz",or"FizzBuzz"
s --string representation of the number
§Ysλṁ!⁰₇ḣ3) --apply both and take max; "" < numeric strings < alphabet
m§Ysλṁ!⁰₇ḣ3)ḣ100 --map across [1,..,100]
Then Husk's default output style for an object of type [[TChar]] turns out to be just what we want.
brainfuck, 411 350 277 258 bytes
Edits:
-61 bytes by storing the values of "Fizz Buzz" as
"BuziF""BuziG" and redoing the number printing section.-71 bytes by redoing the modulo number printing section, splitting the loop counter and the number counter, and reusing the newline cell as the mod value, among other things
-19 bytes by realising that there aren't any 0s in any FizzBuzz numbers. Also added explanation
+[-[>+<<]>-]>--[>+>++>++>++++++>+>>>++++++[<<<]>-]<+++++[>+>+>->>->++>>>-->>>++[<<<]>>>-]>[>]+++>>[>+<<<-[<]<[>+++>+<<-.+<.<..[<]<]>>-[<<]>[.>.>..>>>>+[<]+++++<]>[>]>>[[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[-<+>]>,>[>]<[>-[<+>-----]<---.,<]++++++++++>]<.<<<<,>-]
Instead of checking if the number itself was divisible by 5 or 3 I had two counters keeping track of the modulo of the number, decrementing them for each number and printing out the corresponding word when they reached 0.
How It Works:
+[-[>+<<]>-]>-- Generate the number 61
[>+>++>++>++++++>+>>>++++++[<<<]>-] Set the tape to multiples of 61
TAPE: 0 0' 61 122 122 110 61 0 0 110
"=" "z" "z" "n" "="
<+++++[>+>+>->>->++>>>-->>>++[<<<]>>>-]>[>]+++>> Modify values by multiples of 5
TAPE: 0' 5 66 117 122 105 71 3 0 100' 0 0 10
"B" "u" "z" "i" "G"
Some info:
5 - Buzz counter
"Buz" - Buzz printing
"ziG" - Fizz printing. Modifying the G in the loop is shorter than modifying it outside
3 - Fizz counter
0 - This is where the Fizz|Buzz check will be located
100 - Loop counter
0 - Number counter. It's not worth it to reuse the loop counter as this.
0 - Sometimes a zero is just a zero
10 - Value as a newline and to mod the number by
[ Loop 100 times
>+<<< Increment number counter
-[<]< Decrement Fizz counter
[ If Fizz counter is 0
>+++ Reset the Fizz counter to 3
>+<< Set the Fizz|Buzz check to true
-.+<.<.. Print "Fizz"
[<]<] Sync pointers
>>-[<<]> Decrement Buzz counter
[ If Buzz counter is 0
.>.>.. Print "Buzz"
>>>>+ Set the Fizz|Buzz check to true
[<]+++++< Reset the Buzz counter to 5
]
>[>]>> Go to Fizz|Buzz check
[ If there was no Fizz or Buzz for this number
TAPE: 3% BuziG 5% 0 Loop Num' 0 10
[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<] Mod the number counter by 10
TAPE: 3% BuziG 5% 0 Loop 0' Num 10-Num%10 Num%10 Num/10
>[-<+>] Move Num back in place
>,>[>]< Reset 10-Num%10
[ For both Num/10 (if it exists) and Num%10
>-[<+>-----]<--- Add 48 to the number to turn it into the ASCII equivilent
.,< Print and remove
]
++++++++++> Add the 10 back
]
<. Print the newline
<<<<, Remove Fizz|Buzz check
>- Decrement Loop counter
]
Befunge-93, 61 bytes
1+::::3%|>.#_:"c"`#@_55+,
,,:,,0\v>"ziF"
,:,,$01>>5%#v_"zuB",
Decided to come back to this and make it conform to specification while shaving some bytes off. Look, no extra spaces!
KoopaScript, 250 characters
def i 1 if \%va is \%vu set a 1;setath b \%va %% 3;setath c \%va %% 5;setath e \%va %% 15;if \%vb is 0 if \%vc not 0 print Fizz;if \%vb not 0 if \%vc is 0 print Buzz;if \%ve is 0 print FizzBuzz;if \%vb not 0 if \%vc not 0 print \%va;setath a \%va + 1
Guide to reading: Don't. Either learn KoopaScript more or less entirely by looking at the code (my documentation isn't that great) or just take my word for it that it works. By the way, KoopaScript is an interpreted language I made (not specifically for this) that runs inside ActionScript 2, and doesn't actually have else statements, or... most of the stuff that makes other examples short. All functions are one line, so this was pretty easy. Here's the GitHub repo.
Yabasic, 108 bytes
Yet Another basic answer.
For i=1To 100
S$=""
If!Mod(i,3)Then S$="Fizz"Fi
If!Mod(i,5)Then S$=S$+"Buzz"Fi
If S$=""Then?i Else?S$Fi
Next
Visual Basic .NET (Mono), 151 bytes
Module M
Sub Main
Dim i,s
For i=1To 100
s=""
s=IIf(i Mod 3,s,"Fizz")
s=IIf(i Mod 5,s,s+"Buzz")
Console.WriteLine(IIf(s="",i,s))
Next
End Sub
End Module
MY-BASIC, 116 bytes
A basic response.
For i=1 To 100
S=""
If i Mod 3=0 Then S="Fizz"
If i Mod 5=0 Then S=S+"Buzz"
If S="" Then Print i; Else Print S;
Next
SmileBASIC, 70 bytes
Printing "Fizz" and "Buzz" is easy, the slightly more difficult part is to only print the number when required. There are basically 2 ways to do this (and they end up being the same length)
1: Print the number when I isn't divisible by 3 or 5
FOR I=0TO 100A=I MOD 3B=I MOD 5?"Fizz"*!A;"Buzz"*!B;STR$(I)*(A&&B)NEXT
2: Print the number if the cursor is at column 0:
FOR I=1TO 100?"Fizz"*!(I MOD 3);"Buzz"*!(I MOD 3);
?STR$(I)*!CSRX
NEXT
In a previous version of SB, % was used for MOD, making the program shorter:
Petit Computer BASIC, 62 bytes
FOR I=0TO 100?"Fizz"*!(I%3);"Buzz"*!(I%5);
?STR$(I)*!CSRX
NEXT
Wumpus, 49 bytes
"zzuB"L)=S5%4*&;"zziF"L3%!!4*&;l=]&oL~!?ONL"d"-:.
Explanation
I haven't yet found a good way to write compact programs with branching control flow, so I decided to avoid branches altogether for this one (handling conditionals via skipping individual instructions). The program is a single line which is a run in a loop (because the . at the end skips back to the first character).
We'll be using the stack depth to determine whether Fizz and/or Buzz needs to be printed, so we can't keep the loop counter on the stack. Instead, we'll be using the default register for this (which is initialised to zero).
"zzuB" Tentatively push the code points for "Buzz" onto the stack.
L)=S Load the loop counter from the register, increment it, and store a
copy back in the register.
I'll call the loop counter for this iteration i.
5% Compute i % 5 to test divisibility by 5.
4* Multiply by 4. This gives 0 if 5 divides i, and some n ≥ 4 if it doesn't.
&; Discard that many values from the stack. Discarding from an empty
stack does nothing, so if 5 doesn't i, we get rid of "Buzz",
otherwise, we do nothing.
The code for "Fizz" is similar:
"zziF" Push the code points for "Fizz".
L3% Compute i % 3.
This time, we can't just discard n ≥ 4 values, but we have to
discard exactly 4 values, otherwise we might get rid of the "Buzz".
!! Double logical NOT. Gives 0 for 0 and 1 for positive values.
4* Multiply by 4. Now we've got 0 if 3 divides i and 4 otherwise.
&; Discard that many values to get rid of "Fizz" if 3 doesn't divide i.
l Push the stack depth D.
=] Make a copy for later and shift it to the bottom of the stack.
&o Print D characters from the top of the stack. If any of "Fizz" or
"Buzz" were left on the stack, this prints them. Otherwise, D = 0
and this does nothing.
L~ Load i and put it underneath D.
!?O If D = 0, print i (in decimal). Otherwise, i remains on the stack.
N Print a linefeed.
L"d"- Compute i-100. This is zero when we want to end the program.
: Compute i/(i-100). When we've reached i = 100, this terminates the
program due to the attempted division by zero. Otherwise, this
leaves some junk value X on the stack.
. Jump to (0, X), emptying the stack. But since it's impossible to
go out of bounds in Wumpus, the coordinates will automatically be
taken modulo the grid dimensions. Since the grid is only one row
tall, the y-coordinate becomes X%1 = 0, so regardless of X, this
always jumps back to the beginning of the program.
kavod, 688 bytes
535 9}122 2}122 2}105 2}70 2}4 2}122 3}122 3}117 3}66 3}4 3}1 0><-+0>~0~><3 66 9}165.86?<1+>><-+2 0 86 9}478.><-+><5 100 9}165.120?<1+>><-+3 0 120 9}478.><-+<140?><-+><139 9}392.0><-+1+><10#100 158 9}258.162?47.9{.171 9}178.><-+9{.0 8}0 8}8}9}8{9{1+8{>8}9}8{9{>214 9}276.218?241.><-+<7}><<+8{1+8}8}7{196.><-+<1-+<-8{1-9{.-265 9}318.1 273 9}296.9{.-283 9}318.0 1-293 9}296.9{.-303 9}318.307?313.><-9{.1+9{.323?9{.><1+331?359.8}9}8{9{1-345?355.8}9}8{9{325.1+363.1-363.8}9}8{9{><-+9{.0 8}9}8{9{-9{.396?451.><0 406 9}276.457?><-+418 9}421.9{.425?445.10 433 9}178.439 9}421.48+#9{.~0~9{.48+#9{.><-+45#469 9}378.475 9}421.9{.8}~><8}489?499.1-8}>#8{485.><-+8{><8}513?526.1-<8}9}8{9{509.8{+8{~9{.
Formatted better:
535 9}122 2}122 2}105 2}70 2}4 2}122 3}122 3}117 3}66 3}4 3}1 0><-+0>~0~><3 66 9}165.86?<1+>>
<-+2 0 86 9}478.><-+><5 100 9}165.120?<1+>><-+3 0 120 9}478.><-+<140?><-+><139 9}392.0><-+1+>
<10#100 158 9}258.162?47.9{.171 9}178.><-+9{.0 8}0 8}8}9}8{9{1+8{>8}9}8{9{>214 9}276.218?241.
><-+<7}><<+8{1+8}8}7{196.><-+<1-+<-8{1-9{.-265 9}318.1 273 9}296.9{.-283 9}318.0 1-293 9}296.
9{.-303 9}318.307?313.><-9{.1+9{.323?9{.><1+331?359.8}9}8{9{1-345?355.8}9}8{9{325.1+363.1-363
.8}9}8{9{><-+9{.0 8}9}8{9{-9{.396?451.><0 406 9}276.457?><-+418 9}421.9{.425?445.10 433 9}178
.439 9}421.48+#9{.~0~9{.48+#9{.><-+45#469 9}378.475 9}421.9{.8}~><8}489?499.1-8}>#8{485.><-+8
{><8}513?526.1-<8}9}8{9{509.8{+8{~9{.
Ok so I can only really explain this vaguely, but stacks 2 and 3 hold the strings Fizz and Buzz. The program loops is roughly equivalent to the following code:
push 0 ;dummy
:fb
drop
copy 0
dup
call divides 3
jif not3
load
add 1
copy
drop
call puts 2 0
:not3
drop
dup
call divides 5
jif not5
load
add 1
copy
drop
call puts 3 0
:not5
drop
load
jif cont
drop
dup
call putn
push 0
:cont
drop
add 1
dup
putc 10
call gt 100
jnt fb
ret
...just translated into pseudo-ops codes. Yeah. Then the rest of the program is defining sanity functions.
Guide to reading
J 9}N. usually means "call function at N, and return to J afterwards"; 9{. signifies this return.
17, 229 bytes
17 was made after the challenge was made, but not designed to be any good at it. This code could probably be golfed a bit smaller, but it is a reasonably hard language to do anything with. Golfed version(removed unneeded space and duplicated numbers where useful):
0{2 #
1 +
:
2 @
5g ==
1 +
0 @}1{2 # 3 % ! 3 *
2 # 5 % ! 5 *
+ 10 + 0 @}13{42 $ 63 $ 73 : $ $ a $
0 0 @}15{3f $ 6f $ 73 : $ $ a $
0 0 @}18{42 $ 63 $ 73 : : : $ $ 3f $ 6f $ $ $ a $
0 0 @}10{2 # $$ a $
0 0 @}}777{0 2 @
0 1 @
0 0 @}
Ungolfed version:
0 {
2 #
1 +
:
2 @
5g ==
1 +
0 @
}
1 {
2 # 3 % ! 3 *
2 # 5 % ! 5 *
+ 10 + 0 @
}
13 {
42 $ 63 $ 73 $ 73 $ a $
0 0 @
}
15 {
3f $ 6f $ 73 $ 73 $ a $
0 0 @
}
18 {
42 $ 63 $ 73 $ 73 $ 3f $ 6f $ 73 $ 73 $ a $
0 0 @
}
10 {
2 # $$ a $
0 0 @
}
777 {
0 2 @
0 1 @
0 0 @
}
Explanation:
Block 0: Load value at 2, add 1, duplicate, store at 2, if value == 100 push 1, else 0, add 1, store at 0.
Block 1: Will only be ran after block zero if value != 100. Load from 2, mod 3, not, times 3. If value at 2 is a multiple of 3 it will be 3, else 0. Same again for 5, add them and 17(looks like 10, but remember it uses base 17) and stores value at 0.
Block 13(or 20): Will only be run after 1 if value is a multiple of 3, not 5. Push and print ascii values for Fizz\n
Block 15(or 22): Will only be run after 1 if value is a multiple of 5, not 3. Push and print ascii values for Buzz\n
Block 18(or 25): Will only be run after 1 if value is a multiple of 3 and 5. Push and print ascii values for FizzBuzz\n
Block 10(or 17): Will only run after 1 if value is not multiple of 3 or 5. Prints numeric form of value.
Block 777(or 2149): Like main for C++, first block to be run
Retina, 317 139 134 132 70 63 60 55 bytes
.100{`^
_
*\(a`(___)+
Fi;$&
\b(_{5})+$
Bu;
;_*
zz
'_&`.
Explanation
.100{`^
_
The . is the global silent flag which turns off implicit output at the end of the program. 100{ wraps the rest of the program in a loop which is executed for 100 iterations. Finally, the stage itself just inserts a _ at the beginning of the string, which effectively increments a unary loop counter.
*\(a`(___)+
Fi;$&
More configuration. *\( wraps the remainder of the program in a group, prints its result with a trailing linefeed, but also puts the entire group in a dry run, which means that its result will be discarded after printing, so that our loop counter isn't actually modified. a is a custom regex modifier which anchors the regex to the entire string (which saves a byte on using ^ and $ explicitly).
The atomic stage itself takes care of Fizz. Divisibility by 3 can easily be checked in unary: just test if the number can be written as a repetition of ___. If this is the case, we prepend Fi; to the string. The semicolon is so that there is still a word boundary in front of the number for the next stage. If we turned the line into Fizz___... the position between z and _ would not be considered a boundary, because regex treats both letters and underscores as word characters. However, the semicolon also allows us to remove the zz duplication from Fizz and Buzz.
\b(_{5})+$
Bu;
We do the exact same for divisibility by 5 and Bu;, although we don't need to keep the _s around this time. So we would get a results like
_
__
Fi;___
____
Bu;
Fi;______
...
Fi;Bu;
...
This makes it very easy to get rid of the underscores only in those lines which contain Fizz, while also filling in the zzs:
;_*
zz
That is, we turn each semicolon into zz but we also consume all the _s right after it. At this point we're done with FizzBuzz in unary. But the challenge wants decimal output.
'_&`.
& indicates a conditional: this stage is only executed if the string contains an underscore. Therefore, Fizz, Buzz and FizzBuzz iterations are left untouched. In all other iterations (i.e. those which are neither divisible by 3 nor 5), we just count the number of characters, converting the result to decimal.
J, 73 Bytes
}.":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_)@.((0:=3&|)++:@(0:=5&|))"0 i.101
Definitely not the greatest, looking for ways to improve this.
Explanation:
"0 i.101 | To each number from 0 to 100
((0:=3&|)++:@(0:=5&|)) | 1 if divisble by three, 2 if by 5, 3 if by both
@. | Using the result of the previous verb, select a verb from the following gerund
":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) | Apply the appropriate Fizz-Buzz string
}. | Remove the first entry (since we counted 0)
face, 152 bytes
(FizzBuzz%d@
)\F*,c'Fo>m+*1+m=*m?*m1+m3+m4+m5+11334455$BF"B4$%B"%4$N%"N3:~0?%=+3?=31?w=F4>:3%=+5?=51?w=B4>:5??+p="%c+w="=>:+w=N1>+++1*=55*==4+==1-=+=?=~
Annotated:
(FizzBuzz%d@
)
\F*,c'Fo> ( obtain data pointer, a number, and stdout )
m+*1+ ( counter variable, goes from 1 to 100 )
m=*m?* ( result and temp variables )
m1+m3+m4+m5+11334455 ( relevant constants )
$BF"B4$%B"%4$N%"N3 ( get pointers to Fizz, Buzz, %d, and \n )
:~
0? ( has either Fizz or Buzz been printed? )
%=+3?=3 ( skip to label 3 if not divisible by 3 )
1?w=F4>:3 ( otherwise, print "Fizz" )
%=+5?=51?w=B4>:5 ( same for "Buzz" )
??+p="%c+w="=>:+ ( if we didn't print anything, print the number )
w=N1> ( print a newline )
+++1 ( increment the counter )
*=55*==4+==1-=+= ( set the result variable to 100-n )
?=~
Try it online! (The trailing newline is required on TIO due to a bug that's been fixed in a newer version of face.)
Kotlin, 115 bytes
fun main(a:Array<String>){(1..100).map{println(when(it%15){0->"FizzBuzz";3,6,9,12->"Fizz";5,10->"Buzz";else->it})}}
Symbolic Python, 324 bytes
I think I fried my brain making this...
_____=_;_=-~(_==_);___=_**(_*_+_);____=___+___/_+_+_
___=(('%'+`'¬'`[-_])*_)%(___+_,___*_-_*_-_)
___=`_>_`[_>_]+`__`[_*_+_]+___[~-_]*_,___[-_]+`__`[_]+___[~-_]*_
_=_>_
__('____=""'+(';_=-~_;____+=((_%-~-~(_==_)<(_==_))*___[_>_]+(_%-~-~-~-~(_==_)<(_==_))*___[_==_]'+`_____`[_==_]+`_==_`[_==_]+'`_`)+'+`"""
"""`)*____)
_=____
C (gcc), 101 bytes
#define P printf
main(i){for(i=0;i++<100;P("\n"))(i%3<1&&P("fizz"))+(i%5<1&&P("Buzz"))<1&&P("%u",i);}
It could have one indefinite behavior in the use + operation, the order of evaluation could be swapped. Try it online!
C, 152 bytes
#include<stdio.h>
#define p printf
int i,f;main(){while(i++<100){if(i%3==0&&(f=1))p("Fizz");if(i%5==0&&(f=1))p("Buzz");if(f==0||(f=0))p("%d",i);p("\n");}}
Ungolfed one:
#include<stdio.h>
#define p printf
int i,f;
main()
{
while(i++<100)
{
if(i%3==0&&(f=1))p("Fizz");
if(i%5==0&&(f=1))p("Buzz");
if(f==0||(f=0))p("%d",i);
p("\n");
}
}
Clean, 148 + 2 = 150 bytes
+2 for the -b compiler flag
module m
import StdEnv
f[0,0,_]="FizzBuzz"
f[a,b,n]|a==0="Fizz"|b==0="Buzz"=fromInt n
Start=flatlines[fromString(f[n rem 3,n rem 5,n])\\n<-[1..100]]
APL Nars 93 chars
h;i;j
i←0
L:j←0⋄i+←1⋄→A×⍳0≠3∣i⋄⍞←'Fiz'⋄j←1
A:→B×⍳0≠5∣i⋄⍞←'Buz'⋄j←1
B:→C×⍳j=0⋄→D
C:⍞←i
D:⎕←''⋄→L×⍳i≤99
Indented:
∇ h;i;j
i←0
L:j←0⋄i+←1⋄→A×⍳0≠3∣i⋄⍞←'Fiz'⋄j←1
A: →B×⍳0≠5∣i⋄⍞←'Buz'⋄j←1
B: →C×⍳j=0⋄→D
C: ⍞←i
D: ⎕←''⋄→L×⍳i≤99 ∇
nodejs repl, 60 bytes
for(i=0;++i<101;util.puts(i%5?s||i:s+'Buzz'))s=i%3?'':'Fizz'
With latest node, this prints a deprecation warning to the console. This presumably violates the rule about printing to STDERR, but using an older version of node will fix this.
Java (OpenJDK 8), 127 bytes
interface J{static void main(String[]a){for(int i=0;i++<100;)System.out.println((i%3<1?"Fizz":"")+(i%5<1?"Buzz":i%3<1?"":i));}}
ungolfed:
interface J {
static void main(String[] a) {
for (int i = 0; i++ < 100;)
System.out.println((i % 3 < 1 ? "Fizz" : "") + (i % 5 < 1 ? "Buzz" : i % 3 < 1 ? "" : i));
}
}
Modula-2, 222 bytes
MODULE F;IMPORT InOut;VAR i:INTEGER;BEGIN
FOR i:=1 TO 100 DO
CASE i*i*i*i MOD 15 OF
0:InOut.WriteString("FizzBuzz")|1:InOut.WriteInt(i,0)|6:InOut.WriteString("Fizz")|10:InOut.WriteString("Buzz")END;InOut.WriteLn
END END F.
Tested with Amsterdam Compiler Kit. The program needs 4-byte INTEGER. If using 2-byte INTEGER, i*i*i*i overflows and the program fails with a case error.
With indentation:
MODULE F;
IMPORT InOut;
VAR i: INTEGER;
BEGIN
FOR i := 1 TO 100 DO
CASE i * i * i * i MOD 15 OF
0: InOut.WriteString("FizzBuzz")
| 1: InOut.WriteInt(i, 0)
| 6: InOut.WriteString("Fizz")
| 10: InOut.WriteString("Buzz")
END;
InOut.WriteLn
END
END F.
ACK compiles the PIM3 dialect of Modula-2 and comes with an InOut module. Other compilers for Modula-2 or Oberon might have shorter syntax or come with shorter modules.
I don't like having 3 calls to
InOut.WriteString, but adding aPROCEDURE p(s:ARRAY OF CHAR);BEGIN InOut.WriteString(s)END p;would cost 61 bytes and save only 48 bytes in the calls.I would write
FOR i:=1TO 100DObut ACK rejects it as a syntax error.I had used
i*i*i*i MOD 15in my AppleScript answer.
AppleScript, 104 102 100 bytes
""
repeat with i from 1to 100
result&{"FizzBuzz",i,"Fizz","Buzz"}'s item((i^4mod 15+7)div 4)&"
"
end
If you run it in Script Editor, the result has "quotes" around it. If you run it with osascript, there are no "quotes", but the result ends with an extra blank line.
I steal the technique from Lynn's Lua answer, where the script picks from a list of possible values to print. I use (i^4mod 15+7)div 4 to calculate the index 1, 2, 3, or 4. It's different from Lua's i^2%3+i^4%5*2+1.
In AppleScript, i^4 raises i to 4th power. It returns a real, which is a floating-point number, but the value is equal to the correct integer.
The values of n = i^4mod 15 with i from 1 to 15 are
i = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
n = 1 1 6 1 10 6 1 1 6 10 1 6 1 1 0
So n is 0.0 for "FizzBuzz", 1.0 for i, 6.0 for "Fizz", or 10.0 for "Buzz". This pattern continues with i from 16 to 100. I need to map the values 0.0, 1.0, 6.0, 10.0 to a list index; lists in AppleScript start at index 1.
n = 0.0 1.0 6.0 10.0
(n+2)mod 7 = 2.0 3.0 1.0 5.0
(n+7)div 4 = 1 2 3 4
My 104-byte answer used (n+2)mod 7, but that mapping had 5.0 instead of 4.0, so it needed a list of 5 items, where the extra item 0, cost 2 bytes. My 102-byte answer uses (n+7)div 4. My 100-byte answer deletes 2 extra spaces.
05AB1E, 29 bytes
тLʒ"Fizz"D'ÒÖ™DŠ«)¬ÑD5ås3å«è,
To my surprise (or my incapability to use the search function) there was no 05AB1E answer to this question.
Explanation
тLʒ"Fizz"D'ÒÖ™DŠ«)¬ÑD5ås3å«è,
тL # push [1,...,100]
ʒ # for each...
"Fizz" # Push Fizz (didn't find a way to shorten this one sadly)
D # Duplicate
'ÒÖ™ # Push Buzz
D # Duplicate
Š # Move top item on the stack two slots down
« # Concatenate the top items (Results in FizzBuzz)
) # Wrap stack to array
„ # Get Divisors of N
D5å # Does 5 divide it?
s3å # Does 3 divide it?
« # Concatenate top two items
è, # Gets item in the array at the index of the concatenated divisors (indexing wraps around) and prints
Extremely late answer and for a language that has already a bit too many answers, however, i've not seen a single function answer that actually RETURNS the expected string, instead of printing it to console, so here it is:
Javascript 73 bytes
(i=0,r="")=>i>99?r:f(++i,r+=(i%5?i%3?i:'Fizz':i%3?'Buzz':'FizzBuzz')+'
')
Jq 1.5, 90 bytes
def f:if.%15<1then"FizzBuzz"elif.%5<1then"Buzz"elif.%3<1then"Fizz"else. end;range(100)+1|f
Recursiva, 46 bytes
EmB100"%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz'
Explanation:
EmB100"%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz'
E - Stringify and join with new-lines
m - map with
B100 - Range [1,2..100]
" - mapping function start
%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz' - string as per divisibility
%a15:%a5:%a3:a!'Fizz'!'Buzz'!'FizzBuzz' roughly translates to this if-else block:
if(a%15):
elif(a%5):
elif(a%3):
return a
else:
return 'Fizz'
else:
return 'Buzz'
else:
return 'FizzBuzz'
Python 2, 57 bytes
for i in range(100):print i%3/2*"Fizz"+i%5/4*"Buzz"or i+1
Not the most beautiful code but it works at least with
python -c
groovy, 55 bytes
Borrows idea from answer by @feersum https://codegolf.stackexchange.com/a/58623
100.times{println'Fizz'*(it%3/2)+'Buzz'*(it%5/4)?:it+1}
AsciiDots, 152 bytes
#
/$""
\~\
@\-\
[=]@*-\
/@----*-~&
|0/---*[>]
|@\<>$_"Buzz"@1)
|*-~/ /-/
||[%]-\>#100)
v\-*#5*/
|.//
| \<>$_"Fizz"@1)
|/-~/
@|[%]-\
0\-*#3/
*-[+]
\#1/
TrumpScript, 938 bytes
As always nothing is, 1000001 minus 1000000;
And Putin is, 1000003 minus 1000000; great
Just as Trump is, 1000005 minus 1000000; even better
Also as America is, Putin times Trump; the best
Most importantly Ivanka is, 1000101 minus 1000000;
And believe me that Hillary is nothing
As long as, Hillary thinks less of Ivanka;:
China is friends with Hillary
Democrats are idiots like Hillary
Obama is in line with Hillary
As long as, China thinks its more than America;:
Make China, China minus America;!
As long as, Democrats fear more Trump;:
Make Democrats, Democrats minus Trump;!
As long as, Obama gets more arsenal against Putin;:
Make Obama, Obama minus Putin;!
If everybody thinks, America is China?;:
Say "FizzBuzz"!
Otherwise: if we ask, Democrats are Trump?;:
Say "Buzz"!
Otherwise: what if, Obama is Putin?;:
Say "Fizz"!
Otherwise do this: tell Hillary all her lies!!!
Hillary is, as always Hillary plus nothing;!
America is great.
I was quite bored... Not too efficient, but fun!
Pseudocode:
var nothing = 1, Putin = 3, Trump = 5, America = Putin * Trump, Ivanka = 101, Hillary = nothing;
while Hillary < Ivanka
var China = Democrats = Obama = Hillary;
while China > America
China = China - America;
while Democrats > Trump
Democrats = Democrats - Trump;
while Obama > Putin
Obama = Obama - Putin;
if China == America
print "FizzBuzz";
else if Democrats == Trump
print "Buzz";
else if Obama == Putin
print "Fizz";
else
print Hillary;
Hillary = Hillary + nothing;
America is great.
Python 2.7, 59 Bytes
for i in range(100):print i%3//2*'Fizz'+i%5//4*'Buzz'or i+1
Explanation:
for i in range(100)
This will generate a list of numbers from 1 to 100 and assign it to the i variable.
print i%3//2*'Fizz'+i%5//4*'Buzz'or i+1
Note that this loop will repeat 100 times, and in each time, the loop will do what this line is commanding.
Python 2, 61 60 bytes
for i in range(1,101):print"Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i
MATLAB, 172 bytes
s=char(arrayfun(@(n){num2str(n)},[1:100 1e7])');s(3:3:end,1:4)=repmat('Fizz',33,1);s(5:5:100,1:4)=repmat('Buzz',20,1);s(15:15:100,:)=repmat('FizzBuzz',6,1);disp(s(1:100,:))
TeX, 304 bytes
\documentclass[9pt,a4paper]{article}\pagestyle{empty}\begin{document}\count0=0\count1=0\count3=3\count5=5\loop\advance\count1 by1\count0=0
\ifnum\count1=\count3 Fizz\advance\count3 by3\count0=1\fi\ifnum\count1=\count5 Buzz\advance\count5 by5\count0=1\fi\the\count1
\ifnum\count1<100\repeat\end{document}
Somehow count0 is necessary but I didn't check whether it is zero. It works and I have no idea why.
Python 2, 106 bytes
for n in range(1,101):
a="Fizz"*int(n%3==0)+"Buzz"*int(n%5==0)
if a=="": print n
else: print a
APL, 41 bytes
⊣{⎕←∊(z,⍱/z←0=3 5|⍵)/'Fizz' 'Buzz'⍵}¨⍳100
Tested on GNU-APL (ver 1.7/980M)
Ruby, 82 72 70 68 bytes
based on other answers:
puts (1..100).map{|i|(x=(i%3<1?"Fizz":"")+(i%5<1?"Buzz":""))>""?x:i}
old solution:
(1..100).map{|i|$><<"Fizz"if f=i%3<1
$><<"Buzz"if b=i%5<1
$><<i if !(f||b)
puts()}
q/kdb+, 58 56 49 bytes
Solution:
0{$[sum i:0=y mod 3 5;`Fizz`Buzz(&)i;y]}'1+(!)100
Example:
q)0{$[sum i:0=y mod 3 5;`Fizz`Buzz(&)i;y]}'1+(!)100
1
2
,`Fizz
4
,`Buzz
,`Fizz
7
8
,`Fizz
,`Buzz
11
,`Fizz
13
14
`Fizz`Buzz
16
...etc
Explanation:
0{$[sum i:0=y mod 3 5;`Fizz`Buzz where i;y]}'1+til 100 / ungolfed
{ }' / anonymous function that takes each-left and each-right
0 / this would be parameter 'x' but we dont use it
til 100 / til generates a list of 0..99
1+ / adds 1 to every item in the list, thus 1..100
$[ ; ; ] / switch, $[condition;true;false]
y mod 3 5 / modulo operation on input for 3 and 5, mod[1;3 5] = 1 1
0= / is 0 equal to this result (basically a 'not' operation)
i: / save in i for later
sum / add these, will get 0, 1 or 2. 0 is interpretted as false
where i / where gives indices where i is true
`Fizz`Buzz / 2 item list which gets indexed into (and implicitly returned)
y / return the input if the condition was false
Notes:
This ^^ is pretty much a q version of the k solution, so I've written in a different way.. unfortunately it's about 50% slower :(
0{(`Fizz;`Buzz;y)(&)(0=a),all a:mod[y;3 5]}'1+(!)100
Here we are indexing into a list of Fizz, Buzz, based on the result of the modulo operation... The k solution style is better.
Swift, 97 bytes
for i in 1...100{i%15==0 ?print("FizzBuzz"):i%3==0 ?print("Fizz"):i%5==0 ?print("Buzz"):print(i)}
Micro, 72 bytes
:i{i1+:i"":d
i3/i3%=if("Fizz":d,)
i5/i5%=if(d"Buzz"+:d,)
d:\i100=if(,a)}
braingasm, 40 bytes
The language is coming along nicely. A few recent features allows for a quite decent FizzBuzz, if I may say so myself:
100[>#3p["Fizz".+]#5p["Buzz".+]z[#:]10.]
Here's how it works:
100[ One hundred times:
> Go to the next cell.
#3p[ If current cell number is divisble by 3:
"Fizz". Print "Fizz".
+ Increment current cell
]
#5p["Buzz".+] Same thing for 5 and "Buzz".
z[ If the current cell is 0 (hasn't been incremented):
#: Print current cell number
]
10. Print a newline
]
///, 209 208 bytes
/I/
EFizz
//H/FizzE//G/
Fizz
//E/Buzz
/1
2G4I7
8GE11G13
14
H16
17G19I22
23GE26G28
29
H31
32G34I37
38GE41G43
44
H46
47G49I52
53GE56G58
59
H61
62G64I67
68GE71G73
74
H76
77G79I82
83GE86G88
89
H91
92G94I97
98GBuA
Fourier, 81 bytes
|`Fizz`|F|`Buzz`|B1~i100(i~X%15{0}{1~XFB}X%5{0}{1~XB}X%3{0}{1~XF}X{i}{Xo}10ai^~i)
Who knew such a simple task would yield such a mammoth of a program!
Pseudocode of the program:
Function F {
Print "Fizz"
}
Function B {
Print "Buzz"
}
i = 1
While i != 100
X = i
If X % 15 == 0
X = 1
Function F
Function B
End if
If X % 5 == 0
X = 1
Function B
End If
If X % 3 == 0
X = 1
Function F
End If
If X == i
Print X
End if
Print "\n"
i += 1
End while
Ruby, 68 65 bytes
q='Buzz';(1..100).map &->e{p e%3<1?'Fizz'+(e%5<1?q:''):e%5<1?q:e}
REXX 81 Bytes
f.=""
f.0="buzz"
t.=""
t.0="fizz"
do i=1 to 100
f=i//5
t=i//3
say overlay(t.t||f.f,i)
end
Turtlèd, 221 bytes
99;,:[*,l]u[*d{*u,dr}ul' l[ l]ru]u3;[ [ r]l[ ' l]ll"Fizz";]<97:>5[ (*[ r]l[ ' l]ll)(zr)"Buzz";]<104:>[ lll'0rrr[ r]l{*' l{*l}{ l}(9'0l( r"1!")(9"10!"))(8'9)(7'8)(6'7)(5'6)(4'5)(3'4)(2'3)(1'2)(0'1)(!'0):{ l}}[ l]drrrr{zd}]
due to a bug (having two close curly brackets next to each other causes the second one to match to the first ones open bracket), the Try it online version is different for now (I put a space between the two close curly brackets)
99;,:[*,l]u[*d{*u,dr}ul' l[ l]ru]u3;[ [ r]l[ ' l]ll"Fizz";]<97:>5[ (*[ r]l[ ' l]ll)(zr)"Buzz";]<104:>[ lll'0rrr[ r]l{*' l{*l}{ l}(9'0l( r"1!")(9"10!"))(8'9)(7'8)(6'7)(5'6)(4'5)(3'4)(2'3)(1'2)(0'1)(!'0):{ l} }[ l]drrrr{zd}]
I might write an explanation if I get time motivated
Julia, 70 bytes
for i=1:100 println("$(i%3<1?"Fizz":"")$(i%5<1?"Buzz":i%3>0?i:"")")end
Julia has perl-like string formatting. Very nice for challenges like these.
S.I.L.O.S, 141 bytes
lbla
a+1
c=1-(a%3)*(a%5)
if c b
printIntNoLine a
lblb
c=(a%3)
if c d
print Fizz
lbld
c=(a%5)
if c c
print Buzz
lblc
printLine
b=100-a
if b a
Unfortunately SILOS is incredibly verbose, and an interpreter bug cost me a few extra bytes, but I think SILOS is "superior" only to scratch in this challenge.
8086 machine code, 70 68 62 bytes
00000000 31 c0 40 50 89 c2 89 e5 68 0a 24 d4 05 75 06 68 |1.@P....h.$..u.h|
00000010 7a 7a 68 42 75 89 d0 d4 03 75 06 68 7a 7a 68 46 |zzhBu....u.hzzhF|
00000020 69 89 d0 83 fc fa 75 08 d4 0a 86 c4 0d 30 30 50 |i.....u......00P|
00000030 b4 09 89 e2 cd 21 89 ec 58 3c 64 75 c5 c3 |.....!..X<du..|
0000003e
How it works:
| org 0x100
| use16
31 c0 | xor ax, ax
40 | aa: inc ax
50 | push ax
89 c2 | mov dx, ax
89 e5 | mov bp, sp
68 0a 24 | push 0x240a
d4 05 | aam 5
75 06 | jnz @f
68 7a 7a | push 0x7a7a
68 42 75 | push 0x7542
89 d0 | @@: mov ax, dx
d4 03 | aam 3
75 06 | jnz @f
68 7a 7a | push 0x7a7a
68 46 69 | push 0x6946
89 d0 | @@: mov ax, dx
83 fc fa | cmp sp, -6
75 08 | jne @f
d4 0a | aam 10
86 c4 | xchg al, ah
0d 30 30 | or ax, 0x3030
50 | push ax
b4 09 | @@: mov ah, 0x09
89 e2 | mov dx, sp
cd 21 | int 0x21
89 ec | mov sp, bp
58 | pop ax
3c 64 | cmp al, 100
75 c5 | jne aa
c3 | ret
K, 52 Bytes
-1@{,/$$[#i:&~.q.mod[x;3 5];`Fizz`Buzz i;x]}'1+!100;
Thanks
Java, 153 145 bytes
enum f{;static{for(int i=1;i<101;i++)System.out.println(i%3>0&i%5>0?i:(i%3<1&i%5<1?"FizzBuzz":(i%3<1?"Fizz":(i%5<1?"Buzz":0))));System.exit(0);}}
Not as long as I expected it to be, maybe because I ommited main function and used an enum. Quite overcomplicated print statement.
Ungolfed version(Modified to be readable) with comments:
enum f {; // Required because it is an enum
static { // static block
for (int i = 1; i < 101; i++) { // loop from 1 to 100 inclusive
boolean by3 = i % 3 == 0;
boolean by5 = i % 5 == 0;
if (!by3 && !by5) // Not divisible by 3 and 5
System.out.println(i); // Just show the number
else if (by3 && by5) // Divisible by both
System.out.println("FizzBuzz"); // Show FizzBuzz
else if (by3) // Divisible only by 3
System.out.println("Fizz"); // Show Fizz
else // Divisible only by 5
System.out.println("Buzz"); // Show Buzz
}
System.exit(0); // Required because there can't be output to stderr and it would crash trying to run main function
}
}
Ungolfed not modified:
enum f {;
static {
for (int i = 1; i < 101; i++)
System.out.println(i % 3 > 0 & i % 5 > 0 ? i : (i % 3 < 1 & i % 5 < 1 ? "FizzBuzz" : (i % 3 < 1 ? "Fizz" : (i % 5 < 1 ? "Buzz" : 0))));
System.exit(0);
}
}
EDIT: Saved 8 bytes by replacing ==0 with <1, !=0 with >0 and && with &
Lua, 126 bytes
for i=1,100 do if i%15==0 then print"FizzBuzz"elseif i%3==0 then print"Fizz"elseif i%5==0 then print"Buzz"else print(i)end;end
REXX, 94 bytes
f.=
b.=
f.0='Fizz'
b.0='Buzz'
do i=1 to 100
f=i//3
b=i//5
r=f.f||b.b
if r<i then r=i
say r
end
Alternative 94 byte solution:
f='FizzBuzz'
do i=1 to 100
r=left(f,(i//3=0)*4)right(f,(i//5=0)*4)
if r='' then r=i
say r
end
Cardinal 217 bytes
%x>+ v >+++++~M! 8# "buzz"
0 #~0#+++~>M! # V "fizz"
+ ^jM< ~ V>#
+ V > #xV
= 0 V
t ~ >#x
t t v V
* = > #}#} /
> ^ >}/
.
Explanation
%x
0
+
+
= 0
t ~
t t
* =
> ^
Initializes a pointer with an inactive value of 100 and active value of 0
>+ v
#
^jM<
Loops around, incrementing the active value of the pointer and sending out a duplicate until the active value is equal to the inactive value (100)
>+++++~M!
~0#+++~>M!
Checks if the value mod 3 or mod 5 is equal to 0
# "buzz"
# # V "fizz"
~ V>#
V > #xV
V
>#x
v V
> #}#} /
>}/
.
Uses reflectors and splitters in order to print only numbers that are not divisible by 3 or 5. Printing fizz when divisible by 3 and buzz when divisible by 5.
Japt, 45 44 43 39 36 35 33 32 31 bytes
Japt is a shortened version of JavaScript.
Lò1@"Fizz"pXv3)+"Buzz"pXv5)ªX÷
How it works
Lò1@"Fizz"pXv3)+"Buzz"pXv5)ª XÃ ·
Lò1@"Fizz"pXv3)+"Buzz"pXv5)||X} qR
Lò1 // Create the inclusive array [1...100].
@ // Map each item X in this range to:
"Fizz"p // "Fizz" repeated:
Xv3) // if X is divisible by 3, 1 time, otherwise, 0 times;
+ // concatenated with
"Buzz"p // "Buzz" repeated:
Xv5) // if X is divisible by 5, 1 time, otherwise, 0 times.
||X // If the result is an empty string, set it to X.
} qR // Join the range with newlines.
// Implicit: output last expression
Old version, 32 bytes:
Lo@"FizzBuzz"s°X%3©4X%5?4:8 ªX÷
Lo@"FizzBuzz"s++X%3&&4X%5?4:8 ||X} qR
Lo // Create the range [0..100).
@ // Map each item X in this array to:
"FizzBuzz"s // "FizzBuzz".slice(
++X%3&&4 // if ++X is divisible by 3, 0; else, 4,
X%5?4:8 // if X is divisible by 5, 8; else, 4).
||X // If the result is an empty string, set it to X.
} qR // Join the range with newlines.
// Implicit: output last expression
Alternate version (45 44 40 38 bytes): (Note: this doesn't work in the current version of Japt)
1o#e £(X%3?":Fizz" +(X%5?":Buzz" ªX} ·
1o#e m@(X%3?":Fizz" +(X%5?":Buzz" ||X} qR
1o#e // Create an array of 1 to 100.
m@ // Map each item X in this array to:
(X%3?":Fizz" // If X is divisible by 3, "Fizz"; else, an empty string
+ // concatenated to:
(X%5?":Buzz" // if X is divisible by 5, "Buzz"; else, an empty string.
||X // If the result is an empty string, set it to X.
} qR // Join the range with newlines.
// Implicit: output last expression
Suggestions welcome!
Plain Javascript (no console.log() & no alert()), 64 bytes
for(f=b='';f++<100;b+=(f%5?z||f:z+'Buzz')+'\n')z=f%3?'':'Fizz';b
Just copy/paste into any javascript console and hit enter.
Javascript, 56 bytes
for(f=0;f++<100;alert(f%5?b||f:b+'Buzz'))b=f%3?'':'Fizz'
Assuming 100 alerts is an acceptable output method.
Valyrio, 13 bytes
s∫main [CF]
This is a fairly basic (and slightly unimaginative) answer.
Explanation
C pushes 100 to the stack, which means that ...
F is the FizzBuzz builtin. This was mainly added in as a basic stack based program but got left in as a command and I never got rid of it.
Mathematica, 61 Bytes
Heavily inspired by this post on the mathematica stack exchange
fizzbuzz[#,,fizz,,buzz][[#~GCD~15~Mod~15]]&~Array~100//Column
DUP, 76 bytes
[$$3/%$[]['F,'i,'z,'z,]?\5/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c:0[$100<][1+c;!]#
Explanation of program flow, code blocks:
DUP has two default truth values: -1 (true, all bits set) and 0 (false, no bits set). For conditional evaluations every nonzero value is accepted as true, comparisons themselves lead to either -1 or 0.
DUP has two conditional expressions, if-then-else and a while loop:
[execute if not false][execute if false]?. E.g. 1['t,]['f,]? prints t to STDOUT, because 1 is not false.
[condition][execute while not false]#. E.g. 5[$0>][$.1-]# prints the numbers 5,4,3,2,1 to STDOUT. The condition block tests the top stack value if it’s greater than 0, the execute block prints the number and decrements it.
The condition that’s checked is always the topmost stack element, which gets popped off the stack during the check.
[
$$3/%$ {dup,dup,push 3, moddiv, pop, dup}
[] {if condition true do nothing}
['F,'i,'z,'z,]? {if condition false print Fizz}
\5/%$ {swap, push 5, moddiv, pop, dup}
[] {if condition true do nothing}
['B,'u,'z,'z,]? {if condition false print Buzz}
* {mul}
[$.] {if condition true dup, print to STDOUT}
[]? {if condition false do nothing}
10, {push 10, print char to STDOUT (newline)}
]c: {define function c}
0 {push 0}
[$100<] {while dup < push 100 true}
[1+c;!]# {do push 1, add, execute function c}
Step by step:
instruction stack
0 0
[
$ 0,0
100 0,0,100
< 0,-1
] 0
[
1 0,1
+ 1 increment counter
c; 1,0 0=start address of function c
! execute c
[
$$3 1,1,1,3
/ 1,1,1,0 mod,div operator (n mod 3, n div 3)
% 1,1,1 /% → mod
$ 1,1,1,1 result of n%3 used as flag for later check
[] 1,1,1 condition true→do nothing
['F,'i,'z,'z,]? skipped
\ 1,1,1 swap top and 2nd stack elements
5 1,1,1,5
/ 1,1,1,0 mod,div operator
% 1,1,1 /% → mod
$ 1,1,1,1 n%5 flag
[] 1,1,1 condition true → do nothing
['B,'u,'z,'z,]? skipped
* 1,1 multiply %3 and %5 flags, result is only >0
if neither %3 nor %5 are 0.
[ 1 if condition (flag)>0
$ 1,1 dup
.] 1 print number to STDOUT: '1'
[]? skipped
back to while loop
[
$ 1,1
100 1,1,100
< 1,-1
] 1
[
1 1,1
+ 2 increment counter
c; 2,0 0=start address of function c
! execute c
...
A full description of all operators and program flow can be found at my GitHub repository, together wtih my Julia interpreter of DUP.
An online Javascript implementation showing useful debug information can be found here.
A rather terse introduction can be found on the esolangs.org DUP page.
Brainfuck, 425 bytes
-[>+>+<<-----]>--->-->++++++++++>->++++++++++>+++++++++>>>+++>>>+++++>>>>>-[<+<+>>-------]<---<--->---->>-[<++>-----]<+++>>>----[<+++<+++>>--]<-----<<<<<<<<<<<<<<[<++++++++++[>>[->>-<]>+[->>>>>-[<<<-[<<<<<<<<.>>>>>>>>>>-<]>+[->]<<+>>>>>-<]>+[->]<<+<<<<]>-[>>>-[<<<<<<<<<<.>>>>>>>>>>>>-<]>+[->]<<+<-<]>+[>>>>>.>>.>..<<<<<<<<<+++>->]>-[>>-<]>+[>>>.>>>.<..<<<<<<+++++>->]<<<<<<<<<<<<+>.>-]<<----------<+>>>>-]>>>>>>>>>>>.>>>.<..
Explanation
Cell indexes in comments are in hexadecimal to match numbering in bfdev debug view.
# #####################
# ##### VARIABLES #####
# #####################
# C1 & C2: 48 (ascii 0)
-[>+>+<<-----]>--->-->
# C3: 10 (ascii LF)
++++++++++>
# C4: Singles counter
->
# C5: Tens counter
++++++++++>
# C6: is1to9 if countdown
+++++++++>
# C7: 0 to enter/exit is1to9, or 1 to enter is10to99
>
# C8: 0 to not enter is10to99
>
# C9: isMultiOf3 if countdown
+++>
# CA: 0 to exit isMultiOf3, or 1 to enter !isMultiOf3
>
# CB: 0 to not enter !isMultiOf3
>
# CC: isMultiOf5 if countdown
+++++>
# CD: 0 to exit isMultiOf5, or 1 to enter !isMultiOf5
>
# CE: 0 to not enter !isMultiOf5
>
# CF: 70 F, and put C13 to 70
>>-[<+<+>>-------]<---<--->
# C10: 66 - ascii B
---->
# C11: 105 - ascii i
>-[<++>-----]<+++>
# C12: 122 - ascii z, and put C16 to 122
>>----[<+++<+++>>--]<
# C13: 117 - ascii u
-----
# Goto C5
<<<<<<<<<<<<<<
# #################
# ##### LOGIC #####
# #################
# While C5 (tens counter): Print 1-99
[
# Restore C4: singles counter
<++++++++++
# For 0 to 9, using singles counter
[
# Goto C6
>>
# If is1to9
[
# Decrement is1to9 countdown
-
# Prepare else condition at C8
>>-<
]
# Goto C7 or C8
>+
# Else If C7: is10to99
[
# Decrement C7
-
# Goto CC
>>>>>-
# If is not multi of 5
[
# Goto C9
<<<-
# If is not multi of 3
[
# Print C1: tens
<<<<<<<<.
# Prepare else condition at CB
>>>>>>>>>>-
# Goto CA
<
]
# Goto CA or CB
>+
# Else If is multi of 3
[
# Goto CA, restore, goto CB
->
]
# Goto C9 and restore
<<+
# Prepare else condition at C1E
>>>>>-
# Goto C1D
<
]
# Goto CD or CE
>+
# Else If is multi of 5
[
# Goto CD, restore, goto CE
->
]
# Goto CC and restore
<<+
# Goto C8
<<<<
]
# Goto C9
>-
# If is not multi of 3
[
# Goto CC
>>>-
# If is not multi of 5
[
# Print C2: singles
<<<<<<<<<<.
# Prepare else condition at CE
>>>>>>>>>>>>-
# Goto CD
<
]
# Goto CD or CE
>+
# Else If is multi of 5
[
# Goto CD, restore, goto CE
->
]
# Goto CC and restore
<<+
# Prepare else condition at CB
<-
# Goto CA
<
]
# Goto CA or CB
>+
# Else If is multi of 3
[
# Print Fizz
>>>>>.>>.>..
# Goto C9 (If is not multi of 3)
<<<<<<<<<
# Restore C9
+++
# Goto CA, decrease, goto CB
>->
]
# Goto CC
>-
# If is not multi of 5
[
# Prepare else condition at CE
>>-
# Goto CD
<
]
# Goto CD or CE
>+
# Else If is multi of 5
[
# Goto C10 and print Buzz
>>>.>>>.<..
# Goto CC (If is not multi of 5) and restore
<<<<<<+++++
# Goto CD, decrease, goto CE
>->
]
# Goto C2: singles, and increment
<<<<<<<<<<<<+
# Print C3: LF
>.
# Decrement C4: singles counter
>-
]
# Restore C2: singles ascii
<<----------
# Increment C1: tens ascii
<+
# Goto C5 (tens counter) and decrement it
>>>>-
]
# Goto C10 and print Buzz
>>>>>>>>>>>.>>>.<..
Nim, 100 76 73 bytes
for i in 1..100:echo max(["Fizz","",""][i%%3]&["Buzz",""][ord i%%5>0],$i)
Hm... still trying to learn Nim, and I'm thinking there's got to be a better way...
Vim, 44 bytes
33o<CR>Fizz<CR><Esc>qqABuzz<Esc>5kq19@q:%s/^$/\=line('.')<CR>
On vimgolf.com we have the classic Remember FizzBuzz?, which is similar to this, but keeps the numbers on all the lines. There's also Neither Fizz nor Buzz, which uses a similar format, but provides a useful input file. Those small differences drastically change the optimal solution. I did exactly this same variation 2 years ago in the edit to this reddit post. I had to check whether visual increment (not available back then) creates an improvement, like it has for the other variations, but it looks like it hasn't.
33o<CR>Fizz<CR><Esc>: Create the Fizz lines AND the blank lines with a simple insert mode repeat. Much quicker than a macro. AFAIK first discovered by @KersonHsiao in the vimgolf.com version, and used by every top solution since.qqABuzz<Esc>5kq19@q: A very simple macro appends the Buzzes.:%s/^$/\=line('.')<CR>: Replaces all blank lines with that line's line number. The expression replacement is very long, so this tactic is rarely used in vimgolf, but the alternatives are all worse.
Groovy, 61 bytes
100.times{a=++it%3?"":"fizz"
a+=it%5?"":"buzz"
println a?:it}
JavaScript (using external library) (90 bytes)
x=>_.Range(1,100).Select(x=>x%3==0?(x%5==0?"FizzBuzz":"Fizz"):x%5==0?"Buzz":x).WriteLine()
Link to library: https://github.com/mvegh1/Enumerable/
Code explanation: Creates a range starting at 1 and extending 100 elements. Select maps the item according to the predicate. First check if divisible by 3, if so check if divisible by 5. If so, select "FizzBuzz", else select "Fizz". Otherwise,check if divisible by 5. If so, select "Buzz", else just select the number. WriteLine is built into the library, and it writes each element on its own line
ROOP, 187 bytes
1
V! !<
(102) 1|
e#r3##r5# a|
#H # # Y-<
N N !
"Fizz""Buzz"
mX mX
### V--> !
A V---->
#
' C
V'e "\n"
|# M #
<V# #v
C A C
#X ##
w
O#
I will try to explain each section of code:
V! !< Add 1 to each number that goes to the left of the a
1| and sends it to the bottom of the V
a|
-<
(102) The 102 falls to the left of the e and each number
e that passes over is compared to 102.
#H If a number is equal then the H runs and ends the program
#r3# With each number that goes above the r
# the remainder of dividing by 3 is obtained.
N The N returns 1 if the number is 0, and 0 otherwise.
"Fizz" The string "Fizz" falls and moves to the left of the m.
The number is multiplied by the string
mX ("" or "Fizz" if it is 0 or 1 respectively)
### The X removes the number when it moves to the right
The same is done with 5 and "Buzz"
mX mX
V--> Both strings are concatenated with the A
A getting "", "Fizz", "Buzz" or "FizzBuzz"
#
' C The C changes the direction of advance of string, to the left.
'e At the same time the "e" compares the string with the empty string.
# The single quotes are a vertical literal string.
V The V and pipes redirects the string to the right of the C
| that changes the direction again in order that comes to the left of the A
<V
C A
Y The original number is converted to a string with Y.
!
! Pipes and teleporters (!) Redirects the string to below the V
V---->
M The string falls to the right of the M and multiplies
# # with the number previously obtained by the e
A The result is above the A
"\n" The string "\n" falls on the v which makes a copy
M # whenever there is a space below.
v The C changes the direction of the string so it goes to the left.
A C It waits to the right of the A
A The A concatenate all 3 strings, the result is on the w that sends it
#X ## to the O representing the output. At the same time the X deletes the string.
w
O#
I hope it is comprehensible, English is not my main language.
Oration, 98 bytes
literally, for i in range(1,100):x=""if i%3 else'Fizz';x+=""if i%5 else "Buzz";print x if x else i
Ruby, 72 bytes
(1..100).each{|n|puts "#{n%3==0?'Fizz':''}#{n%5==0?'Buzz':n%3!=0?n:''}"}
Explanation
For each number from 1 to 100, print 'Fizz' if the number mod 3 is 0, then if the number mod 5 is 0, print 'Buzz' else if the number mod 3 is 0, print the number.
///, 229 bytes
/x/Buzz//b/
x//f/
Fizz/1
2f
4bf
7
8fb
11f
13
14fx
16
17f
19bf
22
23fb
26f
28
29fx
31
32f
34bf
37
38fb
41f
43
44fx
46
47f
49bf
52
53fb
56f
58
59fi
61
62f
64bf
67
68fb
71f
73
74fx
76
77f
79bf
82
83fb
86f
88
89fx
91
92f
94bf
97
98fb
Elixir, 182 bytes
import Stream
f=fn(n)->(zip(cycle(["","","fizz"]),cycle(["","","","","buzz"]))|>zip(iterate(1,&(&1 + 1)))|>map(fn{{"",""},n}->n
{{p,o},_}->p<>o end))|>take(n)|>Enum.each(&IO.puts/1)end
Calling: f.(100)
Python 91 Bytes
for n in range(100):
c=""
if n%3==0:c+="fizz"
if n%5==0:c+="buzz"
if c=="":c=n
print c
Tcl, 136 bytes
set f {Fizz 3 Buzz 5}
while {[incr n]<=100} {set s ""
foreach {m d} $f {if {$n%$d==0} {append s $m}}
if {$s eq ""} {puts $n} {puts $s}}
This solution, incidentally, is easily extensible to any combination of multiples. See The Smart Person's Mirage golf, where gnibbler posted the same idea (but in Python).
set iterations 100
set fizzies {
Fizz 3
Jazz 4
Buzz 5
}
while {[incr n] <= $iterations} {
set s ""
foreach {name divisor} $fizzies {
if {$n % $divisor == 0} {append s $name}
}
if {$s eq ""} {puts $n} {puts $s}
}
Javascript, 64 bytes
for(i=0;++i<101;)console.log((i%5?'':'fizz')+(i%3?'':'buzz')||i)
Vim, 66, 57 56 keystrokes
i1<esc>qqYp<C-a>q98@q3Gqy:s/\d*/Fizz<CR>3j@yq@y5Gqz:s<CR>ABuzz<esc>5j@zq@z
Further golfing, and explanation on the way.
Seriously, 36 bytes
2╤R`;;3@%Y"Fizz"*)5@%Y"Buzz"*(+;I`Mi
Explanation:
2╤ push the value 10**2 (100)
R pop a: push range(1,a+1)
` start function literal
;; duplicate the top of the stack twice
3 push the value 3
@ swap the top 2 values
% pop a,b: push a%b
Y pop a: push 1 if a==0, else 0
"Fizz" push the string "Fizz"
* pop a,b: push a*b (in this case, "Fizz" repeated b times)
) rotate the stack right by one ([a,b,c] -> [c,a,b])
5@%Y"Buzz"* Do the same thing as above, but with divisibility testing for 5 and using "Buzz"
( rotate the stack left by one
+ pop a,b: push a+b (string concatenation here)
; dupe top of stack
I pop a,b,c: push b if a is truthy, else c (here, a and b are the same string, either "", "Fizz", "Buzz", or "FizzBuzz", and c is the original integer)
` end function literal
M pop f,[a]: using each element of [a] as a temporary stack, evaluate f, and push the result
i flatten [a] (push each value in [a] to the stack, starting from the end to preserve order)
Jelly, 24 20 bytes
³µ3,5ḍTị“¡Ṭ4“Ụp»ȯµ€G
How it works
³µ3,5ḍTị“¡Ṭ4“Ụp»ȯµ€G Main link. No input.
³ Yield 100.
µ Begin a new, monadic chain.
µ€ Apply the preceding chain to all integers n in [1, ..., 100].
3,5ḍ Test n for divisibility by 3 and 5.
T Get all truthy indices.
This yields [1] (mult. of 3, not 5), [2] (mult. of 5, not 3),
[1, 2] (mult. of 15) or [].
“¡Ṭ4“Ụp» Yield ['Fizz', 'Buzz'] by indexing in a dictionary.
ị Retrieve the strings at the corr. indices.
ȯ Logical OR hook; replace an empty list with n.
G Grid; join the list, separating by linefeeds.
Hexagony, 91 bytes
Thanks for the bounty :)
Wow, I would never have imagined I could beat Martin’s Hexagony solution. But—who would have thunk it—I got it done. After several days of failure because I neither had the Hexagony colorer nor the EsotericIDE to check my solution. I got several aspects of the specification wrong, so I produced a few wrong “solutions” just using pen and paper and a text editor. Well, finally I overcame my laziness and cloned both repositories, downloaded VisualStudio and compiled them. Wow, what useful tools they are! As you can see, I am far from being someone you’d call a programmer (I mean, come on! I didn’t even have VisualStudio installed, and have pretty much no clue about how to compile a program) ;)
It still took me a while to find a working solution, and it is quite crammed and chaotic, but here it is in all its glory:
Fizzbuzz in a size 6 hexagon:
3}1"$.!$>)}g4_.{$'))\<$\.\.@\}F\$/;z;u;<%<_>_..$>B/<>}))'%<>{>;e"-</_%;\/{}/>.\;.z;i;..>(('
Hexagonal layout:
3 } 1 " $ .
! $ > ) } g 4
_ . { $ ' ) ) \
< $ \ . \ . @ \ }
F \ $ / ; z ; u ; <
% < _ > _ . . $ > B /
< > } ) ) ' % < > {
> ; e " - < / _ %
; \ / { } / > .
\ ; . z ; i ;
. . > ( ( '
And the beautiful rendition, thanks to Timwi’s Hexagony Colorer:
So, here is a 110 seconds long GIF animation at 2 fps, showing the program flow during the first 6 numbers 1, 2, Fizz, 4, Buzz, Fizz, the first 220 ticks of the program (click on the image for the full size):
My goodness, thanks to the Natron compositing software the animation of the pointer was still tedious to create, but manageable. Saving 260 images of the memory was less amusing. Unfortunately EsotericIDE can’t do that automatically. Anyways, enjoy the animation!
After all, once you wrap your head around the memory model and the rather counterintuitive wrapping of paths that cross the borders of the hexagon, Hexagony is not that hard to work with. But golfing it can be a pain in the butt. ;)
It was fun!
Javascript, 191 bytes
for(var i=1; i<=100; i++){
var r = "";
if( i%15 == 0 ? r = "FizzBuzz" : (i%5 == 0 ? r = "Buzz" : (i%3 == 0 ? r = "Fizz" : r = i)) ){
console.log(r);
}
}
Python 2, 91
1;exec"print'FizzBuzz'if _%3==_%5==0else'Fizz'if _%3==0else'Buzz'if _%5==0else _;_+=1;"*100
XQuery 3, 172 bytes
declare option output:method "text";string-join(for$x in 1 to 100 return if($x mod 15=0)then"FizzBuzz"else if($x mod 3=0)then"Fizz"else if($x mod 5=0)then"Buzz"else $x,"
")
There were only 7 XQuery answers on the whole site, I thought it could at least have its FizzBuzz ! Granted it's not very golfy, in particular when you need to add a 36 bytes preface so that it does not output an XML header.
I tested it with Saxon-HE's command-line XQuery tool (java net.sf.saxon.Query fizzbuzz.xq), with which I had to replace the w3-defined option declaration with declare option saxon:output "method=text";.
Kotlin, 119 115 bytes
fun main(a:Array<String>){for(i in 1..100)println(if(i%3<1)"Fizz" else ""+if(i%5<1)"Buzz" else if(i%3<1)"" else i)}
Clojure, 113 106 101 100 91 bytes
My first golf!
(dotimes[i 100](println(str({2'Fizz}(mod i 3))({4'Buzz}(mod i 5)({2""}(mod i 3)(inc i))))))
Ungolfed:
(dotimes [i 100] ; account for off-by-one later
(println (str ({2 'Fizz} ; str converts symbols to strings
(mod i 3))
({4 'Buzz} ; 4 instead of 0 because of off-by-one
(mod i 5)
({2 ""} ; shortest way to write when-not
(mod i 3)
(inc i))))))
Kotlin, 145 bytes
fun main(a:Array<String>){IntRange(1,100).forEach{val f=it%3==0;val b=it%5==0;var x="";if(f)x+="Fizz";if(b)x+="Buzz";if(!f&&!b)x+=it;println(x)}}
ArnoldC, 842 bytes
IT'S SHOWTIME
HEY CHRISTMAS TREE a
YOU SET US UP 100
HEY CHRISTMAS TREE b
YOU SET US UP 0
HEY CHRISTMAS TREE r
YOU SET US UP 0
STICK AROUND a
GET TO THE CHOPPER b
HERE IS MY INVITATION 101
GET DOWN a
ENOUGH TALK
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 15
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 3
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
GET TO THE CHOPPER r
HERE IS MY INVITATION b
I LET HIM GO 5
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE r
TALK TO THE HAND b
BULLSHIT
TALK TO THE HAND "Buzz"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "Fizz"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "FizzBuzz"
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER a
HERE IS MY INVITATION a
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED
First try at golfing, I think this is as bad as it gets (both language and golfing).
beeswax, 104 89 81 bytes
Denser packing allowed for cutting off 8 more bytes.
Shortest solution (81 bytes), same program flow, different packing.
p?@<
p?{@b'gA<
p@`zzuB`d'%~5F@<f`z`<
>~P"#"_"1F3~%'d`Fiz`b
d;"-~@~.<
>?N@9P~0+d
Changing the concept enabled me to cut down the code by 15 bytes. I wanted to get rid of the double mod 5 test in the solution, so I implemented a flag.
Short explanation:
if n%3=0 Fizz gets printed, and the flag gets set. The flag is realized simply by pushing the top lstack value onto the gstack (instruction f).
If n%5=0, then either n%3=0(FizzBuzz case) or n%3>0(Buzz case). In both cases, Buzz gets printed, and the flag reset by popping the stack until it’s empty (instruction ?).
Now the interesting cases:
If n%5>0, then either we had n%3=0 (printing Fizz case, n must not be printed) or n%3>0 (Fizz was not printed, so n has to be printed). Time to check the flag. This is realized by pushing the length of gstack on top of gstack (instruction A).
If n%3 was 0 then the gstack length is >0.
If n%3 was >0, the gstack length is 0.
A simple conditional jump makes sure n gets only printed if the length of gstack was 0.
Again, after printing any of n, Fizz, and/or Buzz and the newline, the gstack gets popped twice to make sure it’s empty. gstack is either empty [], which leads to [0] after instruction A (push length of gstack on gstack), or it contains one zero ([0],the result of n%3), which leads to [0 1], as [0] has the length 1. Popping from an empty stack does not change the stack, so it’s safe to pop twice.
If you look closer you can see that, in principle, I folded
> q
d`Fizz`f>
into
<f`z`<
d`Fiz`b
which helps to get rid of the all the wasted space between A and < at the end of the following row in the older solution below:
q?{@b'gA< p <
New concept solution (89 bytes) including animated explanation:
q?@ <
q?{@b'gA< p <
p?<@`zzuB`b'%~5F@<f`zziF`b'<
>N@9P~0+.~@~-";~P"#"_"1F3~%d
Hexagonal layout:
q ? @ <
q ? { @ b ' g A < p <
p ? < @ ` z z u B ` b ' % ~ 5 F @ < f ` z z i F ` b ' <
> N @ 9 P ~ 0 + . ~ @ ~ - " ; ~ P " # " _ " 1 F 3 ~ % d
Animation of the first 326 ticks at 2 fps, with local and global stacks, and output to STDOUT.
For comparison, below are the path overlays of the older, more complex solution. Maybe it’s also the prettier solution, from a visual standpoint ;)
TCL, 208 bytes
Golfed:
set i 1;while {$i<101} {set p "";if {[expr $i % 3]==0} {set p [concat $p {fizz}]};if {[expr $i % 5]==0} {set p [concat $p {buzz}]};if {[expr $i % 3]>0&&[expr $i % 5]>0} {set p [concat $p $i]};puts $p;incr i;}
Ungolfed:
set i 1
while {$i<101} {
set p ""
if {[expr $i % 3]==0} {set p [concat $p {fizz}]}
if {[expr $i % 5]==0} {set p [concat $p {buzz}]}
if {[expr $i % 3]>0 && [expr $i % 5]>0} {set p [concat $p $i]}
puts $p
incr i
}
Racket, 125 122 bytes
(for([x(range 1 101)])(define(m n)(=(modulo x n)0))(displayln(cond[(and(m 3)(m 5))'FizzBuzz][(m 3)'Fizz][(m 5)'Buzz][x])))
Simplest approach, took some work to get it lower than 130 bytes. Inspired by the Java example.
Pretty-printed code
(for ([x (range 1 101)])
(define (m n)
(= (modulo x n) 0))
(displayln (cond
[(and (m 3) (m 5)) 'FizzBuzz]
[(m 3) 'Fizz]
[(m 5) 'Buzz]
[x])))
Python 2 REPL, 54
0;exec"print _%3/2*'Fizz'+_%5/4*'Buzz'or-~_;_+=1;"*100
Based on this answer by feersum. Essentially the same technique, only using Python's underscore variable to save 2 chars at the start.
Mathematica, 103 86 73 bytes
With 30 bytes saved thanks to @A Simmons!
f="Fizz";b="Buzz";Range@100/.{x_/;15∣x->f<>b,x_/;3∣x->f,x_/;5∣x->b}
Hoon, 126 bytes
%+
turn
(gulf [1 100])
|=
a/@
=+
[=((mod a 3) 0) =((mod a 5) 0)]
"{?:(-< "Fizz" "")}{?:(-> "Buzz" "")}{?:(=(- [| |]) <a> "")}"
Map over the list [1...100] with the function, interpolating the strings "Fizz" and "Buzz". If both mods are false, then it also interpolates the number.
This uses the fact that =+ pushes the value to the top of the context, which you can access with - and navigate with -< or -> for head/tail. Unfortunately, it looks pretty ugly because it needs a newline after runes to minimize byte count, along with not having built in operator functions.
I'm not entirely sure if this counts as a valid entry: It simply returns a list of strings to be printed by the shell, which is optimal. The other way would be to use ~& to print each element as it's mapped over, but it would still be rendered as "Fizz" or "Buzz" (with quotes) since it's a typed print, along with the shell then printing out the entire list anyways since it's the return value.
D, 130 bytes
import std.stdio,std.conv;void main(){string x;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),writeln(x?x:i.to!string)){};}
Ungolfed:
module FizzBuzz;
import std.stdio;
import std.conv;
void main() {
string x;
for (
int i;
i++ < 100;
x = ((i % 3 ? "" : "Fizz")
~ (i % 5 ? "" : "Buzz")),
writeln(x ? x : i.to!string)
){};
}
Or, building a string, for 142 bytes,
import std.stdio,std.conv;void main(){string x,y;for(int i;i++<100;x=((i%3?"":"Fizz")~(i%5?"":"Buzz")),y~=(x?x:i.to!string)~"\n"){};write(y);}
Ungolfed:
module FizzBuzz;
import std.stdio;
import std.conv;
void main() {
string x,y;
for (
int i;
i++ < 100;
x = ((i % 3 ? "" : "Fizz")
~ (i % 5 ? "" : "Buzz")),
y ~= (x ? x : i.to!string) ~ "\n"
){};
write(y);
}
C#, 174 bytes
void A(){for(int x=1;x<101;x++){if(x%15<1)Console.Write("FizzBuzz\n");else if(x%3<1)Console.Write("Fizz\n");else if(x%5<1)Console.Write("Buzz\n");else Console.WriteLine(x);}}
Ungolfed:
void A(){
for (int x = 1; x < 101; x++) {
if (x % 15 < 1) Console.Write("FizzBuzz\n");
else if (x % 3 < 1) Console.Write("Fizz\n");
else if (x % 5 < 1) Console.Write("Buzz\n");
else Console.WriteLine(x);
}
}
JavaScript, 62 bytes
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
I think I this is the shortest Javascript solution now.
Jolf, 42 33 31 bytes
Try it here! Replace ƒ with \x9f. I'm stealing ETHproduction's method of fizzbuzzing.
ƒΜz~1d|]"FizzBuzz"?%H340?%H548H
Old version, 42 bytes
γ"Fizz"ƒΜz~1d?mτͺ35H+γζ?m|3Hγ?m|5HΖ"Buzz"H
γ"Fizz" γ = "Fizz"
Μz~1d map 1..100 with the following function
?mτͺ35H if both 3 and 5 | H
+γζ return γ + ζ
m|3H else if 3 | H
γ return γ
?m|5H else if 5 | H
Ζ"Buzz" return ζ = "Buzz"
H else return H
ƒ join by newlines
I might be able to golf it down by using the dictionary in Jolf, but who would want to with such a perfect score?
Perl 6, 46 bytes
say "Fizz"x $_%%3~"Buzz"x $_%%5||$_ for 1..100
Rotor, 32 31 bytes
1N2{3%!"Fizz"~5%!"Buzz"N$?~N}\
This has one unprintable, so here's a hexdump:
0000000: 314e 7f32 7b33 2521 2246 697a 7a22 7e35 1N.2{3%!"Fizz"~5
0000010: 2521 2242 757a 7a22 4e24 3f7e 4e7d 5c %!"Buzz"N$?~N}\
Explanation:
1 Push a one to the stack.
N Push a newline.
^? Spooky invisible unprintable that pushes 100 to the stack.
2 Pushes a two to the stack.
{ Starts block.
3% Takes mod 3 of the top number on the stack.
!"Fizz" If falsy, push "Fizz".
~ Push the contents of the register.
5% Takes mod 5.
!"Buzz" If falsy, push "Buzz".
N$ Compares the top value of the stack to a newline. (this doesn't pop the values off the stack)
?~ If truthy, push the contents of the register.
N Push a newline.
}\ For loop between 2 and 100, pushing the counter to the register and stack each time.
Try it online. (note that it is very slow)
Mathematica, 83 75 73 67 62 bytes
Print/@(#/.(##&[15#->FizzBuzz,3#->Fizz,5#->Buzz]&)/@#&@Range@100)
I do not think that this could be golfed any further. Thanks to branislav for helping me golf this.
Rust, 145 137 131 bytes
Golfed
fn main(){for i in 1..101{let s=i.to_string();println!("{}",match i%15{0=>"FizzBuzz",3|6|9|12=>"Fizz",5|10=>"Buzz",_=>&(s)[..]});}}
Ungolfed
fn main() {
for i in 1..101 {
let s = i.to_string();
println!("{}", match i % 15 {
0 => "FizzBuzz",
3|6|9|12 => "Fizz",
5|10 => "Buzz",
_ => &(s)[..]
});
}
}
Uses the current stable version of Rust (1.5.0).
Javascript ES6, 77 chars
"\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i)
Test:
"\n".repeat(100).replace(/(?=\n)/g,(m,i)=>(++i%3?m:"Fizz")+(i%5?m:"Buzz")||i) == document.querySelector("pre").textContent
scg, 51 bytes
1á01°r{d[[d"Buzz"]["Fizz"d"Buzz"+]]\3%!@\5%!@"
"}m
So, does this mean that scg is a real language now? Explanation:
1 .- adds 1 to the stack
á01 .- adds 101 to the stack
°r .- range, adds array with 1-100 on the stack
{ .- start function for use in map
d .- duplicates number
[ .- array
[
d .- duplicate number again, ends up in array
"Buzz" .- wonder what this does
] .- end array
[
"Fizz"
d .- duplicate fizz
"Buzz"+ .- ends up with "FizzBuzz"
]
] .- end array. Ends up with a 2D array
\ .- gets number to calculate to the top
3% .- mod 3
! .- not, so any above 0 int turns to 0 and 0 turns to1
@ .- get array value. Now you have two choices for output
\5%!@ .- same as above but for 5.
.- now we have the correct fizzbuzz value
"\n" .- pushes newline. I do not have variables yet so no shortcuts
}m .- end function, map. output is implicit
ShapeScript, 57 bytes
0'1+0?3%1<"Fizz"*1?5%1<"Buzz"*+"#0?"1?_1<*!@"
"@'554***!#
How it works
0 Push 0 (accumulator).
' Push a string that, when evaluated, does the following:
1+ Increment the accumulator.
0? Push a copy.
3%1< Check if the remainder of its division by 3 is zero.
"Fizz"* Push "Fizz" for True, "" for False.
1? Push another copy of the accumulator.
5%1< Check if the remainder of its division by 5 is zero.
"Buzz"* Push "Buzz" for True, "" for False.
+ Concatenate the potential fizzes and buzzes.
" Push a string that, when evaluated, does the following:
# Discard the topmost stack item.
0? Push a copy of the item below it (accumulator).
"
1? Push a copy of the concatenation.
_1< Check if its length is zero.
*! Execute "#0?" once for True, zero times for False.
@ Swap the generated output with the accumulator.
" Push "\n".
"
@ Swap it with the accumulator.
'
554** Push 5 * 5 * 4 = 100.
*! Execute the '...' string 100 times.
# Discard the accumulator.
Brainfuck, 16321 3602 1597
Almost as short as Java. This is just the trivial answer generated by another program, This is still a computer generated answer, but I am sure there are way shorter solutions! The general idea is initializing the cells to 4 B F i u z. If the program has to output a number, it just goes to the first cell and manipualtes it, if it is one of the letters, it will just jump to the corresponding cell and output it.
++++++++++<<+++++++[>+++++++<-]>[>>+>+>+>++>++>++<<<<<<<-]>>+++>+++++++++++++++++>+++++++++++++++++++++>+++++++>+++++++++++++++++++>++++++++++++++++++++++++<<<<<---.<.>+.<.>>>.>.>>..<<<<<<.>++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>+++.<.>+.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-------..<.>>>.>.>>..<<<<<<.>.++.<.>--.+++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>---.+++++.<.>-----.++++++.<.>>>.>.>>..<<<<<<.>------.++++++++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-------..<.>.+.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-.++++.<.>>>.>.>>..<<<<<<.>----.++++++.<.>------.+++++++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>------.--.<.>++.-.<.>>>.>.>>..<<<<<<.>+.+.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-.++++.<.>----.+++++.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>----.---.<.>>>.>.>>..<<<<<<.>+++.-.<.>+..<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>.++.<.>--.+++.<.>>>.>.>>..<<<<<<.>---.+++++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>----.---.<.>+++.--.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>++.+.<.>>>.>.>>..<<<<<<.>-.+++.<.>---.++++.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>---.-----.<.>+++++.----.<.>>>.>.>>..<<<<<<.>++++.--.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>++.+.<.>-.++.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>-.------.<.>>>.>.>>..<<<<<<.>++++++.----.<.>++++.---.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>+++.-.<.>+..<.>>>.>.>>..<<<<<<.>.++.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>-.------.<.>++++++.-----.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.>+++++.--.<.>>>.>.>>..<<<<<<.>++..<.>.+.<.>>>.>.>>..<<<<.>>>.>..<<<<<<.>.--------.<.>++++++++.-------.<.>>>.>.>>..<<<<<<.>+++++++.-----.<.>>.>>>.>..<<<<<<.>>>.>.>>..<<<<<<.>+++++.--.<.>++.-.<.>>>.>.>>..<<<<<<.>>.>>>.>..<<<<<<.
Gol><>, 40 bytes
`e2RFL5%zR"zzuB"L3%zR"zziF"lQlRoaoC|LN|;
Updated for 0.4.0! I'm still tinkering with loops and trying to figure out how to do things best, but this is looking good so far.
Explanation
`e Push 'e', or 101
2RF ... | Execute F for loop twice - the first time activates the loop, and the
second time updates it. This effectively makes the loop start from 1
L5%z Push 1 if loop counter % 5 is 0, else 1
R"zzuB" Push "Buzz" (top of stack) number of times
L3%z Push 1 if loop counter % 3 is 0, else 1
R"zziF" Push "Fizz" (top of stack) number of times
lQ ... | If the stack is not empty...
lRo Output stack
ao Output newline
C Continue for loop
LN Otherwise, print loop counter with newline
; Terminate program
As we can see, there's a lot of abuse of R, which pops the top of the stack and executes the next instruction that many times.
APL, 56 50 bytes
⊣{1+⍵⊣⎕←∊2↑((0=3 5|⍵)/'Fizz' 'Buzz'),''(⍕⍵)}⍣100⊢1
Note: The very first ⊣ should suppress output in GNU APL. Replace it with → to get correct results in Dyalog, etc, or with portable assignment to some variable X← adding one byte.
A+, 51 bytes
(x←100)do↓⊃2↑((0=3 5|1+x)/4⊂'FizzBuzz'),⌽2↑<1↓⍕1+x;
Hexagony, 112 bytes
d{$>){*./;\.}<._.zi...><{}.;/;$@-/=.*F;>8M'<$<..'_}....>.3'%<}'>}))'%<..._>_.'<$.....};u..}....{B.;..;.!<'..>z;/
After unfolding and with colour-coded execution paths:

Diagram created with Timwi's HexagonyColorer.
Finally got around to finishing this. I had written an ungolfed solution weeks ago, but wasn't entirely happy with it so I never actually golfed it. After revisiting it the other day, I found a way to simplify the ungolfed solution slightly, and while I think there might still be a better way to approach the problem in general, I decided to golf it this time. The current solution is far from optimal, and I think it should actually fit in side-length 6 instead of 7. I'll give this a go over the next days, and when I'm happy with the result will add a full explanation.
F#, 129 116 113 111
Seq.iter(fun x->printfn"%s"(["Fizz";"";""].[x%3]+(if x%5=0 then"Buzz"elif x%3>0 then string x else""))){1..100}
C++, 130 126 119 115
#include<iostream>
int i;int main(){for(auto&o=std::cout;++i<101;o<<'\n')i%3?o:o<<"Fizz",i%5?i%3?o<<i:o:o<<"Buzz";}
Python 2, 72 bytes
for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'
Not as clever as feersum's solution, but it avoids casting exec magic.
EDIT: with just two more parentheses, it works in Python 3 AND Python 2:
for x in range(100):print(('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n')
Scratch, 203 185 bytes
Bytes counted from the golfed textual representation, per this meta post. Scratch is not very space-efficient.
say is the closest thing to a stdout Scratch has: the sprite displays a speech bubble containing whatever it is saying. In practice, a wait n secs block would be needed to actually read this output, but for the purposes of this challenge this code fulfills the requirements.
Pyth, 30
VS100|+*!%N3"Fizz"*!%N5"Buzz"N
Explanation:
VS100|+*!%N3"Fizz"*!%N5"Buzz"N
VS100 : for N in range(1,101)
| : logical short-circuiting or
+*!%N3"Fizz" : add "Fizz" * not(N % 3)
: Since not gives True/False this is either "" or "Fizz"
*!%N5"Buzz" : Same but with 5 and Buzz
N : Otherwise N
: The output of the | is implicitly printed with a newline
Groovy, 69 Bytes
(1..100).each{i->println i%15?(i%5?(i%3?i:'Fizz'):'Buzz'):'FizzBuzz'}
MoonScript, 83 82 bytes
[print(i%15==0and"FizzBuzz"or(i%3==0and"Fizz")or(i%5==0and"Buzz")or i) for i=1,100]
Groovy, 83 80 bytes
(1..100).each{def f=it%3,b=it%5;println!f&&!b?'FizzBuzz':!f?'Fizz':!b?'Buzz':it}
Swift, 75 bytes
for n in 1...100{print(n%3*n%5>0 ?n:(n%3>0 ?"":"Fizz")+(n%5>0 ?"":"Buzz"))}
Minkolang, 50 bytes
"d"[i1+d5%6&"Buzz"0c3%6&"Fizz"I1-3&N6@0gx(O)25*O].
Explanation
"d"[...]. For loop that loops from 0 to 99, then stops
i1+ Loop counter + 1 (so it's 1 to 100)
d5%6&"Buzz" Divisibility test by 5, skips "Buzz" if not divisible
0c3%6&"Fizz" Divisibility test by 3, skips "Fizz" if not divisible
I1- Length of stack minus 1 (0 if there's no Fizz or Buzz)
3&N6@ Output as integer if ^ is 0, skip character output otherwise
0gx(O) Dump the loop counter and output "Fizz"/"Buzz"/"FizzBuzz"
25*O Print newline
Bubblegum, 131 129 bytes
0000000: 4d cd bb 0d c4 30 0c 03 d0 9e db e8 63 7d da 14 d9 e5 M....0......c}....
0000012: 06 b8 26 d3 e7 60 0b 38 56 a6 29 10 4f a0 b8 3f cf 03 ..&..`.8V.).O..?..
0000024: c7 f5 fd 3d 3b 27 ea 84 5d 89 9c 8f 18 c4 77 3c 75 40 ...=;'..].....w<u@
0000036: 72 2e 4d 63 55 a8 d1 5c 63 fa 82 f6 7f 6e 02 1b da d8 r.McU..\c....n....
0000048: b6 84 b1 ee a3 bb c1 49 f7 80 8f ee ac 2f c5 62 7d 8d .......I...../.b}.
000005a: be 0a 8b f4 10 c4 e8 c1 7a 24 82 f5 1c 3d 0d 49 7a 06 ........z$...=.Iz.
000006c: 72 f4 64 bd 14 c5 7a 8d 5e 85 22 bd 05 3d 7a b3 de 89 r.d...z.^."..=z...
000007e: 26 fd 05 &..
The above hexdump can be reversed with xxd -r -c 18 > fizzbuzz.bg.
Compression has been done with Python's zlib, which uses the DEFLATE format but obtains a better ratio than (g)zip.
Thanks to @Sp3000 for -2 bytes!
Scala, 103 94 bytes
for{i<-1 to 100;s=(if(i%3==0)"Fizz"else"")+(if(i%5==0)"Buzz"else"")}println(if(s=="")i else s)
thx @Ben (shortened by 9 bytes)
Snowman 1.0.2, 97 chars
)1vn101nR:du*_/3NmO0eQ)(#5NmO0eQ}~(~%@or(%nO?_/)#%@{%@tS?)aRsP@@"Fizz"_aRsP\"Buzz"aRsP?)10wRsP;aE
How does it work, you ask? ... I have no idea. I might edit in a full explanation at some point if I ever decide to try to understand this again.
(Pulled directly from Snowman's examples directory.)
Scala, 90 bytes
for(i<-1 to 100)println{var s="";if(i%3==0)s="Fizz";if(i%5==0)s+="Buzz";if(s=="")i else s}
OCaml, 106
for i=1to 100do
let(!)n=i mod n<1and p=Printf.printf
in!3&p"Fizz"=();!5&p"Buzz"=()or!3||p"%d"i=();p"
"done
Apparently this isn't a very good attempt as the shortest one on anarchy golf is only 97.
O, 53 52 bytes
I'm sure that there will be a better way to do this. Thanks to kirbyfan64sos for the implicit J.
"Buzz"JA.*1mrl{.3%{.5%{}{;J}?}{"Fizz"\5%{}{J+}?}?p}d
rs, 92 91 bytes
(_)^^(100)
+^(_+)(_)/\1 \1\2
\b((___)+)\b/Fi;\1
\b(_{5})+\b/Bu;
;_*/zz
\b(_+)\b/(^^\1)
/\n
Saved 1 byte thanks to @MartinBüttner!
Live demo. (It may take a bit to run!)
MSX-BASIC, 106 bytes
1FORI=1TO100:IFIMOD3=0ANDIMOD5=0THEN?"FizzBuzz"ELSEIFIMOD3=0THEN?"Fizz"ELSEIFIMOD5=0THEN?"Buzz"ELSE?I
2NEXT
The one-liner version to be executed in direct mode would be 120 bytes because all of the extra NEXTs needed before the ELSEs:
FORI=1TO100:IFIMOD3=0ANDIMOD5=0THEN?"FizzBuzz":NEXTELSEIFIMOD3=0THEN?"Fizz":NEXTELSEIFIMOD5=0THEN?"Buzz":NEXTELSE?I:NEXT
C#, 155 142 Bytes
class a{static void Main(){for(int i=0;i++<100;){var s="";if(i%3<1)s="Fizz";if(i%5<1)s+="Buzz";if(s=="")s=i+"";System.Console.WriteLine(s);}}}
Added as an alternate approach to the example using LINQ
Thanks @Riokmij!
C (83 characters)
Because misusing a (POSIX conformant) printf is not that bad, after all:
i;main(){while(++i<101)printf(i%3?i%5?"%2$d\n":"%s\n":"Fizz%s\n",i%5?"":"Buzz",i);}
Windows Batch, 172
@setlocal enableDelayedExpansion&for /l %%N in (1 1 100) do @(set v=&set/a1/(%%N%%3^)||set v=Fizz&set/a1/(%%N%%5^)||set v=!v!Buzz&if defined v (echo !v!)else echo %%N)2>nul
haxe, 110 bytes
class Main{
static function main()
for(i in 1...101)
Sys.println(i%3<1?"Fizz"+(i%5<1?"Buzz":""):i%5<1?"Buzz":i);
}
(newlines and indents added for clarity)
Haxe isn't much of a golfing language … I was trying to do something with enumerators:
class Main{
static function main()
for(i in 1...101)
Sys.println(
switch(i){
case _%3=>0:i%5<1?"FizzBuzz":"Fizz";
case _%5=>0:"Buzz";
case _:i;
}
);
}
But 140 bytes. :I
C# using LINQ, 168 186
using System.Linq;class A{static void Main(){foreach(var s in Enumerable.Range(1,100).Select(n=>n%3==0?n%5==0?"FizzBuzz":"Fizz":n%5==0?"Buzz":n.ToString()))System.Console.WriteLine(s);}}
UniBasic, 106 bytes
FOR I=1 TO 100;D='';IF MOD(I,3)=0 THEN D='Fizz'
IF MOD(I,5)=0 THEN D:='Buzz'
IF D='' THEN D=I
CRT D;NEXT I
MUMPS, 56 54 bytes
f i=1:1:100 w:i#5=0 "Fizz" w:i#3=0 "Buzz" w:$X<3 i w !
What's this w:$X<3 i thing, you ask? $X is a magic variable (an "intrinsic") that stores the horizontal position of the output cursor (as a number of characters from the left edge of the terminal). w is the abbreviated form of the WRITE command. The syntax command:condition args is a postconditional - "if condition, then do command args".
So we're checking whether the output cursor has been advanced more than two characters (which would mean that at least one of "Fizz" or "Buzz" has been written to the terminal), and if not, writing i to the terminal. The $X variable - and hence, this sort of deep inseparability from the terminal - is a first-class feature of MUMPS. Yikes.
Commodore Basic, 87 bytes
1F┌I=1TO100:F=F+1:B=B+1:IFF=3T|?"FIZZ";:F=0
2IFB=5T|?"BUZZ";:B=0
3IFF>0A/B>0T|?I;
4?:N─
Or in "shifted mode" to get both lower- and upper-case letters, but with the byte values of lowercase and uppercase swapped relative to ASCII-1967 (press COMMODORE+SHIFT):
1fOi=1to100:f=f+1:b=b+1:iff=3tH?"Fizz";:f=0
2ifb=5tH?"Buzz";:b=0
3iff>0aNb>0tH?i;
4?:nE
Usual PETSCII-to-Unicode substitutions: ┌ = SHIFT+O, | = SHIFT+H, / = SHIFT+N, ─ = SHIFT+E
Commodore Basic doesn't have a "modulus" operation, so I need to use alternate methods to figure out when to print what: keeping a pair of counters turns out to be fewer bytes than dividing and checking for integer-ness. It also doesn't have a true logical "and" (despite the manual saying otherwise), so I need to do an explicit comparison against zero to decide if I should print the plain number.
C#, 128 126 125 124 bytes
class A{static void Main(){for(var i=0;i++<100;)System.Console.Write("{0:#}{1:;;Fizz}{2:;;Buzz}\n",i%3*i%5>0?i:0,i%3,i%5);}}
89 bytes without the boilerplate code around.
Done with the use of C#'s conditional formatting.
With two section separators ;, Fizz or Buzz are printed if the value from their condition is zero.
Saved a total of 4 bytes thanks to @RubberDuck, @Timwi and @Riokmij.
GolfScript, 37 bytes
100,{)..3%!'Fizz'*\5%!'Buzz'*+\or n}/
Python 2, 148 133 Bytes
def f(n):
if n%3+n%5<1:return"FizzBuzz"
if n%5<1:return"Buzz"
if n%3<1:return"Fizz"
return n
for x in map(f,range(1,101)):print x
Bash + coreutils, 41 bytes
seq 100|sed 5~5cBuzz|sed 3~3s/[^B]*/Fizz/
You can't seem to do better without cheating: the 12-byte answers on that server simply invoke its gs2 interpreter with a 1-byte FizzBuzz program...
zsh, 65 63 bytes
repeat 100 x=|let ++i%3||x=Fizz&&let i%5||x+=Buzz&&<<<${x:-$i}
Changed echo to <<<. It's now 2 bytes shorter, because <<< doesn't need a space.
repeat 100 x=|let ++i%3||x=Fizz&&let i%5||x+=Buzz&&echo ${x:-$i}
Ruby, 50 bytes
Requires version 1.8, which seems to be popular among golfers:
1.upto(?d){|n|puts'FizzBuzz
'[i=n**4%-15,i+13]||n}
In modern Ruby, you replace ?d with 100 for a 51-byte solution.
This seems to be the world record.
Lua, 72 bytes
for i=1,100 do print(({'FizzBuzz','Buzz','Fizz',i})[i^2%3+i^4%5*2+1])end
Tied the world record! (Please don't cheat the rankings there.)
STATA, 115 bytes
qui{
set ob 100
g a="Fizz" if!mod(_n,3)
g b="Buzz" if!mod(_n,5)
g c=a+b
replace c=string(_n) if c==""
}
l c,noo noh
qui{} suppresses output for everything in that block. First set the number of observations to be 100. Then generate variable a to be "Fizz" for every observation where its index number is divisible by 3. Then generate variable b to be "Buzz" for every observation where its index number is divisible by 5. Generate variable c to be the concatenation of these two. Then, replace c with the index number (STATA uses 1 indexing) if it is still an empty string. Then list the results of c in a table without observation numbers or headers.
Only works in the "real" STATA interpreter. I need to add functions and conditions to the online interpreter for it to work there.
A different solution in 116 bytes:
forv x=1/100{
if!mod(`x',3){
di"Fizz"_c
if!mod(`x',5) di"Buzz"_c
}
else if!mod(`x',5) di"Buzz"_c
else di `x' _c
di
}
This solution goes through a for loop and checks whether the loop variable is divisible by 3 or not. If it is, it prints "Fizz". Then it checks if it is divisible by 5 and prints "Buzz". Otherwise, it checks if it is divisible by 5 and prints "Buzz". If not, it prints the loop variable.
Python 3, 59 bytes
Based on @feersum's answer.
for i in range(100):print(i%3//2*"fizz"+i%5//4*"buzz"or-~i)
C, 74 bytes
main(i){for(;i<101;puts(i++%5?"":"Buzz"))printf(i%3?i%5?"%d":0:"Fizz",i);}
The 0 argument to printf instead of "" is fishy, but seems to work on most platforms I try it on. puts segfaults when you try the same thing, though. Without it, you get 75 bytes.
There are 73-byte solutions that work on anarchy golf, and I found one digging around in the right places on the internet, but they rely on platform-specific behavior. (As you might have guessed, it's something of the form puts("Buzz"±...).)
Perl 5, 49 bytes
46 bytes script + 3 bytes -E"..."
Using say (which requires -E"...") can reduce this further to 46 bytes since say automatically includes a newline (Thanks @Dennis!):
say'Fizz'x!($_%3).Buzz x!($_%5)||$_ for 1..100
Perl 5, 50 bytes
print'Fizz'x!($_%3).Buzz x!($_%5)||$_,$/for 1..100
Labyrinth, 94 bytes
"):_1
\ } 01/3%70.105
" : @ " .
" =";_""..:221
+ _
"! 5%66.117
_:= " .
="*{"..:221
Sub-100! This was a fun one.
Explanation
Let's start with a brief primer on Labyrinth – feel free to skip this if you're already familiar with the basics:
Labyrinth has two stacks – a main stack and an auxiliary stack. Both stacks have an infinite number of zeroes at the bottom, e.g.
+on an empty stack adds two zeroes, thus pushing zero.Control flow in Labyrinth is decided by junctions, which look at the top of the stack to determine where to go next. Negative means turn left, zero means go straight ahead and positive means turn right... but if we hit a wall then we reverse direction. For example, if only straight ahead and turn left are possible but the top of the stack is positive, then since we can't turn right we turn left instead.
Digits in Labyrinth pop
xand push10*x + <digit>, which makes it easy to build up large numbers. However, this means that we need an instruction to push 0 in order to start a new number, which is_in Labyrinth.
Now let's get to the actual code!
Red
Execution starts from the " in the top-left corner, which is a NOP. Next is ), which increments the top of the stack, pushing 1 on the first pass and incrementing n on every following pass.
Next we duplicate n with :. Since n is positive, we turn right, executing } (shift top of main stack to auxiliary) and :. We hit a dead end, so we turn around and execute } and : once more, leaving the stacks like
Main [ n n | n n ] Aux
Once again, n is positive and we turn right, executing _101/ which divides n by 101. If n is 101 then n/101 = 1 and we turn into the @, which terminates the program. Otherwise, our current situation is
Main [ n 0 | n n ] Aux
Orange 1 (mod 3)
3 turns the top zero into a 3 (10*0 + 3 = 3) and % performs a modulo. If n%3 is positive, we turn right into the yellow ". Otherwise we perform 70.105.122:.., which outputs Fizz. Note that we don't need to push new zeroes with _ since n%3 was zero in this case, so we can exploit the infinite zeroes at the bottom of the stack. Both paths meet up again at light blue.
Light blue
The top of the stack is currently n%3, which could be positive, so the _; just pushes a zero and immediately pops it to make sure we go straight ahead, instead of turning into the @. We then use = to swap the tops of the main and auxiliary stacks, giving:
Main [ n | n%3 n ] Aux
Orange 2 (mod 5)
This is a similar situation to before, except that 66.117.122:.. outputs Buzz if n%5 is zero.
Dark blue
The previous section leaves the stacks like
Main [ n%5 | n%3 n ] Aux
{ shifts the n%3 back to the main stack and * multiplies the two modulos.
If either modulo is zero, the product is zero so we go straight into yellow. = swaps the top of the stacks and _ pushes a zero to make sure we go straight ahead, giving
Main [ n 0 | 0 ] Aux
Otherwise, if both modulos are nonzero, then the product is nonzero and we turn right into green. = swaps the tops of the stacks, giving
Main [ n | (n%5)*(n%3) ] Aux
after which we use : to duplicate n, turn right, then use ! to output n.
Purple
At this point, the main stack has either one or two items, depending on which path was taken. We need to get rid of the zero from the yellow path, and to do that we use +, which performs n + 0 in some order for both cases. Finally, \ outputs a newline and we're back at the start.
Each iteration pushes an extra (n%5)*(n%3) to the auxiliary stack, but otherwise we do the same thing all over again.
Lua, 88 86 bytes
Saved 2 bytes thanks to @Mauris
I'm sure this can be golfed more, any suggestions are welcome.
for i=1,100 do n=(i%3<1 and"Fizz"or"")..(i%5<1 and"Buzz"or"")print(n~=""and n or i)end
TI-BASIC, 59 bytes
For(X,1,ᴇ2
int(ln(gcd(X,15→J ;[3 divides X] + [5 divides X]
X
If J
sub("FizzBuzz",7-2gcd(X,3),4J
Disp Ans
End
Or at the same length:
For(X,1,ᴇ2
gcd(X,15→J
X
If ln(J
sub("FizzBuzz",5^(J=5),4int(ln(J
Disp Ans
End
Both programs use the fact that ⌊ln(3)⌋ = ⌊ln(5)⌋ = 1 and ⌊ln(15)⌋ = 2.
There could be another byte to golf off somewhere, but I can't find it. By comparison, here's the naïve approach at 67 bytes:
For(X,1,ᴇ2
"Fizz
If fPart(X/3:X
If not(fPart(X/5:"Buzz
If not(fPart(X/15:"FizzBuzz
Disp Ans
End
TI-BASIC's quirks lengthen the program in two ways:
- TI-BASIC needs two bytes to encode every lowercase letter other than
i(which represents the imaginary unit). - Empty strings are not supported:
sub("FizzBuzz",5,0and""+"Buzz"both throw errors.
dc, 64 62 bytes
[[Fizz]P]sI[[Buzz]P]sU[dn]sNz[zdd3%d0=Ir5%d0=U*0<NAPz9B>L]dsLx
Ungolfed:
[[Fizz]P]sI # macro I: print "Fizz"
[[Buzz]P]sU # macro U: print "Buzz"
[dn]sN # macro N: print current stack depth
z # increase stack depth
[ # Begin macro
zdd # Get current stack depth and ducplicate it twice
3%d0=I # Check modulo 3 and leave a duplicate. If it's 0, run macro I
r # Rotate top two elements, bringing up the stack depth again
5%d0=U # Check modulo 5 and leave a duplicate. It it's 0, run macro U
* # Multiply the duplicates of modulos of 3 and 5 ...
0<N # ... if it's not 0, run macro N
AP # Print a newline (`A` is 10)
# The macro leaves the stack with one more element each time
z9B>L # Run macro L if stack depth is less than "ninety eleven" (101)
] # End macro
dsLx # store the macro in register L and execute it
80386 machine code + DOS, 75 bytes
Hexdump of the code:
0D 0A 24 B1 64 33 C0 BA-03 05 BB 00 01 40 50 FE
CE 75 0C 83 EB 04 66 C7-07 42 75 7A 7A B6 05 FE
CA 75 0C 83 EB 04 66 C7-07 46 69 7A 7A B2 03 84
FF 74 0C D4 0A 04 30 4B-88 07 C1 E8 08 75 F4 52
8B D3 B4 09 CD 21 5A 58-E2 C0 C3
Source code (TASM syntax):
.MODEL TINY
.CODE
.386
org 100h
MAIN PROC
db 13, 10, '$'
mov cl, 100
xor ax, ax
mov dx, 503h
main_loop:
mov bx, 100h
inc ax
push ax
dec dh
jnz short buzz_done
sub bx, 4
mov dword ptr [bx], 'zzuB'
mov dh, 5
buzz_done:
dec dl
jnz short fizz_done
sub bx, 4
mov dword ptr [bx], 'zziF'
mov dl, 3
fizz_done:
test bh, bh
jz short num_done
decimal_loop:
aam;
add al, '0'
dec bx
mov [bx], al
shr ax, 8
jnz decimal_loop
num_done:
push dx
mov dx, bx;
mov ah, 9
int 21h
pop dx
pop ax
loop main_loop
ret
MAIN ENDP
END MAIN
This code counts from 1 to 100 in ax, building the output message from the end to the beginning. The end of the message (newline and the $ character that DOS uses for end-of-message flag) appears at the beginning of the code:
db 10, 10, '$'
It's executed as a harmless instruction (or ax, 240ah). I could put it in a more conventional place, like after the end of the code, but having it at address 0x100 has a benefit.
The code also uses 2 additional counters:
- Counting from 3 to 0 in
dl - Counting from 5 to 0 in
dh
When a counter reaches 0, it pushes the string Fizz or Buzz to the end of the output message. If this happens, bx will be decreased, and bh will be zero. This is used as a condition for outputting the number in a decimal form.
Note: I am using 32-bit data here. This won't work on a pre-386 computer.
Swift, 77 bytes
for i in 1...100{print(i%15<1 ?"FizzBuzz":i%3<1 ?"Fizz":i%5<1 ?"Buzz":"\(i)")}
MATLAB, 94 bytes
for i=1:100 t=mod(i,3);f=mod(i,5);s=[(t&f)*num2str(i) ~t*'Fizz' ~f*'Buzz' ''];disp(s(s>0));end
So this new code is a slight improvement on the one below. Rather than using arrayfun() which is quite costly in characters as it requires 'UniformOutput','false' to get it to work, I have simply made it a for loop - because the range of numbers is hard coded, there is no need to use a function as I had done in my last edit. Removing it from the function saves another 10 characters.
This does basically the same thing, but rather than making all the strings first, in makes them one by one in a for loop and displays them. This actually also means char() only has to be used once (in the other one it was used a second time to display everything). Having the loop means I can use variables to store the results of mod(i,3) and mod(i,5) so they don't need calculating twice. The nonzeros() function has also now been removed, instead opting for storing to a variable then only printing anything which is not equal to zero. This solution when you run it also doesn't print ans= before the first line.
Thanks to @flawr for the tips, saved 4 bytes.
Old code:
MATLAB, 118 bytes
char(arrayfun(@(x) char(nonzeros([(mod(x,3)&&mod(x,5))*num2str(x) ~mod(x,3)*'Fizz' ~mod(x,5)*'Buzz'])'),1:100,'Un',0))
A bit of fun with multiplying strings with scalars. Basically the output of ~mod(x,5) and ~mod(x,3) are multiplied by 'Fizz' and 'Buzz' respectively which produces either zeros (blanks) or one or both of the words. (mod(x,3)&&mod(x,5))) is basically when the number is neither a multiple of 3 nor 5 which is multiplied by the number as a string to get either zeros or the number.
These are then concatenated into an array which then has all of the zeros removed using nonzeros() and then resulting array transposed to be in the right direction for conversion to a character string.
Finally once all numbers have been processed by arrayfun(), the resulting cell array of arrays is passed to char() which converts it to a cell array of strings. Because there is no ; at the end of the string, the output is dumped to the console.
It might be possible to make it smaller, I'm looking ;)
Fortran, 213 bytes
character(len=8)::o
do i=1,100
if(mod(i,15)==0)then;write(*,*)'FizzBuzz'
elseif(mod(i,3)==0)then;write(*,*)'Fizz'
elseif(mod(i,5)==0)then;write(*,*)'Buzz'
else;write(o,'(i8)')i;write(*,*)adjustl(o)
endif;enddo;end
Not as graceful as the golf languages. I could save bytes using print instead of write, but print indents 1 space without a format specifier which would increase the byte count instead. Likewise I lose bytes printing the number because Fortran doesn't like left-justified output for numbers. I didn't bother sticking it all on one line as newlines and semicolons are both 1 byte -- no savings.
Groovy, 71 bytes
(1..100).each{i->println i%15<1?'FizzBuzz':i%5<1?'Buzz':i%3<1?'Fizz':i}
VB.Net, 147 146 bytes
Module F
Sub Main()
For i=1To 100
Dim a=i Mod 3,b=i Mod 5
Console.WriteLine("{0:#}{1:;;Fizz}{2:;;Buzz}",If(a*b>0,i,0),a,b)
Next
End Sub
End Module
It uses the same conditional formatting trick as the C# answer by Pierre-Luc Pineault.
UPDATED: saved 1 byte thanks to Brian J
Ruby, 59
I wanted to make a Ruby version using the slick modulo/integer-division/string-multiplication trick from feersum's Python answer (though unfortunately Ruby doesn't handle string multiplication the same way, so I spent some bytes on that):
100.times{|i|puts "#{i+1}\r"+"Fizz"*(i%3/2)+"Buzz"*(i%5/4)}
Note that this uses a carriage return \r without a newline. I don't know how portable this is; it works on my Linux and should work on Linux in general, as well as on Mac, but I'm not sure how Windows handles it. Without that, here's a 61-byte version:
100.times{|i|puts ("Fizz"*(i%3/2)+"Buzz"*(i%5/4))[/.+/]||i+1}

















