Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article)
-
That is not a good test because reply overrides mention.
d by accalia
Edit: Did it work? My money is on "no".
-
well accalia, does it work now?
EDIT: we should totally have a thread where all the discussion is done via edits
-
try again you silly fox....
for(i=0;i>=0;i--) { if(i==0) i=100; cout << i<< endl; if (i == 1) i = -1; }
-
looks like it does suppress notifications
-
-
Confirmed working!
/me hands @accalia the Doing It Wrong Correctly medal(with the minor exception of forgetting
int i
instead ofi
)
-
Ooooh! Wait! I can make mine even more evil:
for(int i = 0; printf("%d\n", 100 - i++) && i < 100;);
Beautiful.
-
(with the minor exception of forgetting int i instead of i)
that's your error, not mine :-D
-
-
doing it wrong?
also there are a couple of esoteric C like languages (where that code segment would be valid) that lack the break statement
-
also there are a couple of esoteric C like languages (where that code segment would be valid) that lack the break statement
Perfect time for a
goto
!<mostly sarcasm!
EDIT: And yes, I'd say it's Doing It Wrong. Setting i to -1 forces the reader to think, "why the heck are they doing that?", then scan up to the
for
statement. Whereasbreak
does what it says. Most of the time.
-
+-∞
-
This is one of my pet peeves. Are we allergic to break?
for(i=0;i>0;i--) { cout << i<< endl; } int i = 100; print: cout << i<< endl; i --; if (i > 0) goto print;
A solution just for @NedFodder that technically solves @cartman's rules too.
Perfect time for a goto!
EDIT: I AM 'd
-
people just start posting code samples. I guess to "prove" they aren't the crappy candidates themselves?
For fun.
-
Discussion about an article mentioning a programming problem turns into a code competition for solving said problem. Who would have thought?
-
As I said, you can be critic and you can whine.
I didn't RTFA, but I think we probably have to take the description of "whining" with a grain of salt.
-
And again, instead of people talking about the really important issue of crappy IT interview candidates polluting job pools everywhere, people just start posting code samples.
You say that as if you're new here…
-
The ability of people to focus on trivial examples and ignore the point always amazes me.
-
It's a pretty banal point at this point. Why rehash that shit over and over and over when we can have fun coming up with WTFs from trivial problems?
-
And again, instead of people talking about the really important issue of crappy IT interview candidates polluting job pools everywhere, people just start posting code samples.
Fine, let's talk about the job pool being polluted by frauds. I don't think the problem is fixable. I'm sure you'll disagree.
all mathematical operations a computer does are addition.
I'm sure there's at least one person here who didn't know that.
-
You mean you'd rather see 100 posts all saying the same thing? Instead of a few posts that exhaust the subject, then people having fun coming up with the most solution to the task?
Also, what @boomzilla said. Which is pretty much the same thing.
-
I'm sure there's at least one person here who didn't know that.
Those people, if they have a degree, should fight to get at least a partial refund.
-
Fine, let's talk about the job pool being polluted by frauds. I don't think the problem is fixable. I'm sure you'll disagree
It is fixable. Clearly the programming languages aren't intuitive enough. It's well known that everyone should be allowed and able to program, regardless of their abilities.
-
You forgot your
-
-
Clearly the programming languages aren't intuitive enough. It's well known that everyone should be allowed and able to program, regardless of their abilities.
Pft. When will we acknowledge that some people's intuitions are simply not meant to deal with perfect logicians cast in silicon?
-
all mathematical operations a computer does are addition.
What about multiplication?
AND Gate
1 * 1 = 1
1 * 0 = 0
0 * 1 = 0
0 * 0 = 0
-
It's a pretty banal point at this point. Why rehash that shit over and over and over when we can have fun coming up with WTFs from trivial problems?
Oh, we're supposed to be coming up with WTFs?
Has anyone done the 1 to 100 thing using string concatenation yet?
-
Oh, we're supposed to be coming up with WTFs?
Eh, you're not really supposed to do anything on here in General. But that's what's mostly been going on and what blakey was BITCHing about.
-
I can't believe this? What is WRONG with you people?
for(int i = 0; i < 1; i++) break; WriteLine("100 to 1");
Or even better:
for(int i = 0; i < 1; i++) goto Print; Print: WriteLine("100 to 1");
Why do I have to be the first to do point this out? WAKE UP, SHEEPLE!
-
-
Fine, here I'll do it in C# where strings are immutable for extra WTFiness.
String output = ""; for (int i = 0; i < 100; i++) { String number = Convert.ToString(i); output = number + "\n" + output; } Console.WriteLine(output);
Note: For extra WTFiness I didn't test it either.
Edit: Whoops, I used Environment.NewLine instead of "\n"... Fixed now.
-
Where's the
for (int i=0;
?
-
for (int i=0; i <= 100, i++) {
int k = 100 - i;
print k;
}Right? I never use
for
anymore, so the special syntax is obscure. Normally, I'd do(sequence_ putStrLn) . reverse $ [1..100]
-
The ability of people to focus on trivial examples and ignore the point always amazes me.
No wonder you have such a high opinion of yourself.
-
In a macro.
-
Failed: Doesn't start with
for (int i=0;
.
-
```
for(i=0;i>0;i--)
{
cout << i << endl;
}
int i = 100;
print: cout << 1 << endl;
i --;
if (i < 0)
goto print;Why not go all the way and just write it in asm?
for( int i = 0; 0; )
;asm(
"movq $100,%%rbx\n"
"movq %0,%%r15\n"
"_label:\n"
"movq %%rbx,%%rsi\n"
"movq %%r15,%%rdi\n"
"xorq %%rax,%%rax\n"
"call printf\n"
"subq $1, %%rbx\n"
"jne _label\n"
: : "g"("%lld\n") : "%rbx", "%rax", "%rsi", "%rdi", "%r15", "cc"
);<small>Filed under: [Blazingly fast⸮](#tag) [My asm is getting rusty](#tag) [@accalia's sample declares i too late](#tag)</small>
-
for (var i = 0; i < 100; i += 1) {
console.log(100-i);
}faster solution, cut iterations by 2
-
This post is deleted!
-
it's not the iterations you're speeding up there.... it's the writing to the console. you halved the number of console writes in the second example. ;-)
-
for (var i = 0; i < 100; i += 1) { console.log(100-i);}
even faster:
var a = []; for (var i = 0; i < 100; i += 1) { a.push(100-i); } console.log(a.join('\n'));
-
…
Also disqualified because the for loop isn't the first thing in the code.
-
What part of 'starts with 'for(int i = 0;' did you not understand, idiot?
(Would probably not say this to any human seriously.)
-
Right, forgot it was starts with and not contains. Whoops.
I'm too lazy to intentionally write that code to be even wtfier.
-
-
Also disqualified because the for loop isn't the first thing in the code.
not the point of that bit of code....
also still disqualified because int is not a valid type in JS
-
I'm a little surprised nobody has posted this sort of thing yet:
for (int i=0; i<1; i++) { System.out.println("100"); System.out.println("99"); System.out.println("98"); System.out.println("97"); System.out.println("96"); System.out.println("95"); System.out.println("94"); System.out.println("93"); System.out.println("92"); System.out.println("91"); System.out.println("90"); System.out.println("89"); System.out.println("88"); System.out.println("87"); System.out.println("86"); System.out.println("85"); System.out.println("84"); System.out.println("83"); System.out.println("82"); System.out.println("81"); System.out.println("80"); System.out.println("79"); System.out.println("78"); System.out.println("77"); System.out.println("76"); System.out.println("75"); System.out.println("74"); System.out.println("73"); System.out.println("72"); System.out.println("71"); System.out.println("70"); System.out.println("69"); System.out.println("68"); System.out.println("67"); System.out.println("66"); System.out.println("65"); System.out.println("64"); System.out.println("63"); System.out.println("62"); System.out.println("61"); System.out.println("60"); System.out.println("59"); System.out.println("58"); System.out.println("57"); System.out.println("56"); System.out.println("55"); System.out.println("54"); System.out.println("53"); System.out.println("52"); System.out.println("51"); System.out.println("50"); System.out.println("49"); System.out.println("48"); System.out.println("47"); System.out.println("46"); System.out.println("45"); System.out.println("44"); System.out.println("43"); System.out.println("42"); System.out.println("41"); System.out.println("40"); System.out.println("39"); System.out.println("38"); System.out.println("37"); System.out.println("36"); System.out.println("35"); System.out.println("34"); System.out.println("33"); System.out.println("32"); System.out.println("31"); System.out.println("30"); System.out.println("29"); System.out.println("28"); System.out.println("27"); System.out.println("26"); System.out.println("25"); System.out.println("24"); System.out.println("23"); System.out.println("22"); System.out.println("21"); System.out.println("20"); System.out.println("19"); System.out.println("18"); System.out.println("17"); System.out.println("16"); System.out.println("15"); System.out.println("14"); System.out.println("13"); System.out.println("12"); System.out.println("11"); System.out.println("10"); System.out.println("9"); System.out.println("8"); System.out.println("7"); System.out.println("6"); System.out.println("5"); System.out.println("4"); System.out.println("3"); System.out.println("2"); System.out.println("1"); }
Filed under: This may take a little while to write down
-
it's not the iterations you're speeding up there.... it's the writing to the console. you halved the number of console writes in the second example.
it is still faster with 2 separate console.log. I moved it to one because I wanted to maintain the 3 lines ;)
-