Last active
August 29, 2015 13:56
-
-
Save pex/8963416 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a program that prints the numbers from 1 to 100. | |
But for multiples of three print “Fizz” instead of | |
the number and for the multiples of five print “Buzz”. | |
For numbers which are multiples of both three and five print “FizzBuzz”. |
Author
pex
commented
Feb 12, 2014
#include <stdio.h>
int main() {
int i;
for(i=1; i <= 100; i++)
if(i % 3 == 0)
if(i % 5 == 0)
printf("FizzBuzz\n");
else
printf("Fizz\n");
else
if(i % 5 == 0)
printf("Buzz\n");
else
printf("%d\n",i);
return 0;
}
<?php
for ($i = 1; $i <= 100; $i++)
{
if (!($i % 15))
echo "FizzBuzz";
else if (!($i % 3))
echo "Fizz";
else if (!($i % 5))
echo "Buzz";
else
echo "$i";
}
?>
var fuzzbuzz = function(number) {
var arr = [];
for(var i = 1; i <= number; i++) {
var res = i;
if(i % 3 === 0) res = "Fizz";
if(i % 5 === 0) (typeof res === "number") ? res = "Buzz" : res += "Buzz";
arr.push(res);
}
return arr;
};
console.log(fuzzbuzz(100));
#!/usr/bin/env python
for i in xrange(1, 101):
if i % 15 == 0:
print "FizzBuzz"
elif i % 3 == 0:
print "Fizz"
elif i % 5 == 0:
print "Buzz"
else:
print i
for num in [1..100]
r = ''
r += 'Fizz' if num % 3 == 0
r += 'Buzz' if num % 5 == 0
console.log r || num
print(($_%15?$_%3?$_%5?$_:"buzz":"fizz":"fizzbuzz").$/)for 1..100
<?php
for($i=1;$i<=100 and print(($i%15?$i%5?$i%3?$i:'Fizz':'Buzz':'FizzBuzz')."\n"); $i++);
?>
#!/usr/bin/env ruby -w
(1..100).map{|n|Hash['FizzBuzz',n%15,'Fizz',n%5,'Buzz',n%3,n,0].map{|s,m|m==0?puts(s):next}}
print'Fizz'x!($_%3).'Buzz'x!($_%5)||$_,"\n"for 1..100
BITS 32
global _start
section .data
const10: dd 10
const5: dd 5
const3: dd 3
fizz: db "fizz",0x00
buzz: db "buzz",0x00
section .text
_start:
mov edi, 0
main:
inc edi
mov ebp, 0
main1:
mov eax, edi
xor edx, edx
div dword [const3]
cmp dl, 0
je printfizz
main2:
mov eax, edi
xor edx, edx
div dword [const5]
cmp dl, 0
je printbuzz
main3:
cmp ebp, 1
je loop
mov eax, edi
call printNumber
jmp loop
printfizz:
mov eax, fizz
call printString
mov ebp, 1
jmp main2
printbuzz:
mov eax, buzz
call printString
jmp loop
loop:
mov eax, 0x0a
call printCharacter
cmp edi, 100
jl main
exit:
mov eax, 1 ; SYS_EXIT
xor ebx, ebx
int 0x80
printString:
mov esi, eax
xor eax, eax
mov al, byte [esi]
call printCharacter
mov eax, esi
inc eax
cmp byte [eax], 0
jne printString
ret
printCharacter:
push eax
mov ecx, esp
pop eax
mov eax, 4
mov ebx, 1
mov edx, 1
int 0x80
ret
printNumber:
push eax
push edx
xor edx,edx ;edx:eax = number
div dword [const10] ;eax = quotient, edx = remainder
test eax,eax ;Is quotient zero?
je .l1 ; yes, don't display it
call printNumber ;Display the quotient
.l1:
lea eax,[edx+'0']
call printCharacter ;Display the remainder
pop edx
pop eax
ret
nasm -f elf fizzbuzz.asm
ld -o fizzbuzz fizzbuzz.o -m elf_i386
print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100
-- not mine
:((((((
for(i=0,t=['','Fizz','','Buzz'];i++<100;)console.log((t[0+!(i%3)]+t[2+!(i%5)])||i)
was ist das für chosen few Logo? geht mal weg. FCSP <3
ASM 4 ARM
.global main
.equ Five,5
.equ Three,3
.equ Fivt,15
.equ lStart,1
.equ lEnd,100
.equ Step,1
.equ Rest,0
.set i, r0
.section .data
Fizz:
.asciz "Fizz\n"
.align
Buzz:
.asciz "Buzz\n"
.align
FizzBuzz:
.asciz "FizzBuzz\n"
.align
.section .text
main:
mov r0,#lStart
while_01: @up to 100 baby
cmp r0,#lEnd
beq while_end_01
do_01:
add r0,#Step
mov r1, r0 MOD #Fivt
cmp r1, #Rest
beq print_FizzBuzz
mov r1,r0 MOD #Three
cmp r1, #Rest
beq print_Fizz
mov r1,r0 MOD #Five
cmp r1,#Rest
beq Buzz
print_Fizz:
.print Fizz
b while_01
print_Buzz:
.print Buzz
b while_01
print_FizzBuzz:
.print FizzBuzz
b while_01
print_Number:
b while_01
while_end_01:
.end
Io-Lang
swag := Object clone
swag yolonese := ""
fizzBuzz4MaNiggaz := method(yolo,swag yolonese := "" ;
if(yolo % 3 == 0, swag yolonese = swag yolonese .. "Fizz")
if(yolo % 5 == 0, swag yolonese = swag yolonese .. "Buzz")
if(swag yolonese == "" , swag yolonese := yolo)
swag yolonese println
)
for(yolo,1,100,fizzBuzz4MaNiggaz(yolo))
swag und yolonese?
+1 für ARM-ASM
ich finde swag und yolo/nese sind sehr gute Variablennamen. Weg mit i und j gib uns yolo und swag!!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment