i-is it that time of the day already anons? t-time to post our best fizzbuzz?
pub fn fizzbuzz(range: u64) { for i in 0..range { if i % 15 == 0 { println!("fizzbuzz"); continue; } if i % 3 == 0 { println!("fizz"); continue; } if i % 5 == 0 { println!("buzz"); continue; } } }
t. mad c++let that cant read my code because he is a retarded boomer c++let. do you even know what println!() does? lmao
Aiden Hernandez
pub fn fizzbuzz(range: u64) { for i in 1..range { match (i % 3, i % 5) { (0, 0) => println!("fizzbuzz"), (0, _) => println!("fizz"), (_, 0) => println!("buzz"), _ => println!("{}", i), } } }
Mason Bailey
wtf i love rust now
James Nelson
this is slower and worse than my implementation because match is doing two comparisons by default.
Liam Parker
>this is slower and worse than my implementation It is exactly the same speed as your implementation (when your implementation is corrected to print the number if it isn't divisible by 3 or 5 as per correct fizzbuzz behavior) Stop trying to outsmart the compiler when you don't even know what you're doing
Austin Collins
BTFO
Jack Clark
>It is exactly the same speed as your implementation wrong.
I think this is realistically the most expressive thing you can do in Python 3, ignoring performance from typing import List, Tuple, Callable from itertools import count, islice def fizzbuzz(func: Callable[[int], Tuple[int, int]], nums: List[int]): for i in nums: pair = func(i) if pair == (0,0): yield 'fizzbuzz' elif not pair[0]: yield 'fizz' elif not pair[1]: yield 'buzz' else: yield i
list(islice(fizzbuzz(lambda i: (i % 3, i % 5), count(1)), 15))
Dominic Taylor
Since when does wrapping simple concepts in pointless abstractions qualify as expressiveness?
Gavin Brown
it doesn't that was the point
no matter how fancy and built-in your range, tuples, lazy evaluation, and anonymous functions are, imperative languages have a limit in expressiveness.
Xavier Murphy
Wouldn’t this print an extra “fizz” and “buzz” in the event of ‘n % 15 == 0’ ?
15 satisfies all three of your conditionals and you don’t force the last two to only work if the first of the three already executed through something like an else if statement
from typing import List, Optional, Callable from itertools import count, islice def fizzbuzz(nums: List[int], fizz: Callable[[int], bool], buzz: Callable[[int], Optional[int]]): for i in nums: f = 'fizz' if fizz(i) else None b = 'buzz' if buzz(i) else None yield (f,b) if any((f, b)) else i
list(islice((fizzbuzz(count(1), lambda i: i % 3 == 0, lambda i: i % 5 == 0)), 15))
this is probably better if we relax the requirement that 'fizzbuzz' be a single string and return a tuple instead.
def FizzBuzz_numbers(N): number=0 while numpy.floor(float(N)/float(16))==0: N=increment(N) if Fizzbuzz_table[N]=="Fizz": number="Fizz" else: if Fizzbuzz_table[N]=="Buzz": number="Buzz" else: if Fizzbuzz_table[N]=="FizzBuzz": number="FizzBuzz" else: number=n+Fizzbuzz_table[N]-1 print(str(number))
while 1==1: FizzBuzz_numbers(1) n=n+15
Jaxson Lee
PROGRAM FIZZBUZZ INTEGER t
DO 10 t = 1, 100 IF (MOD(t, 15) .EQ. 0) THEN PRINT *, 'FIZZBUZZ' ELSEIF (MOD(t, 5) .EQ. 0) THEN PRINT *, 'BUZZ' ELSEIF (MOD(t, 3) .EQ. 0) THEN PRINT *, 'FIZZ' ELSE PRINT *, t ENDIF 10 CONTINUE
END PROGRAM FIZZBUZZ
Wyatt Collins
Pre-triggering for Jow Forums's comfort, VBScript. Sub FizzBuzz(ByVal ANum) If ANum Mod 15 = 0 Then Echo "Fizzbuzz" ElseIf ANum Mod 5 = 0 Then Echo "Buzz" ElseIf ANum Mod 3 = 0 Then Echo "Fizz" Else Echo ANum End If End Sub