Quantcast
[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology


View post   

[ Toggle deleted replies ]
File: 160 KB, 1600x1120, 1527344555462.jpg [View same] [iqdb] [saucenao] [google] [report]
66092980 No.66092980 [Reply] [Original] [archived.moe] [rbt]

Write the shortest FizzBuzz in your favorite language.

>> No.66093007

Boobs

>> No.66093022

Her chest reminds me of the cores in Armored Core.

>> No.66093030

One, two, fizz, four, buzz, fizz, seven, eight, fizz, buzz, eleven, fizz, thirteen, fourteen, fizzbuzz, sixteen, seventeen, fizz, nineteen, buzz, fizz, twenty two, twenty three, fizz, buzz, twenty six, fizz, twenty eight, twenty nine, fizzbuzz...

I like English.

>> No.66093033

import fizzbuzz
fizzbuz.fizzbuzz()

>> No.66093047
File: 988 KB, 1000x1000, 1527282301544.png [View same] [iqdb] [saucenao] [google] [report]
66093047

>>66093033

>> No.66093191

>>66092980
numbers = range(1,16)
for number in numbers:
if number % 3 == 0:
print("fizz")
elif number % 5 == 0:
print("buzz")
elif number % 3 == 0 and number % 5 == 0:
print("fizzbuz")
else:
print(number)

>> No.66093233

>>66092980
>in your favorite language.
I like greek.
ΦιζζΜπαζζ

>> No.66093958

rules={'3':'fizz','5':'buzz'}

def main():
for n in range(100):
i=n
for key in rules:
if (n % int(key) == 0):
try:
i+=rules[key]
except TypeError:
i=rules[key]
print(i)

if __name__ == '__main__':
main()

>> No.66094005
File: 6 KB, 250x164, 1488077765498s.jpg [View same] [iqdb] [saucenao] [google] [report]
66094005

>>66092980

>> No.66094228
File: 606 KB, 1024x768, Tulips.jpg [View same] [iqdb] [saucenao] [google] [report]
66094228

>>66093958

is that python?

holy shit that looks disgusting

>> No.66094269

>>66094228
>Disgusting
Explain

>> No.66094309

>>66094269

I am disgusted when I look at it, anon.

>> No.66094334

>>66094309
Ok, retard.

>> No.66094393

HTML is my language
<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><style>p{counter-increment:f}p:not(:nth-of-type(5n)):before{content:counter(f)}p:nth-of-type(3n):before{content:"Fizz"}p:nth-of-type(5n):after{content:"Buzz"

>> No.66094415

>>66094393
What the fuck

>> No.66094446

>>66094005
She has since had breast reduction surgery

>> No.66094461

>>66094393
Nice

>> No.66094515

>>66094393
But that's CSS.

>> No.66094524

>>66094446
D: why

>> No.66094549

numbers = range(1,16)
for number in numbers:
if number % 3 == 0:
print("fizz")
elif number % 5 == 0:
print("buzz")
elif number % 3 == 0 and number % 5 == 0:
print("fizzbuz")
else:
print(number)

I made another one
rules={'3':'fizz','5':'buzz'}

def main():
for n in range(100):
i=n
for key in rules:
if (n % int(key) == 0):
try:
i+=rules[key]
except TypeError:
i=rules[key]
print(i)

if __name__ == '__main__':
main()


here's a third one I quickly made
<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><style>p{counter-increment:f}p:not(:nth-of-type(5n)):before{content:counter(f)}p:nth-of-type(3n):before{content:"Fizz"}p:nth-of-type(5n):after{content:"Buzz"

>> No.66094561

>>66094393
kek

>> No.66094593
File: 1.10 MB, 250x250, tumblr_static_dzjflr3e65cg4cgw8oog400os.gif [View same] [iqdb] [saucenao] [google] [report]
66094593

>>66092980
Saitan no FizzBuzz

>> No.66094597 [DELETED] 

Javascript is superior
function fizzbuzz(number) {
return !!(number % 3) ? (!!(number % 5) ? number : 'buzz') : (!!(number % 5) ? 'fizz' : 'fizzbuzz')
}
fizzbuzz(15); // "fizzbuzz"

>> No.66094611

What do I win? Oh,code first:

for i in {1..100};{((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};}

>> No.66094632

die+map{(Fizz)[$_%3].(Buzz)[$_%5]||$_}1..100

Courtesy of perlmonks.org/?node_id=602901

>> No.66094644

>>66094632
>die

>> No.66094688

>>66094269

probably the indentation stack you got going on

>> No.66094716

int main()
{
char buf[100];
for (int i = 1; i <= 101; i++) {
printf("%s%s%s\n", (i % 3 != 0 && i % 5 != 0) ? (sprintf(buf, "%d", i), buf) : "", (i % 3 == 0) ? "Fizz" : "", (i % 5 == 0) ? "Buzz" : "");
}
return 0;
}

>> No.66094728

>>66094688
It won't execute properly without that

>> No.66094731

>>66092980
function fuzzbizz ( bool fizz ) {
if( fizz ) { return buzz; }
else { return fizz; }
}

>> No.66094741

>>66094549
(You)

>> No.66094759

>>66094741
thanks

>> No.66094777

(defun fb (fn i)
(dotimes (x i)
(cond ((and (mod x 3) (mod x 5)) (funcall fn "fizzbuzz")
(mod x 3) (funcall fn "fizz")
(mod x 5) (funcall fn "buzz")
t (funcall fn x)))))

(fb #'(lambda(str) (format t "~A~%" str)) 100)

>> No.66094794

for(var i = 1; i <= 100; i++) console.log(!(i % 3) ? (!(i % 5) ? 'fizzbuzz' : 'fizz') : (!(i % 5) ? 'buzz' : i))

>> No.66094803

i=0;exec"print i%3/2*'Fizz'+i%5/4*'Buzz'or-~i;i+=1;"*100

>> No.66094805

>>66094759
Anytime :3

>> No.66094935

const wtf = () => new Array(100).fill().forEach((_, i) => console.log(fb(i+1)))

const fb = num => {
if (!((num % 5) + (num % 3))) return 'fizzbuzz'
if (!(num % 5)) return 'buzz'
if (!(num % 3)) return 'fizz'
return num
}

wtf()

>> No.66095013

>>66092980
>golf
>actually tennis
I'll try C#:
string f(n){string r="";if(n%3==0)r+="fizz";if(n%5==0)r+="buzz";return r;}
for(int i=1;i<101;i++){string g=f(i)==""?i.ToString():f(i);Console.WriteLine(g)}

>> No.66095052

>>66094935

more javascript is shit edition

const wtf = () => new Array(100).fill().forEach((_, i) => console.log(fb(i+1)))

const fb = num => `${!(num % 3) ? `fizz` : ``}${!(num % 5) ? `buzz` : ``}` || num

wtf()

>> No.66095214
File: 22 KB, 459x1337, Selection_304.png [View same] [iqdb] [saucenao] [google] [report]
66095214

>> No.66095407

for(i=0;i++<100;)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)


Shortest fizzBuzz I could write in JS

>> No.66095413

new Array(100).fill().map((_,i)=>[i].reduce((a,j)=>(((j+a)%3?'':'Fizz')+((j+a)%5?'':'Buzz')||j+a),1)).forEach(i=>console.log(i))

>> No.66095427

>>66095407
6 shorter

for(i=0;i++<100;)alert((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)

>> No.66095506

>>66094549
You is stoled my code u_u

>> No.66095637

>favorite language
Well then
泡腾嗡嗡

>> No.66095657

3:fizz
5:buzz
1,100

>> No.66095679

>>66092980
old simona best simona

>> No.66095715

rip
she spat in the face of god

>> No.66096180
File: 272 KB, 1138x1600, 1527361574250.jpg [View same] [iqdb] [saucenao] [google] [report]
66096180

>>66094005

>> No.66096194

>>66092980
FizzBuzz

>> No.66096921

>>66093233
>>66095637
>>66096194
>>66093233
russian is pretty nice too
физбyз

>> No.66097425

>>66092980
def fizzbuzz(n):
r = [(3, 'fizz'), (5, 'buzz')]
print("\n".join(["".join([s for i, s in r if not c % i]) or str(c) for c in range(1,n + 1)]))

>> No.66097937

>>66095214
what font?

>> No.66097940

>powershell

1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]}

>> No.66097946

>>66097937
tewi

>> No.66097989

>>66094524
Boobs were too large and were preventing her from playing high-level tennis.

She did get to rank 1 after that.

>> No.66098013

>>66093191
>can't even program a working fizzbuzz in python
Pretty sad desu.

>> No.66098343

def fizzbuzz(n):
for i in range(1, n+1): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)

>> No.66098426

>/golf/
>picture is tennis
you had on fucking job

>> No.66098512
File: 45 KB, 1229x1038, gscreenshot_2018-05-26-183524.png [View same] [iqdb] [saucenao] [google] [report]
66098512

{-# LANGUAGE UndecidableInstances, TypeOperators, TypeFamilies, DataKinds, FlexibleInstances #-}
import GHC.TypeLits

data Fizz ; data Buzz ; data FizzBuzz ; data Number (i :: Nat)

class FzC (i :: Nat) where type FzPred i :: Nat ; type Fz i
instance FzC 0 where type FzPred 0 = 2 ; type Fz 0 = Fizz
instance FzC 1 where type FzPred 1 = 0 ; type Fz 1 = ()
instance FzC 2 where type FzPred 2 = 1 ; type Fz 2 = ()

class BzC (i :: Nat) where type BzPred i :: Nat ; type Bz i
instance BzC 0 where type BzPred 0 = 4 ; type Bz 0 = Buzz
instance BzC 1 where type BzPred 1 = 0 ; type Bz 1 = ()
instance BzC 2 where type BzPred 2 = 1 ; type Bz 2 = ()
instance BzC 3 where type BzPred 3 = 2 ; type Bz 3 = ()
instance BzC 4 where type BzPred 4 = 3 ; type Bz 4 = ()

type family FzBz1 (i :: Nat) f b where
FzBz1 i () () = Number i
FzBz1 i Fizz Buzz = FizzBuzz
FzBz1 i a () = a
FzBz1 i () b = b

type family FzBz (i :: Nat) (f :: Nat) (b :: Nat) where
FzBz 0 f b = ()
FzBz n f b = (FzBz (n - 1) (FzPred f) (BzPred b), FzBz1 n (Fz f) (Bz b))

type Main = FzBz 100 1 0
m :: Main
m = ""

>> No.66100416

>>66094269
2 WORDS
THE FORCED INDENTATION OF CODE!

>> No.66100705

Fizzbuzz has goten boring. Let's try a different approach:
var nums = [];
for(let i = 1; i <= 100; i++) { nums[i] = i;}
for(let i = 3; i <= 100; i=i+3) { nums[i] = 'fizz';}
for(let i = 5; i <= 100; i=i+5) { nums[i] = 'buzz';}
for(let i = 15; i <= 100; i=i+15) { nums[i] = 'fizzbuzz';}
nums.slice(1).forEach(v => console.log(v));

It's still O(n).

>> No.66100709

>>66092980
sugi pula IF

>> No.66100999

>>66094393
Never thought of using CSS. Clever.

>> No.66101198

for( int x = 3, x<100, x=x+1) {
if x % 3 == 0 printf("Fizz");
if x % 5 == 0 printf("Buzz\n");
else printf("\n");
else printf("%s\n", x);
}

>> No.66101226

>>66094393
oh wow

>> No.66101520

>>66092980
#include <stdio.h>

int main(void) {
for(int i=1; i<=100; i++) printf("%d\r%s%s\n", i, "Fizz"+4*!!(i%3), "Buzz"+4*!!(i%5));
}

>> No.66101545
File: 30 KB, 165x256, jojo.png [View same] [iqdb] [saucenao] [google] [report]
66101545

(defun divisible? (dividend divisor)
(= (mod dividend divisor) 0))

;; `(string+ var s)` is equivalent to `var += s` in other languages
(defmacro string+ (varname toconcat)
`(setf ,varname (concatenate 'string ,varname ,toconcat)))

(defmacro fizzbuzz (max &body cases)
`(loop for i from 1 to ,max do
(let ((output ""))
,@(loop for case in cases collecting
`(if (divisible? i ,(first case))
(string+ output ,(second case))))
(if (string-equal output "") (setf output i))
(format t "~A~%" output))))

(fizzbuzz 100
(3 "Fizz")
(5 "Buzz")
;; add whatever the hell else you want mate
(7 "Fluzz"))


Not the shortest, but it's my favorite. One of the first code snippets I wrote while learning Common Lisp

>> No.66101651






















































































>> No.66101698

>>66101651
I was expecting "The Heart". 0/10

>> No.66102633

PROGRAMF
INTEGERn
DOn=1,100
IF(MOD(n,15).EQ.0)THEN
PRINT*,'FIZZBUZZ'
ELSEIF(MOD(n,5).EQ.0)THEN
PRINT*,'BUZZ'
ELSEIF(MOD(n,3).EQ.0)THEN
PRINT*,'FIZZ'
ELSE
PRINT*,n
ENDIF
ENDDO
END

>> No.66102681

>>66092980
import.fizzbuzz
print(fizzbuzz)

>> No.66102937

>>66092980
in C:
#include <stdio.h>
int main() {
for (int i=0;++i<101;puts("")) {
char f[] = "FizzBuzz%d";
f[8-i%5&12]=0;
printf (f+(-i%3&4+f[8]/8), i);
}
}

>> No.66102988

>>66092980
for(let i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)

>> No.66102996
File: 36 KB, 693x480, DVDadDCV4AAV7Nt.jpg [View same] [iqdb] [saucenao] [google] [report]
66102996

>>66092980
mommy

>> No.66103017

>all these unwashed plebians
Learn APL
{∊(3↑(0=3 5|⍵)∪1)/'Fizz' 'Buzz'⍵}¨⍳20

>> No.66103078

>>66101520
Very clever but what does the !! syntax do? Double negation?

>> No.66103083

>>66103017
learn ATS

>> No.66103096

>>66103078
Casts it into 1 or 0

>> No.66103163

>>66103078
>Very clever but what does the !! syntax do?
How come brainlets on /g/ don't understand how to cast a truthy/falsey value a boolean value?

!!(falseyValue) == !(true) == false
!!(truthyValue) == !(false) == true

>> No.66103524

>>66100705
>his language does not support slice assignment
nums = list(range(1,101))
nums[2::3] = ['fizz'] * int(100 / 3)
nums[4::5] = ['buzz'] * int(100 / 5)
nums[14::15] = ['fizzbuzz'] * int(100 / 15)
print("\n".join([str(c) for c in nums]))

>> No.66103578

<script src="FizzBuzz.js"></script>

>> No.66103598

>>66102937
Please explain

>> No.66103656

>>66102937
>>66103598
Figured it out, but how on earth do you come up with this?

>> No.66103912

>>66103598
>>66103656
I didn't come up with it. I found it in another thread.
I guess the idea was to start with "FizzBuzz%d".
Then you write a null byte to the right position to terminate the string after Fizz, FizzBuzz, or the number.
When printing the pointer is set to the right start index, that is, from Fizz, Buzz, or the number.
Setting it up in such a way that the null byte is written to the correct position and that printing starts at the right index needs some clever hacking.
Not sure how people come up with that.

>> No.66104364

>>66093191
lol you suck

>> No.66104886

void fizz_buzz_3(size_t out_len)
{
for(size_t i=1; i<out_len+1; i++){
bool nd3{i%3}, nd5{i%5};
std::cout << (!nd3 ? "Fizz" : "") << (!nd5 ? "Buzz" : "") << (nd3&&nd5 ? std::to_string(i) : "") << "\n";
}
}

>> No.66104996

>>66104886
I've never seen anyone initialize booleans using the {} syntax.

>>
Name (leave empty)
Comment (leave empty)
Name
E-mail
Subject
Comment
Password [?]Password used for file deletion.
Captcha
Action