[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1554473482618.png (163 KB, 723x666)
163 KB
163 KB PNG
bool is_even(int x)
{
while (x > 0) {
x -= 2;
}

return x == 0;
}
>>
ok now do is odd
>>
>>103249272
bool is_odd(int x)
{
return !is_even(x);
}
>>
What happens if x is negative?
>>
>>103249244
What is this mumbo jumbo. Why don't you use a more readable language like Python.
def is_even(x):
return (lambda f,x:f(x,1)//2==f(x,0)//2)(lambda a,b:(lambda x,y,z:x(x,y,z))
((lambda s,c,d:(d and[s(s,c^d,(d&c)<<1)]or[c])[0]),a|b,a&b),abs(x))
>>
for your interview take home question, write a function to get the highest prime number
>>
>>103249517
then it's always uneven because OP is a tard
>>
File: 1547743052479.jpg (64 KB, 758x644)
64 KB
64 KB JPG
>>103249559
>>103249517
bool is_even(int x)
{
if (x < 0) {
x *= -1;
}

while (x > 0) {
x -= 2;
}

return x == 0;
}
>>
>>103249244
Good morning saar. Is 2^64-1 even saaaaar? Which decade do i get answer to this question saaaar
>>
>>103249751
OP might be retarded, but you're even more retarded, 4 billion subtractions take like a second on modern CPU.
>>
>>103249719
Nice
>>
!(x & 1)

Is this the retard thread?
>>
>>103250143
>& 1
you're a midwit which I respect even less than actual retards
>>
>>103249244
i dont get it, is this to mock women or saars?
>>
>>103250227
I don't know anymore if ppl are larping as a retard or are one. Shit's fucked up.
>>
>>103250352
it's to mock white "men"
>>
>>103250494
Anyone who uses anything else but x % 2 is a moron.
>retard: knows modulo from math, clueless about performance
>intelligent person: knows modulo from math, actually implemented division/modulo by a literal by converting it into shifts and multiplies
>midwit: thinks he's intelligent for copying code that maybe was useful in 80's before intelligent people realized that compiler can optimize common patterns automatically, doesn't realize that by being contrarian in 2024 outs himself as a bigger retard than actual clueless retards who never cared to learn about fast way to check if number is even
>>
>>103249800
>2^64=4 billion
>american
>huh who controls the education system there?
>((()))
Not surprised.
>>
>>103250577
Sure Dunning-Kruger.
>>
>>103250143
!(x & 1)  // I am very smart

fixed
>>
>>103250649
>midwit uses midwit talking point to deflect midwittery
>>
>>103250672
!(x & 1) /* I am very smart */

Fixed for real this time
>>
>>103250685
use holyc you shitskin, this is /g/ and no one gives a shit about your gcc that you learned in mumbai academia
However I must agree that anyone who thinks he's unironically smart and brags because muh I know x&1 should hang himself
But for a joke its OK I guess
>>
>>103250648
>2^64
Yes, I made a mistake of dividing the power by 2 instead of subtracting it, the fact you haven't even attempted to do it is consistent with the fact that you're still a colossal retard. The correct number is 2^63 - 1.
>>
>>103250715
Sorry I am not going to use a compiler that causes 100% of its active developers to commit suicide.
>>
>>103250722
>Never heard of unsigned
just kick that chair and let it go
>>
>>103250733
But enough about Rust
>>
>>103250738
was referring to the fact that every iteration subtracts by two, therefore it is at most (2^64-1)/2 iterations, but I already pointed out that you're a retarded nigger.
>>
>>103250747
Rust is only 41%, HolyC trannies really don't send their best (the only good one is dead lmfao).
>>
>>103250577
>intelligent people realized that compiler can optimize
This only makes developers dumber. The intelligence should be in the developer, not the compiler you codemonkey.
>>
>>103250754
If you go that deep into the assembly then you have to count the comparisons too which makes it 2^64-1 you retarded faggot
And you didnt even say the same thing, first it was 2^63-1 now (2^64-1)/2
>>
>>103250803
>same amount of iterations and comparisons
>comparisons double in midwit's mind arbitrarily
>>103250800
Noone cares, midwit, I am intelligent so I use x % 2. I am intelligent so I use simple words. I am intelligent so I use simplest solutions to most complex problems.
>>
>>103250840
>I am intelligent
If someone has to say this, he isn't.
>>
>>103250840
I didn't talk about iterations or comparitions or cpu instructions but the fucking input number and that it takes a long time in my first post
So there is no "correct number"
I don't even know what are you arguing about.
>>
>>103250912
Concession accepted, midwit. Don't pretend to be humble after writing x & 1 for attention and implicit assertion that you're more intelligent for using more complex expressions that are provably not better than dumbest possible one, because you aren't intelligent, only say you are.
>>
>>103250942
Okay you can have the last word. Call me a retard again so you can tell to mom that you won.
>>
>>103250701
!(x & 1) //! I am very smart

fixed for real this time ;)
>>
>>103249719
Better to do it the other way round. Make positive values negative and then count up by 2; that will actually work for all inputs.
>>
>>103249517
The bar bursts in flames
>>
>>103251195
that's the same thing but in reverse
>>
File: 1727001059068495.jpg (26 KB, 828x588)
26 KB
26 KB JPG
>>103249244
bool IsEven(int x) {
string y = x.ToString();
char z = y[y.Length - 1];
switch(z) {
case '1':
return false;
break;
case '3':
return false;
break;
case '5':
return false;
break;
case '7':
return false;
break;
case '9':
return false;
break;
default:
return true;
break;
}
}


I haven't even scrolled this thread but this is the truest way.
>>
>>103249244
this logic will fail for unsigned ints.
>>
>>103254187
quality post
>>
I used to laugh at code like in this thread but now I see it with dread because it's some shit the pajeets at work would write and I see every now and then.
>>
>>103254580
You will be lucky if pajeets will actually write this instead of adding a dependency that will break in production.
>>
>>103249244
int even(int x) {
char* a = malloc(16);
snprintf(a,16,"%d",x);
int i = 0;
while(a[i]) i++;
i--;
switch(a[i]) {
case 48: case 50: case 52: case 54: case 56: return 1; default: return 0;
}
}

the only correct way



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.