# Code-golfing FizzBuzz

**URL:** <https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354>\
**Category:** General Usage\
**Created:** [November 16, 2019, 3:00am UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354 "2019-11-16T03:00:44Z")\
**Posts on this page:** 7\
**Page:** 5

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 8, 2023, 5:10pm UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/82 "2023-03-08T17:10:05Z")

</div>

This is just delightful. @gbaraldi posted on Slack so I got to decipher it without explanation, which took me a while. What a nice puzzle. 👏

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [March 9, 2023, 11:09am UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/83 "2023-03-09T11:09:36Z")

</div>

> [@alemelis](#):
>
> `println(max("Fizz"^(1>i%3)*"Buzz"^(1>i%5),"$i"))`

Thanks for the explanation!

Sorry if this was mentioned before (my eyes glaze over a bit at all of this arcana), but does `\n` count as 2 bytes, or 1? If 1, wouldn’t `print(...,"$i\n")` be shorter?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 9, 2023, 11:18am UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/84 "2023-03-09T11:18:50Z")

</div>

> [@kevbonham](#):
>
> does `\n` count as 2 bytes, or 1? If 1, wouldn’t `print(...,"$i\n")` be shorter

No, because you’d need the `\n` in the Fizz and Buzz parts as well. It’s also bytes of source code that count, so at best you could insert a literal newline byte.

---

<div class="post-metadata">

**Author:** ![alemelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alemelis/32/208433_2.png) [@alemelis](https://discourse.julialang.org/u/alemelis)\
**Post date:** [March 9, 2023, 11:47am UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/85 "2023-03-09T11:47:35Z")

</div>

correct, `\n` is two characters, hence two bytes. It’s better to type in directly the newline in certain cases. Say you have

```julia
println("abc\nabc")

```

this (19bytes) can be _shorter_ (17bytes)

```julia
print("abc
abc
")

```

---

<div class="post-metadata">

**Author:** ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)\
**Post date:** [March 9, 2023, 6:59pm UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/86 "2023-03-09T18:59:22Z")

</div>

> [@alemelis](#):
>
> how do you know that such solution exists?

> **[Rankings: Holes](https://code.golf/rankings/holes/fizz-buzz/julia/bytes)**
>
> Fizz Buzz in Julia in bytes.

Of course, if we trust that site not to be trolling us.

---

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [March 9, 2023, 7:21pm UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/87 "2023-03-09T19:21:45Z")

</div>

> [@fph](#):
>
> Of course, if we trust that site not to be trolling us.

The question was about existence of a solution of given lengths using particular methods not whether any possible solutions of specific lengths.

---

<div class="post-metadata">

**Author:** ![alemelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alemelis/32/208433_2.png) [@alemelis](https://discourse.julialang.org/u/alemelis)\
**Post date:** [March 9, 2023, 8:01pm UTC](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354/88 "2023-03-09T20:01:50Z")

</div>

They take code golfing very seriously and the website code is open-source. Loopholes and exploits are fixed readily. I trust that the solution is legit

[Previous page](https://discourse.julialang.org/t/code-golfing-fizzbuzz/95354.md?page=4)
