Infallible Code
-
At least this madness is isolated to this function. It can easily be fixed.
Pirateโs code is just cluttered with magic numbers everywhere. Hard coded numbers that are referring to a big โstory arrayโ, or characters. Itโs just a giant web of complexity. The only fix is to start from scratch.
It's simple. The only problem is that your code sucks!
-
Though, obviously I had to come up with some ridiculous solutions:
bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
This one works without conditionals
bool IsEven(int i) { try { int _ = (i & 1) / (i & 1); } catch (Exception) { return true; } return false; }
s[^1]
Ohh wow, I've been learning it casually for years, and I didn't know that existed in C#. I guess I should go back and hit the books some more.
-
If small numbers are much more frequent, it's better to return early. Really, you should gather statistics about the numbers the function is called with, and put the most frequent ones at the top.
-
The fuck is that
-
Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious,
I've been trying to figure out roughly how many lines of code that would equal out to but I've run out of fingers.
Ah, common issue. When that happens, you just start using your toes.
-
Yeah, but did your dad work at Blizzard??
Iโm the first ever second generation Blizzard employee!
-
Definitely a vibe.
wrote on last edited by [email protected]The only way I could see that happening is if enough people poisoned the data to do this
-
assert IsEven(-2);
Now see, you need the other method. IsNegativeEven()
-
This post did not contain any content.
Even plus even equals even.
Odd plus odd equals even.
Only odd plus even makes an odd.
Are there twice as many even numbers as there are odd numbers?
-
The fuck is that
Okay so basically this is saving bytes on a technicality but also good programming language design (for this specific purpose).
The first aspect is that since you're scored on bytes, it's not really to your advantage to use a language that uses ascii (or utf-8) for it's tokens, because a large part of it is unprintables like DEL or BELL. So people have designed specially crafted golfing programming languages that use a full 256 possible characters in order to pack as many features as possible in as few bytes as possible.
The good design part of it is that if you really think about it hard, there's really not that many things you expect a programming language to do. It turns out that 256 total different operands is about in the sweet spot, so each character that's available in the 1-byte code page is mapped to one command, and the languages are also designed to make as many things as possible implicit, both at the cost of readability. Remember, all that matters here is getting the lowest score, not code maintainability or anything else.
This leads to languages like japt (which is a terse form of JavaScript, I'm pretty sure) or pyth (same for python) or Vyxal (my personal favorite, used to be python based but is now bespoke) that look like this but absolutely own at getting a task out in as few bytes as possible.
-
Now see, you need the other method. IsNegativeEven()
We can avoid expensive branches (gasp) by using some bitwise arithmetic to achieve the so-called "absolute value", an advanced hacker technique I learnt at Blizzard. Also unlike c, c# is not enlightened enough to understand that my code is perfect so it complains about "not all code paths returning a value".
private bool IsEven(int number) { number *= 1 - 2*(int)(((uint)number & 2147483648) >> 31); if (number > 1) return IsEven(number - 2); if (number == 0) return true; if (number == 1) return false; throw new Exception(); }
-
Even plus even equals even.
Odd plus odd equals even.
Only odd plus even makes an odd.
Are there twice as many even numbers as there are odd numbers?
Even plus even
Odd plus odd
Even plus odd
Odd plus even
-
Even plus even
Odd plus odd
Even plus odd
Odd plus even
Are we working with a non-abelian group? Other wise this would work.
-
Iโm the first ever second generation Blizzard employee!
This is such an unhinged thing to say, it had me rolling.
-
Did you know that he worked for Blizzard for seven years? Not only that, but he was Blizzard's first second-generation employee. He grew up in Blizzard. An extreme accomplishment to be certain. Thank you based and blizzpilled Pirate Software.
I wonder if he was the one stealing the breast milk. After all, I've heard he can be really childish.
The funniest thing about his blizzard obsession and the fact that his dad is like a first generation blizzard employee is such a weird glex these days.
So, did you get to harass any women yourself, or did you get your dad watch doing it? Were you a high enough employee that they gave you the Bill Cosby room to rape someone?
-
I removed the tail recursion for you:
private book IsEven(int number) { if(number > 1) return IsEven(number - 2) == true; if(number == 0) return true; if(number == 2) return false; }
What'd be the result for
IsEven(1)
? -
This noob even forgot zero
That and all negative values
-
What'd be the result for
IsEven(1)
?Stack overflow
-
Pah, mathematicians and their generally applicable pure approach to solutions and fancy modulus operations, who needs 'em? Computing is applied and we always work with well-defined finite precision. Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious, but we're programmers! That's what code generation is for.
You can generate the code with a simple macro.
-
That and all negative values
Patience guys, I'm sure they'll get to supporting zero and negative integers as soon as they finish all positive integers