Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article)
-
@mott555 said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@Tsaukpaetra Did you try running it elevated?
No, I got some kind of path errror at that point. It flashed away too quickly to really tell.
-
@Tsaukpaetra Well, the full source code repository is a few posts up, pull requests accepted! E_CLOSED_DOING_IT_WRONG_OR_SOMETHING
-
@Lorne-Kates said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
for(int i=0;i>=-100;i--){printf("%d", i * (-1));}
this prints 0 through 100.
-
@fwd said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@Lorne-Kates said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
for(int i=0;i>=-100;i--){printf("%d", i * (-1));}
this prints 0 through 100.
That's what I get for copying @fox's shitty code.
-
@Lorne-Kates said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@fwd said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@Lorne-Kates said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
for(int i=0;i>=-100;i--){printf("%d", i * (-1));}
this prints 0 through 100.
That's what I get for copying @fox's shitty code.
You really didn't see that cumming?
Edit: Not even going to fix that.
-
@Polygeekery said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
It is possible to get a CIS degree these days apparently without even knowing that all mathematical operations a computer does are addition.
What definition of "addition" are you using that doesn't refer to some sort of group operation? Because lots of operations computers do are not invertible. Ignoring assignment (and state changes of all forms), bitwise AND and OR are not invertible, nor are bitshifts, nor are branches or even comparisons.
-
@joegy he said mathematical, not logical. Subtraction (two's complement), multiplication, and division are all accomplished by performing addition.
-
@darkmatter okay, I forgot whether it was 100 to 0 or 100 to 1 in the time between me seeing this thread on my phone and me getting home and writing that post. Sue me.
-
@anotherusername I am a working mathematician and have never heard "mathematical" defined to mean "defined in terms of addition".
-
@joegy it's not "defined in terms of addition", it's referring to the basic mathematical operations (addition, subtraction, multiplication, and division... and maybe exponentiation, depending on who you ask). Computers perform all of those by adding.
If we're talking about logic, all logic can be performed with NAND (or NOR, for that matter), but that's a different issue, not really what he was talking about.
-
@anotherusername said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@joegy it's not "defined in terms of addition", it's referring to the basic mathematical operations (addition, subtraction, multiplication, and division... and maybe exponentiation, depending on who you ask). Computers perform all of those by adding.
If we're talking about logic, all logic can be performed with NAND (or NOR, for that matter), but that's a different issue, not really what he was talking about.
I assume that by addition, subtraction and multiplication, you mean all these modulo the various word sizes, and by division you mean integer division with truncation. These are weird canditates for "basic mathematical operations" to the exclusion of all others, and the latter cannot even be defined in terms of addition (in any group).
The original claim was that "some programmers don't even know that all mathematical operations are defined in terms of addition", and everyone who has questioned this has been told that "mathematical" is given some weird special definition on this board for which the claim is tautological.
I'm just saying that I've never heard of this definition anywhere else.
-
@joegy you're hung up on the word that he used. It may or may not be the right word to use; that really doesn't matter. What I'm telling you is what he meant.
Computers perform almost all math by adding. All of the basic mathematical operations that it can perform, it performs by adding; any advanced math that you program it to perform will be broken down into a combination of logic and math, and the math will be performed almost completely by adding.
Does that make sense now?
-
somebody should write a fizz buzz and poker face the rest of the interview, come back with results.
-
@anotherusername Ok, maybe I'm just confused by this distinction between "math" and "logic".
Say I have two 32-bit unsigned integers. If I divide them (with truncation), e.g. with the x86 DIV instruction, this can't be defined in terms of addition, so this is "logic". If I add them with ADD, in the ring of integers mod 2^32, this is "math" because it's addition. If I XOR them, this is addition in a product ring of integers mod 2, so this is "math". If I AND them, this is destructive so it's "logic".
Honestly this separation sounds crazy and random to me.
-
@joegy said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Say I have two 32-bit unsigned integers. If I divide them (with truncation), e.g. with the x86 DIV instruction, this can't be defined in terms of addition
-
@anotherusername How is shifting defined in terms of addition? How about conditionally setting a bit?
-
Shifting is multiplying or dividing by a power of 2.
Conditionally setting a bit is conditionally adding.
Really the only point is that a computer performs subtraction, multiplication, and division by adding. There's also some logic involved -- decisions, logical shifts -- but they're mainly performed by adding.
-
@joegy said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Ok, maybe I'm just confused by this distinction between "math" and "logic".
It's easy: mathematicians say logic is a branch of math, and logicians say math is a branch of logic. Philosophers are wiser, and say both groups should shut up and buy another round of .
-
@dkf said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
another round of .
Finally, somebody making sense!
(Sorry @anotherusername , and thank you for your patience.)
-
@anonymous234 said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Fine, I guess I'm doing this too.
for(int i=0;" >_ :.1-:!#@_ >0# "# *+19+19$
Features:
- Funge-98, can be run in Befunge-93 by adding "<" first, though that violates the main rule.
- Kept it one-dimensional for extra compatibility. Main code runs left-to-right for readability.
- Warning: in Funge-98, this will attempt to open file "\x0f" (that is, ascii code 15). If it succeeds, then it will write "" to it, then attempt to open file "" (empty string) and write "" to it too. If the first file opens successfully but the second one doesn't, it will get stuck in an infinite loop.
- Has two loops, but only for befunge-93 compatibility reasons, one could be removed otherwise (which would also make it 10x more efficient).
Remember the whole "only one loop allowed" bit?
-
@anotherusername said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Shifting is multiplying or dividing by a power of 2.
That's the outcome of shifting; I don't recall encountering a computer that implements it that way though.
-
for (int i = 0; i < 100; i++) { execlp("curl", "https://gist.githubusercontent.com/BenLubar/d4fcc661678275a440ef9583e975ecf6/raw/d570f2ecf420cd5739f3e2ac607c557913a4a6be/gistfile1.txt", NULL); }
-
@Salamander regardless of how it does it, they're the exact same thing.
-
@anotherusername Then what's the point of talking about how computers define operations?
By that same reasoning, it doesn't matter that subtraction is the addition of negative numbers either. Same goes for multiplication and division.
-
@Fox said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@darkmatter okay, I forgot whether it was 100 to 0 or 100 to 1 in the time between me seeing this thread on my phone and me getting home and writing that post. Sue me.
Since you've microagressed me, I just might.
-
@anotherusername said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Really the only point is that a computer performs subtraction, multiplication, and division by adding. There's also some logic involved -- decisions, logical shifts -- but they're mainly performed by adding.
Shifts are done structurally rather than with adding as that's much cheaper in hardware, and multiplies are made with combinations of shifts and adds as well as a few basic bitwise-logical operations. (The long multiplication algorithm in binary turns out to be ridiculously easy.)
-
@dkf addition contains shifting as one of its steps, so why would shifting be computed by a process that requires shifting?
-
@ben_lubar said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
addition contains shifting as one of its steps
-
func add(a, b uint) uint { total := a ^ b carry := a & b for carry != 0 { shift := carry << 1 // look @value@index carry = total & shift total ^= shift } return total }
-
@ben_lubar Even the compiler ought to at that code.
-
@dkf How about this?
public static uint AnotherAdd(uint a, uint b) { uint c = (a & b) << 1; return (c == 0) ? a | b |c : a | AnotherAdd(a, c); } public static void AddTest() { uint a = 8; uint b = 7; Console.WriteLine("A + B = {0}", a + b); Console.WriteLine(AnotherAdd(a, b)); }
-
@cheong that one doesn't work
-
@ben_lubar Yup, flewed logic.
-
@cheong said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
flewed logic
-
@Fox said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Jesus christ, seriously? for(int i=0;i<=100;i++){printf("%d",100-i);} takes approximately ten seconds to type. Maybe twenty seconds to write. And maybe five to ten seconds to think about before you start writing. How are so many people taking more than two minutes?
I wouldn't know by heart which %something represents an integer in the printf formatting string. Does that make me a bad programmer?
-
@Grunnen No. Something you can google in 5 seconds is not something you need to know.
-
@ben_lubar said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Has google books always sucked on mobile or is this a new thing?
I can't even read that because it's rendering like I'm on a desktop and it's scrolling instead of zooming.
-
@Yamikuronue said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@PWolff Article says "cannot use two loops"
This is what gets me.
Do they mean two explicit loops, or can't cause the machine to perform two loops?
I know that sounds trivial, but it's not always the case.
Sometimes you can hide an O(2^n) behind a single line of code.
@Magus said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
maybe I will try a joke that doesn't follow the rules:
Console.WriteLine( Enumerable .Range(0, 99) .Select(i => 100 - i) .Aggregate(string.Empty, (aggregate, current) => aggregate + Environment.NewLine + current) );
And then you get something like this, which IMO is totally legit but feels like a joke.
If an interviewer rejected that, I'd question their company.
A bigger question for me is, if having a degree can't vet out the applicants, then why require one?
-
@xaade said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
A bigger question for me is, if having a degree can't vet out the applicants, then why require one?
To prevent having applications from high school kids who think they're the shit.
-
So wading through hundreds of applications from college kids who think they're the shit.... is so much better?
All you did is add entitlement to the mix.
-
@xaade the requirement of a degree id to prevent you from having a shitton if high schooler applications on top of all of the other ones you get. In other words, it does vet out applicants. Just that the remaining pool is still huge and mostly underqualified.
-
@Fox said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
Just that the remaining pool is still huge and mostly underqualified.
Then, can't you get the same effect by just arbitrarily throwing out 80% of the applications?
Eventually it's going to come to this, because the quality of college student is going down every year.
College has become more about money than producing hard-working students.
-
@xaade there's a decent chance you'll throw out most of your qualified candidates that way.
-
@Fox said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
@xaade there's a decent chance you'll throw out most of your qualified candidates that way.
Yeah, but I'm finding that college is becoming less of a qualifier.
Students that are wanting free passes on their tests because they'd fail with all of their activism, which is so much more important...
Essentially they want society to give them a free pass to enable their protesting.
And we wonder why we're getting kids from college who can't program an if statement.
I'm sorry, but that level of fail makes the degree pointless. It's just paper, and proof that you CAN spend someone else's money for four years.
-
I was about to post a clever bit of code, but then I realised my progamming-fu is lacking, so I will just post the spec:
for i = 0 to 99:
if i = 0, create a new topic in nodebb with the topic "100 to 1", first post "100 - @index"
otherwise, just post to the newly created topic "100 - @index"
-
for (int i = 0; true;) { using (SqlConnection conn = new SqlConnection("Server = (local); Database = test; Trusted_Connection = True;")) { conn.Open(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = "IF OBJECT_ID('numbers') IS NULL BEGIN CREATE TABLE numbers (number int) END"; comm.ExecuteNonQuery(); if (i == 0) { comm.CommandText = "TRUNCATE TABLE numbers"; comm.ExecuteNonQuery(); comm.CommandText = "INSERT INTO numbers VALUES (100)"; comm.ExecuteNonQuery(); i = -1; } comm.CommandText = "SELECT number FROM numbers"; using (SqlDataReader reader = comm.ExecuteReader()) { reader.Read(); int number = reader.GetInt32(0); Console.WriteLine(number); if (number == 1) { break; } } comm.CommandText = $"update NUMBERS set NUMBER -= 1"; comm.ExecuteNonQuery(); } } }
-
Unnecessary obscurity is also possible within the original requirements.
for(int i=0;i!=100;++i) { char s[] = " 10987654321 0987654321"; printf("%c%c%c\n", s[i==0], s[i/10%10+3-(i==0)], s[i%10+13]); }
It does contain a bug of course.
-
I notice that we've been chewing away at this thread for a year. I guess that puts us, as a community, rather in the upper limit of Whining Time. :)
-
@Jaloopa I was also going to do one with a massive switch statement, or a single loop iteration with 100
Console.WriteLine()
s, but that was too much work.As it turned out, just after I finished this, a colleague who's transitioning into C# from ancient obscure languages needed help writing a small app to read some SQL and write to a file, so I was all fresh and sounded like I knew things like connection string formats off the top of my head. Which was nice
-
@cartman82 said in Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article):
As for myself, I solved it in like 15 seconds and I don't feel I'd spend much time whining about my current employer. So I'd fit right into his chart.
I solved it in about that time myself and I DO whine about my current employer a bit (as you all know). However, I wouldn't whine about them while being interviewed.
What does that say about me?
ETA*
FUCK, JUST REALIZED IT'S A YEAR OLD THREAD. WHO KEEPS FUCKING NECROING ALL THIS STUFF? I SERIOUSLY MISS THIS DISCOURSE'S "THIS THREAD IS FUCKING DEAD IN THE WATER, ARE YOU SURE YOU WANT TO REPLY" TOSTER!!!!!11111ONEOENOENEONENOE
NO I WILL KEEP SCREAMING FOR A WHILE!!!!11111ONEONEOENOENOENELEVLELVELLELEENELELVLELENELELVLEN