4 ms·
I had no experience with array languages and decided to give it a try. It took me 4 hours to write FizzBuzz using only Uiua docs for help: # create an array
by ivanjermakov 3y ago
I had no experience with array languages and decided to give it a try.
It took me 4 hours to write FizzBuzz using only Uiua docs for help:
# create an array of number 1-100
ns ← ∵(+1)⇡[100]
# make a copy of it in a string form "1"-"100"
nsStr ← ∵(□$"_") ns
# every i % 3 == 0 is replaced with "Fizz", everything else is ""
f ← ∵(□▽∶ "Fizz" =0◿3) ns
# every i % 5 == 0 is replaced with "Buzz", everything else is ""
b ← ∵(□▽∶ "Buzz" =0◿5) ns
# every i % 3 == 0 && i % 5 == 0 is replaced with "FizzBuzz", everything else is ""
fb ← ∵(□▽∶ "FizzBuzz" × =0◿5∶ =0◿3 .) ns
# combine them into a 2D array
gs ← [nsStr f b fb]
# run a columnwise map
# | pick the greatest string of each column
# | |
⍉ ≡ (⊡⊢⇌⌂.) ⍉gs
Inability to use maximum function with arrays of different sizes is a bummer, I had to workaround it with grade and pick.
- vanderZwan 3y agoThat's a good start! I'm not exactly great with array langauges myself, but I think it's simpler to fill an array with □"Fizz", one with □"Buzz", one with □"FizzBuzz", then create another indexing array and use pick: ⍉[∵(□$"_"+1)⇡100 [⍥.99□"Fizz"] [⍥.99□"Buzz"] [⍥.99□"FizzBuzz"]] +∵(×2=0◿5+1)⇡100 ∵(=0◿3+1)⇡100 ≡⊡ ⍉ There are probably a few more simplifications experienced array programmers can apply.
- ivanjermakov 3y agoSmart!
- zellyn 3y agohttps://code.jsoftware.com/wiki/NYCJUG/FizzBuzz https://code.jsoftware.com/wiki/NYCJUG/FizzBuzz gives a solution in J of: FB=:((0 i.~15 3 5|]){::'FizzBuzz';'Fizz';'Buzz';":)"0 FB i.100 I unfortunately don't know enough J or Uiua to be able to translate that Perhaps someone else can step in!
- vanderZwan 3y agoLuckily the Uiua language creator stepped in to help us out :)
- kaikalii 3y agoThat's some dedication! You can indeed get the maximum item in an array with `/↥`. Here is my fizzbuzz solution: (https://uiua.org/pad?src=fizzbuzz%20%E2%86%90%20%28%0A%20%20%E2%8D%98%E2%8B%AF%5B%3D0%E2%97%BF3%E2%88%B6%3D0%E2%97%BF5.%5D.%0A%20%20%21%26p_%28%26p%22fizz%22%3B%29_%28%26p%22buzz%22%3B%29_%28%26p%22fizzbuz%22%3B%29%0A%29%0A%E2%88%B5fizzbuzz%2B1%E2%87%A120 https://uiua.org/pad?src=fizzbuzz%20%E2%86%90%20%28%0A%20%20...)
- ivanjermakov 3y agoNeat solution! Yes, I'm aware of `/↥`, but it finds maximum within a single array of values of the same shape. But what if I have two values of the same shape? E.g. `↥[][1]` throws an error. So I have to either `fill` them to the same shape or use `grade`.
- sullyj3 3y agoThe fact that you embed the entire program in the URL is a hilarious demonstration of its brevity