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".
What do you mean, 90%? You need ten people for that. All I count are you, me, the sussman, and that faggot spamming ``hax my anus''.
1.upto(100) do |n|
tuna = n % 3 == 0
fish = n % 5 == 0
if tuna and fish
puts "FizzBuzz"
elsif tuna
puts "Fizz"
elsif fish
puts "Buzz"
else
puts n
end
end
Name:
Anonymous2008-04-25 12:53
import fizzbuzz
fizzbuzz f = new fizzbuzz(1,100)
print f.tostring()
Name:
Anonymous2008-04-25 13:00
mapM_ fizz [0..100]
where
fizz n | (mod n 3 == 0) && (mod n 5 ==0) = putStrLn (show n ++ " fizzbuzz")
| (mod n 3 == 0) = putStrLn (show n ++ " fizz")
| (mod n 5 == 0) = putStrLn (show n ++ " buzz")
| otherwise = putStrLn (show n)
I could've optimised it to three cases, but I am in hurry (by the way, fuck you OP, I will be late for a meeting because I had to prove you I can do it.).
Try changing the specifications to leverage the existing software assets.
Name:
The Ginger2008-04-25 14:08
i % (3*5) == 0 considered better than (i % 3 == 0) && (i % 5 == 0)
Name:
Anonymous2008-04-25 14:09
you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus'' you, me, the sussman, and that faggot spamming ``hax my anus''
>>19
I am from Uganda and I can assure you that I didn't.
Name:
Anonymous2008-04-25 14:24
fizzBuzz = mapM_ (putStrLn . check) [1..100] where
check n | n `mod` (3*5) == 0 = "FizzBuzz"
| n `mod` 3 == 0 = "Fizz"
| n `mod` 5 == 0 = "Buzz"
| otherwise = show n
Name:
Anonymous2008-04-25 14:30
>>20
Is your father the treasurer for the King? Do you need some cheques cashing?
Name:
Anonymous2008-04-25 14:35
>>11
NOT GOOD ENOUGH!
1. Make a loop from 1 to 100, and do all 100 checks in it ((i==1) and (ifcheck_div(1, 3, "Fizz") or check_div(1, 5, "Buzz")), or whatever that would be in your FIOC language)
2. MORE INDENTATION! if(i==1){
...
} else if(i==2){
...
} else if(i==3){
...
—bad idea!!! This is how you do it: if(i==1){
...
} else{
if(i==2){
...
} else{
if(i==3){
...
} else{
...
}
}
}
You have ways to go!
Oh, and your language sucks!!
Name:
Anonymous2008-04-25 14:53
>>23
There's a post length limit, you know. I had to make it shorter.
Name:
Anonymous2008-04-25 14:57
Apparently, my contributions to fourms was too large. This is an outrage. I'm never going to post code in comment again. Not only that—when I tried to post that to pastebin site, I got an error! "Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2759 bytes) in /home/pastebin/lib/geshi/geshi.php on line 1979". Does the world not want to see my creation?
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.mysticcoders.pastebin.model.PasteEntry#16103]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:375)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:72)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
at com.mysticcoders.pastebin.model.PasteEntry$$EnhancerByCGLIB$$c09a677.getName(<generated>)
at com.mysticcoders.pastebin.web.resource.ExportResource.setHeaders(ExportResource.java:27)
at org.apache.wicket.markup.html.WebResource.configureResponse(WebResource.java:52)
at org.apache.wicket.Resource.onResourceRequested(Resource.java:119)
at org.apache.wicket.request.target.resource.SharedResourceRequestTarget.respond(SharedResourceRequestTarget.java:190)
at org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:103)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1100)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1169)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1245)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:489)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:354)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:173)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.ajp.Ajp13Connection.access$2700(Ajp13Connection.java:42)
at org.mortbay.jetty.ajp.Ajp13Connection$RequestHandler.headerComplete(Ajp13Connection.java:221)
at org.mortbay.jetty.ajp.Ajp13Parser.parseNext(Ajp13Parser.java:488)
at org.mortbay.jetty.ajp.Ajp13Parser.parseAvailable(Ajp13Parser.java:142)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
foreach(range(1,100) as $i) echo (($f=$i%3===0)?"Fizz":"").(($b=$i%5==0)?"Buzz":"").(($f|$b)==0?$i:"") . "\n";
Name:
Anonymous2008-04-25 16:21
1 to(100) each("x") {
case
{ x %(3) ==(0); } { writeLine("Fizz"); }
{ x %(5) ==(0); } { writeLine("Buzz"); }
{ x %(3 *(5)) ==(0); } { writeLine("FizzBuzz"); }
unless { writeLine(x); };
};
Here is my contribution, written in my own programming language, a derivative of Io (and indirectly, Smalltalk) that stole Ruby's syntax for blocks and also forgoes Io's syntactic sugar for infix expressions.
* Number#to constructs a range object.
* Range#each iterates over the range and accepts a single argument, the name to which the number in the range will be bound in the corresponding block.
* Object#case accepts mutually exclusive (predicate, action) block pairs and returns whether any of the predicates succeeded (making Bool#unless act as a sort of else clause).
Semicolon statement delimiters are needed (unfortunately) so that message send chains may be broken into several lines.
The interpreter, of course, is written in HASKELL.
Name:
Anonymous2008-04-25 16:27
>>32
ONE WORD: FORCED SEMI-COLONS IN THE CODE. THREAD OVER.
Name:
Anonymous2008-04-25 17:33
Some awesome trolling in this thread, from start to finish.
Here is my contribution, written in my own programming language, a derivative of Scheme (and indirectly, Lisp) that stole Ruby's syntax for symbols and also forgoes Scheme's tail recursion for loops.
* (iterate variable (from to) conditions) loops between 'from' and 'to' inclusive, and tests the conditions for each number.
* (number expression) prints the expression if the iteration variable is divisible by the number.
* (else expression) prints the expression if no previous number matched (making (iterate) act as a sort of switch statement).
Parentheses are needed (unfortunately) so that simultaneous iterators may retain their own lexical scope.
The interpreter, of course, is written in CROMA.
Name:
Anonymous2008-04-25 18:05
My attempt
Fizzbuz X where X is an integer
Int y = 0;
for (y = 0; y<300; Y+3)
if (x = y) then print Fizz
for (y = 0; y<30000; y+5}
if (y == x) then print buzz
esle print X
next line
#!/usr/local/bin/ploki
LET i += 1
IF i > 100
END
END IF
WUNT \AUSG @FIZZBUZZi
IF
FOR FIZZBUZZ LEET r
IF \@ % 3 = 0
LET r "Fizz"
FI
IF \@ % 5 = 0
LET r _= "Buzz"
FI
IF @NOT r
LET r \@
FI
KTHX r
Name:
Anonymous2008-04-25 18:36
UM LOL C
void fizzbuzz()
{
for(int x=1;x<=100;x++)
{
if(x%3==0) {printf("FIZZ\n");}
else if(x%5==0) {printf("BUZZ\n");}
else if(x%15=0) {printf("FIZZBUZZ\n");}
else {printf("%i",x);}
}
}
too lazy to format. simple shit yo
Sage for FizzBuzz. Sure, I've met "Programmers" who couldn't code it, but their numbers are few.
The problem's real nature lies in making people who read it think "Hey, I could solve that!" and feel good about themselves. They then feel somehow compelled to post their own solution, to show that "Hello, I'm anonymous, and I am superior because I can solve a problem any eight-year old who've ever sat down at a BASIC prompt can handle."
Clever obfuscations or circumlocutions are still encouraged.
(mod x1 x2) is R6RS and (modulo x2 x2) is R5RS what the fuck.
those using non r6rs compilers (define mod modulo) i guess
Name:
Anonymous2008-04-25 23:50
>>63
DIEROM SEI
LDA #0
STA 0
HALT JMP HALT
.ASC "OMG WHERE IS YOUR KERNAL RESET ROUTINE NOW?"
Name:
Anonymous2008-04-26 0:47
(defun fizzbuzz ()
(format t "~{~a ~}"
(loop for i from 1 upto 100
when (= (mod i 15) 0) collect "FizzBuzz"
when (= (mod i 3) 0) collect "Fizz"
when (= (mod i 5) 0) collect "Buzz"
else collect i)))
Or in my custom Lisp where fizzbuzz is a builtin:
(fizzbuzz)
Name:
Anonymous2008-04-26 1:43
The fun thing about FizzBuzz (other than writing obfuscated versions) is to write versions that seem correct but aren't, present them to others and see if they spot the mistake.
#include <stdio.h>
int main() {
int i, f, b;
for(i=1;i<=100;i++) {
if((f = !(i%3)) || (b = !(i%5)))
printf("%s%s", f ? "Fizz" : "", b ? "Buzz" : "");
else
printf("%d", i);
printf("\n");
}
return 0;
}
MD5 (solution) = 78a1dc71c6d126a040c7da4f006f717c
Name:
Anonymous2008-04-26 2:20
>>67
Apart from newlines, I don't see anything wrong with it
>>71
I'm going to take a stab at it:
in if((f = !(i%3)) || (b = !(i%5)))
when the condition is evaluated, if the first one is true then the condition is true so the second isn't evaluated. So b doesn't change from its state from iteration 5.
if you write instead:
#include <stdio.h>
int main() {
int i, f, b;
for(i=1;i<=100;i++) {
f = !(i%3);
b = !(i%5);
if (f || b) {
printf("%s%s", f ? "Fizz" : "", b ? "Buzz" : "");
} else {
printf("%d", i);
}
printf("\n");
}
return 0;
}
both statements are should be evaluated and it seems to work correctly.
>>17
At first I was like ``hey thanks for the helpful advice'', but then I noticed your name and I burst with laugh. Damn you, Patrick.
Name:
Anonymous2008-04-26 5:27
>>67 The fun thing about FizzBuzz (other than writing obfuscated versions) is to write versions that seem correct but aren't, present them to others and see if they spot the mistake.
(define l '((3 . "fizz") (5 . "buzz")))
(define (f l method f2 n m)
(if (<= n m)
(begin
(check l method f2 n #f)
(f l method f2 (+ n 1) m))))
(define (check l method f n x)
(if (not (null? l))
(if (method n (caar l))
(begin
(f (cdar l))
(check (cdr l) method f n #t))
(check (cdr l) method f n #f))
(if (not x) (f n))))
(define (fizzbuzz n)
(f l (lambda (a b) (= (remainder a b) 0)) (lambda (x) (display x)) 1 n))
Name:
Anonymous2008-04-26 7:49
int n = 1;
while( n <= 100 )
{
if( !( n % 3 ) && !( n % 5 ) )
printf( "FizzBuzz" );
else
if( !( n % 3 ) )
printf( "Fizz" );
else
if( !( n % 5 ) )
printf( "Buzz" );
else
printf( "%d", n );
n++;
}
Name:
Anonymous2008-04-26 8:04
// FizzBuzz v2.0
short n = 1;
while( n <= 100 )
{
short n0 = n;
if( !( n % 3 ) )
{
n0 = 0;
printf( "Fizz" );
}
if( !( n % 5 ) )
{
n0 = 0;
printf( "Buzz" );
}
if( n0 )
printf( "%d", n );
n++;
}
int main ()
{
bool mod = 1;
for ( int i = 1; i < 101; i++)
{
if ( i % 3 == 0)
{
cout << "Fizz";
mod = 0;
}
if ( i % 5 == 0)
{
cout << "Buzz";
mod = 0;
}
if (mod)
cout << i;
mod = 1;
cout << endl;
}
return 0;
}
For numbers which are multiples of both three and five print "FizzBuzz".
Name:
Anonymous2008-04-26 20:28
>>104
Well yeah... it's an If If, not an If Else If. Both If's will be determined for each number and for those numbers where both are true both Fizz and Buzz will be printed
Name:
Anonymous2008-04-26 20:46
>>105
I did not understand what you meant, but you have made me realise that the blocks in >>103 are quite weird.
So I started thinking, what about controlling the output cache? If there's something, print \n, if not, print i. I wouldn't consider implementing that in java, though.
Name:
Anonymous2008-04-26 20:53
anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus anus
Name:
Anonymous2008-04-26 21:05
So for 15, should it print Fizz, Buzz and FizzBuzz or just FizzBuzz?
hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus hax my anus
print '\n'.join([str(((not x%3) and x%5 and 'fizz') or ((not x%5) and x%3 and 'buzz') or ( ((not x%5) and (not x%3)) and 'fizzbuzz') or x) for x in range(1, 101)])
>>118
It's not so much an encouraged Python practice as something people carry over from Perl.
>>121
Not really. Everything in the thread is either trivial or lifted from somewhere else.
Name:
Anonymous2008-04-27 23:28
>>124
I didn't say it is instructive, I said it is enjoyable. Also, what do you care if posts were lifted from somewhere else? Everyone is anonymous anyway, it doesn't matter.
<@MrVacBob> i should add reporting i guess
<@MrVacBob> dis moderators are.... some people, i guess, but i'm the only one who would read prog and i don't understand it at all
interface IFizzBuzz
{
public function setFizzBuzz($fizz = null, $buzz = null);
public function checkFizz($int);
public function checkBuzz($int);
public function generateFizzBuzz();
}
class FizzBuzz implements IFizzBuzz
{
/**
* Fizz
*
* @var string
*/
public $fizzText = 'Fizz';
/**
* Buzz
*
* @var string
*/
public $buzzText = 'Buzz';
/**
* Lower interger range.
*
* @var int
*/
public $lowerInt = 1;
/**
* Upper interger range.
*
* @var int
*/
public $upperInt = 100;
return ($int % 3 == 0) ? true : false;
i would like you to write a formal explanation of the ternary operator and tell me why that statement is so redundant
Name:
Anonymous2008-04-28 6:21
>>128
too lazy, otherwise i would have added more garbage to my code
i'm not really sure why i added the ternary operator in there
but you can keep it as a momento of my shitty code
>>145 Click photo to enlarge http://www.fluffycat.com/photograph--1/ Fatal error: Call to undefined function: numberofphotosfortopicname() in /home/fluff4/public_html/core/photo_functions.php on line 176
I lold.
Name:
Anonymous2008-04-29 13:47
// C
include <stdio.h>
int main() {
printf("lol");
return 69;
}
Name:
Anonymous2008-04-29 14:04
return 69;
wuts it do?
Name:
Anonymous2008-04-29 16:49
import Control.Monad.Instances
import Function
import Monad
>>153 Functional programming considered harmful Guido Van rossum
Name:
Anonymous2008-04-29 21:24
Bow down before the ENTERPRISE package fizzbuzz;
public interface IFizzBuzz {
public void setStart();
public void setEnd();
public String getFizzBuzz();
}
=================================================
package fizzbuzz;
/**
* Singleton adapter factory
*/
public class FizzBuzzFactory {
public static final FizzBuzzFactory INSTANCE = new FizzBuzzFactory();
private FizzBuzzFactory() {
registerAdapters();
}
public <T> createInstance(Class<T> clazz) {
if (clazz == IFizzBuzz.class) {
return new FizzBuzzImpl();
} else return null;
}
public String getFizzBuzz() {
String result = "";
for (int i = fStart; i <= fEnd; i++) {
if (getFizz(i) && getBuzz(i))
result += "FizzBuzz";
else if (getFizz(i))
result += "Fizz";
else if (getBuzz(i))
result += "Buzz";
else result += i;
}
return result;
}
}
=================================================
import junit.framework.*;
public class TestFizzBuzz extends TestCase {
public void setUp() {
}
public void tearDown() {
}
public void testGetFizzBuzz() {
IFizzBuzz f = FizzBuzzFactory.INSTANCE.createInstance(IFizzBuzz.class);
f.setStart(1);
f.setEnd(100);
AssertEquals(f.getFizzBuzz(),
int main() {
static int i = 1;
if (!(i%3)) printf("Fizz");
if (!(i%5)) printf("Buzz");
if (i%3 || i%5) printf("%d",i);
putchar('\n');
i++;
if (i<=100) main();
return(0);
}
Name:
Anonymous2008-05-01 3:05
>>165
* changed || to && (was causing erroneous behavior)
* removed redundant value checks
* removed the static variable (poor form)
* added declarations for printf and putchar
* tail-call optimized
#include <stdio.h>
int main(int i, char **argv) {
return argv ? main(1,NULL) : i > 100 ? 0 : ((
(i%3 || (printf("Fizz"), 0))
&& (i%5 || (printf("Buzz"), 0))
) && printf("%d",i), putchar('\n'), main(i + 1, NULL));
}
Name:
Anonymous2008-05-01 3:10
>>166 : ((
it looks like shit now. I hope you feel kind of bad about it。。。
Name:
Anonymous2008-05-01 3:20
>>167
You mean it looks like Lisp now, or about as close as you'll get in C.
Here's a version with a bunch of extra return statements, maybe it's more to your liking.
#include <stdio.h>
int main(int i, char **argv) {
if (argv)
return main(1, NULL);
if (i > 100)
return 0;
(
(i%3 || (printf("Fizz"), 0))
&& (i%5 || (printf("Buzz"), 0))
) && printf("%d",i);
putchar('\n');
return main(i + 1, NULL);
}
>>166
That was so beautiful I had to post a version that actually works (I apologize if it was meant to be wrong).
#include <stdio.h>
int main(int i) {
return i > 100 ? 0 : ((
(!(i%3) && printf("Fizz"))
+ (!(i%5) && printf("Buzz"))
) || printf("%d",i), putchar('n'), main(i + 1));
}
>>170
Hm? I tested mine before I posted it. Even built with -ansi -pedantic -W -Wall and tried it on Linux/AMD64, FreeBSD/i686, and PPC/OS X. GCC 4.3 prints two warnings, but it produced correct output on all three systems.
Name:
Anonymous2008-05-01 14:25
>>176
Does not print "FizzBuzz" on multiples of 15 because "&&" is shorting. Should have used "*" instead.
>>177
Oh fuck, I pasted the wrong version. That should've been &, as >>178 said. [/dumbass]
Your version doesn't work if you give it command line arguments. (and you have 'n' instead of '\n', but that's more a typo than an implementation error)
Name:
Anonymous2008-05-01 15:08
>>179
I test-posted it on http://snafu.dasourcerer.net/bbcode/ and it ate the backslash. "&" might be dangerous because (1&2) is 0, thus (7%3)&(7%5) is 0 too. It does work on your program, though. I sacrificed correct command line argument handling to achieve increased beauty. It's fucking beautiful, dude. Congratulations.
Name:
Haprog2008-05-01 17:00
I challenge you to write FizzBuzz in Brainfuck
Name:
Anonymous2008-05-01 17:06
print "\n".join(([str((o,o,f,o,b,f,o,o,f,b,o,f,o,o,z)[o%15]) for (f,b,z) in (("Fizz", "Buzz", "FizzBuzz"),)])[0] for o in range(1,100))
Will run on GForth.
: fizzbuzz
101 1 +do
r@ 3 mod 0= dup if ." Fizz" endif
r@ 5 mod 0= dup if ." Buzz" endif or
invert if r@ . endif
cr
loop ;
fizzbuzz bye
Name:
Anonymous2008-05-05 0:51
I created this language called FizzBuzz. It has one keyword, FizzBuzz. It also supports C-style comments and blocks (braces), and statements must be terminated with a semicolon. The FizzBuzz keyword creates the output as described in the OPs post. Here is the program:
# DO_OP_BIDDING.FBZ: Do what OP said - Version 1.0
{ FizzBuzz };
Name:
Anonymous2008-05-05 0:52
>>188
Whoops. Changed my mind. Does not support C-style comments, but rather Unix style comments.
Name:
Anonymous2008-05-05 1:29
>>189
That so ruined everything. You made a dynamic entry and then on the way out you slipped and fell on your ass and everybody lold and then commenced to hax your anus.
>>153
Excuse me fine sir, we can't let you board the LOLplane with that extra piece of whitespace. You'll have to stow it in the whitespacehold with the rest of the whitespace:
Must admit, I am impressed by the Perl and Python one liners. Can't us Haskellers make a short one liner?
Name:
Anonymous2008-05-05 20:16
After closer inspection it seems that they exploit that boolean operators return numbers instead of true or false typed values. Haskell can't do this of course. Otherwise something similar like this might work:
>>196,197
Thy wish be granted.
mapM_ putStrLn$map(\x->["FizzBuzz","Buzz","Fizz",show x]!!(signum(x`mod`3)+signum(x`mod`5)*2))[1..100]
I still like >>37 better, though.
Name:
Anonymous2008-05-05 20:58
These versions will save you 3 more characters.
mapM_(\x->putStrLn(["FizzBuzz","Buzz","Fizz",show x]!!(signum(x`mod`3)+signum(x`mod`5)*2)))[1..100]
This one is actually from http://hpaste.org/93, but seemed worth posting:
mapM_ putStrLn[cycle[show n,"Fizz","Buzz","FizzBuzz"]!!div(gcd n 15)2|n<-[1..100]]
void Main(int argc, char[][] agv) {
int num= 0;
start:
if(num = 100) {
goto end;
}
if (num < 100) {
num= num +1;
}
// print section
if (num % 3 = 0) {
cout<< "fizz";
}
if (num % 5= 0) {
cout<< "buzz;"
}
if (num %3= 0) {
if (num%5 =0) {
cout << "fizzbuzz";
}
}
goto start;
}
Name:
Anonymous2008-05-07 18:52
>>1
heh. ha ha. HA. HA HA HA. AH HAHAHAHAHAHAHA, OH GOD AH HAHAHAHAHAHAHAHA. BUHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHa....
Oh... oh...
That's a good one.
Name:
Anonymous2008-05-07 19:12
#light
let modcheck y =
match y with
| _ when y % 3 + y % 5 = 0 -> printfn "FizzBuzz"
| _ when y % 5 = 0 -> printfn "Buzz"
| _ when y % 3 = 0 -> printfn "Fizz"
| _ -> printfn "%d" y
let fizzbuzz =
let range = seq {1 .. 100}
range |> Seq.iter modcheck
fizzbuzz
(F#)
Name:
Anonymous2008-05-07 19:41
>>216 [/code]
That syntax looks
|_Absolutely
|_Horrid [/code]
let fizzbuzz =
let range = seq {1 .. 100}
let modcheck y =
match y with
| _ when y % 3 + y % 5 = 0 -> printfn "FizzBuzz"
| _ when y % 5 = 0 -> printfn "Buzz"
| _ when y % 3 = 0 -> printfn "Fizz"
| _ -> printfn "%d" y
range |> Seq.iter modcheck
//F# is beautiful so fuck off, every other piece of code in this thread is pretty much the same level of readability or worse.
fizzBuzz = mapM_ putStrLn $ map f [1..100]
where
f n | m3 n && m5 n = "FizzBuzz"
| m3 n = "Fizz"
| m5 n = "Buzz"
| True = show n
m3 n = mod n 3 == 0
m5 n = mod n 5 == 0
>>244
Because I know people are going to be too lazy to find the original ABC thread, here's an interpreter:
/* Copyright (c) 2009Xarn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
Here's one that also prints the newlines, even though they weren't specified in >>1:
#!/usr/bin/python
out = ""
for i in range(1, 101):
if i % 15 == 0:
out += "$n" + "a" * ord('F') + "c" + \
"a" * (ord('i') - ord('F')) + "c" + \
"a" * (ord('z') - ord('i')) + "cc" + \
"b" * (ord('z') - ord('B')) + "c" + \
"a" * (ord('u') - ord('B')) + "c" + \
"a" * (ord('z') - ord('u')) + "cc" + \
"n" + "a" * ord("\n") + "c$"
elif i % 3 == 0:
out += "$n" + "a" * ord('F') + "c" + \
"a" * (ord('i') - ord('F')) + "c" + \
"a" * (ord('z') - ord('i')) + "cc" + \
"n" + "a" * ord("\n") + "c$"
elif i % 5 == 0:
out += "$n" + "a" * ord('B') + "c" + \
"a" * (ord('u') - ord('B')) + "c" + \
"a" * (ord('z') - ord('u')) + "cc" + \
"n" + "a" * ord("\n") + "c$"
else:
out += "n" + "a" * i + "c$"
out += "a" * (ord("\n") - i) if i < ord("\n") else \
"b" * (i - ord("\n")) if (i - ord("\n")) <= 10 else \
"n" + "a" * ord("\n")
out += "c$"
out = "".join(out.split("$$"))[1:-1]
for i in range(0, len(out), 80):
print out[i : i + 80]