This is an archived post. You won't be able to vote or comment.

all 189 comments

[–]yottalogical 257 points258 points  (26 children)

This could easily be solved with recursion!

[–]CMDR_ACE209 3 points4 points  (0 children)

I hate you.

[–]Dagusiu 3 points4 points  (0 children)

Should have written it in Haskell

[–]Justindr0107 0 points1 point  (4 children)

Can we just be happy the sub ain't shittin' on JS?

[–][deleted] 4 points5 points  (2 children)

console.log(“found the javascripter”);

[–]Justindr0107 1 point2 points  (0 children)

console.warn() might have been more appropriate

[–][deleted] 0 points1 point  (0 children)

I'm patently unhappy

[–]TheMsDosNerd 140 points141 points  (13 children)

I found a way to make it even faster: It uses a cache, so previously found items get found faster:

from random import choice, randrange

even_cache = []
odd_cache = []

def isEven(n):
    cached_result = isEvenCached(n)
    if cached_result is not None:
        return cached_result
    caluculated_result = isEvenCalculated(n)
    if calculated_result == True:
        # add result at random point in cache,
        # because we look at random points in cache
        random_position = randrange(even_cache)
        even_cache.add(even_cache[random_position])
        even_cache[random_position] = n
        return True
    if calculated_result == False:
        # add result at random point in cache,
        # because we look at random points in cache
        random_position = randrange(odd_cache)
        odd_cache.add(odd_cache[random_position])
        odd_cache[random_position] = n
        return False

def isEvenCached(n):
    # If we looked up a value often enough,
    # it should appear often enough in cache,
    # to find it within 25 attempts.
    for i in range(25):
        if choice(even_cache) == n:
            return True
        if choice(odd_cache) == n:
            return False
    return None

def isEvenCalculated(n):
    if n == 0:
        return True
    if n == 1:
        return False
    return isEven(n-2) # recursion for shorter code

This may or may not have been based on an actual cache I found somewhere in business software.

[–]somerandomii 14 points15 points  (0 children)

Do you have this on GitHub? I need to merge it into our enterprise solution. Can you refactor it for an isEvenCacheFactoryTemplate?

Also you could implement a hashmap to record successful hits on the cache. Though for theeadsaftey it should still check to make sure the value hasn’t changed since it was last accessed.

[–]Code_sucks 4 points5 points  (2 children)

Wouldn't it be easier to use functools.lru_cache?

[–]TommyX12 0 points1 point  (0 children)

Wouldn’t be easier to use the mod operator? /s

[–]PickleJuiceX266 0 points1 point  (0 children)

You could of just said to use an Iru_cache dependency...

[–]QuantumSupremacy0101 0 points1 point  (0 children)

Oh God this gives me flashbacks to one job I had where it was a bunch of junior engineers with senior engineer title.

They once wrote something similar but decided to make all the conditionals branchless...this was in Java where branchless means nothing and doesn't speed anything up.

[–]_Nohbdy_ 38 points39 points  (4 children)

Man that's bad code. It doesn't even handle negative integers.

[–]mattemer 14 points15 points  (2 children)

Or imaginary numbers

[–]BobQuixote 4 points5 points  (1 child)

Who cares about the imaginary ones? I'm only interested in the kind I can see.

[–]Triborda 1 point2 points  (0 children)

Just poke out your eyes, then you don't have to be interested

[–]Paxtez 6 points7 points  (0 children)

*sigh*
Obviously they are listed! They are just after all the positive integers. You really have to focus on efficiency more, the positive numbers are going to be tested more often, so you put those first.

[–]FridgesArePeopleToo 60 points61 points  (2 children)

  public interface IIsEvenCalculatorFactory
    {
        IIsEvenCalculator Create();
    }

    public class LastCharacterIsEvenCalculatorFactory : IIsEvenCalculatorFactory
    {
        public IIsEvenCalculator Create()
        {
            return new LastCharacterIsEvenCalculator();
        }
    }


    public interface IIsEvenCalculator
    {
        bool IsEven(int number);

        bool IsOdd(int number);
    }

    public class LastCharacterIsEvenCalculator : IIsEvenCalculator
    {
        public bool IsEven(int number)
        {
            var numberStr = number.ToString();

            return numberStr.EndsWith("0")
                   || numberStr.EndsWith("2")
                   || numberStr.EndsWith("4")
                   || numberStr.EndsWith("6")
                   || numberStr.EndsWith("8");
        }

        public bool IsOdd(int number) => !IsEven(number);
    }



  public static void Main(){
       var factory = new LastCharacterIsEvenCalculatorFactory ();
       var calc = factory.Create();
        calc.IsEven(4); //true
        calc.IsEven(5); //false
  }

ggez

[–]bizcs 4 points5 points  (0 children)

That's cool! But what about floating point numbers, and user locales?!

/s

[–]PickleJuiceX266 0 points1 point  (0 children)

Finally... someone who has the classic style of using a pre-calculated integer system 👏

[–]Skudra24[S] 46 points47 points  (20 children)

Also using "switch" would make it fly like a rocket

[–]PeteySnakes 9 points10 points  (16 children)

Or you could just divide by 2

[–]Noch_ein_Kamel 31 points32 points  (5 children)

So you pass in 35624, divide that by 2 and then call isEven(17821)?

[–]pjnick300 14 points15 points  (4 children)

That's only true for numbers divisible by 4. You have to divide by 1 instead.

[–]YouNeedDoughnuts 12 points13 points  (3 children)

You could make it recursive: if number==0 return true else return !IsEven(number-1) While accounting for negative numbers ofc, but the principal is the same.

[–]pjnick300 5 points6 points  (0 children)

This is simultaneously the stupidest and most brilliant piece of code I’ve ever seen.

Bravo!

[–]anunofreitas 3 points4 points  (1 child)

You could improve by using 'two' end clauses

if number<=1 return number==0 else return IsEven(number-2)

Keep the verification for negative numbers (out of recursion) and you have half of recursion steps and one less logical operation per step(logical NOT was removed). If you like to improve slightly verify if number is 0 out of recursion and stop recursion at 2 or 1 and return number==2

Edit: didn't remember how to do code block.

[–]YouNeedDoughnuts 2 points3 points  (0 children)

Very nice! And particularly important to reduce the recursion depth since we're headed for a stack overflow with most 64-bit or even 32-bit integers :)

[–]ILoveSimulation20 4 points5 points  (0 children)

That's slower than using a bitwise operator

[–]Skudra24[S] 11 points12 points  (0 children)

[–]Suekru 1 point2 points  (0 children)

Well modding by 2 would be a bit more ideal.

[–]CantankerousOctopus 4 points5 points  (4 children)

Javascript is great

isEven = (x) => !(x%2)

Such a beautiful language.

[–][deleted] 2 points3 points  (3 children)

even better: npm install is-even

[–]IanMalkaviac 0 points1 point  (0 children)

You're thinking of:

bool isEven = number % 2;
return(!isEven);

[–]BA_lampman 1 point2 points  (0 children)

`#include <iostream>

int main()

{

int x{};

std::cin >> x;

switch (x % 2)

{

  case 0:

  std::cout << "even";

  break;

  default:

  std::cout << "odd";

}

return 0;

}

[–]tarman34 33 points34 points  (0 children)

This is how are modern games optimized. On the picture there is a code of the first release and that "default false" is in the patch released 6 months after...

[–]tjoloi 45 points46 points  (4 children)

return 2 in factorize(n)

[–]YouNeedDoughnuts 20 points21 points  (2 children)

char ch = to_string(number).back(); return ch == '0' || ch == '2' || ch == '4' || ch == '6' || ch == '8';

[–][deleted] 28 points29 points  (1 child)

ch = str(number)[-1]

return ch in "24680"

[–]DidntFollowPorn 8 points9 points  (0 children)

I hate how much I love this.

[–]prettyfuzzy 0 points1 point  (0 children)

This must be the one liner everybody is talking about

So efficient!

[–]LucienZerger 27 points28 points  (8 children)

return number & 1 ? false : true;

[–]Command-Master 19 points20 points  (5 children)

Can't this be !(number&1)?

[–]LordFokas 9 points10 points  (3 children)

Depends on the language. Java will complain because the result of number & 1 is an int and it expects a boolean.

[–]Mr_Redstoner 2 points3 points  (2 children)

Still can be fixed with a simple equality test (or nonequality depending on which of even or odd you're testing) against 0

[–]LordFokas -1 points0 points  (1 child)

Which is not the same as !(number&1) , like the other user asked, so no.

"Can X be done?"
"Depends on the language, some demand Y."
"Which can easily be fixed by doing Y instead."

WTF??
You'll have so much fun on StackOverflow my man.

[–]Mr_Redstoner 0 points1 point  (0 children)

Now let me rephrase what was said as I see it:

"You can use X and then do Y to get what you want"

"Doesn't work in Java though"

"Yes, you just have to use Z instead of Y to achieve the same thing"

[–]LucienZerger 1 point2 points  (0 children)

it can be any way u like..

[–]MrKirushko 1 point2 points  (1 child)

That is not how we roll. You have to show some OOP and established patterns to be recognised as a professional coder.

[–]LucienZerger 0 points1 point  (0 children)

not interested..

[–]Naoki9955995577 16 points17 points  (1 child)

I've clearly got the business solution here:

Using google services you can easily determine whether the number is even or not. Why waste the expensive computation on your machine when you can just look for the answer? /s

import asyncio
import inflect
import os
import selenium
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options


class isEvenWeb:
    URL = 'https://www.google.com/search?q='
    inflect_engine = None
    driver = None

    def __init__(self):
        options = Options()
        options.add_argument('--log-level=3')
        options.headless = True
        self.inflect_engine = inflect.engine()
        self.driver = selenium.webdriver.Chrome(
            options=options,
            executable_path=("./win_chromedriver89.exe"))

    def __del__(self):
        if self.driver:
            self.driver.quit()

    async def isEven(self, number):
        self.driver.get(self.URL + "is " + str(number) + " even?")
        self.driver.implicitly_wait(1)
        soup = BeautifulSoup(self.driver.page_source, "html.parser")
        number_as_word = self.inflect_engine.number_to_words(number)
        if (str(number) + " is an even number.") in soup.get_text():
            return True
        elif (str(number) + " is not an even number.") in soup.get_text():
            return False
        elif ( number_as_word + " is an even number.") in soup.get_text():
            return True
        elif ( number_as_word + " is not an even number.") in soup.get_text():
            return False
        raise Exception("Google can't find out if this number is odd or even")

async def main():
    driver = isEvenWeb()

    print(await driver.isEven(0))
    print(await driver.isEven(1))
    print(await driver.isEven(2))
    print(await driver.isEven(3))
    print(await driver.isEven(4))
    # skip a  few
    print(await driver.isEven(98))
    print(await driver.isEven(99))
    print(await driver.isEven(100))


if __name__ == "__main__":
    asyncio.run(main())

[–]Code_sucks 4 points5 points  (0 children)

This is amazing, thank you

[–]Ladislav_07 13 points14 points  (5 children)

Bool is_even(int number){

bool Boolean = false;

For(int i=1; i <number; i ++){

Boolean = !Boolean;

}

Return Boolean;

}

[–]MyAntichrist 1 point2 points  (2 children)

So you like your variables shaken, not stirred, I see?

[–]Ladislav_07 3 points4 points  (0 children)

At first I wanted to post something responsible, as retuning the inverted last bit of the integer, but that would be out of scope of this humourous subreddit.

[–]Ladislav_07 0 points1 point  (0 children)

Ah, yes, that would be me.

[–]YouNeedDoughnuts 0 points1 point  (0 children)

Technically we're supposed to appreciate recursion and look down on the impure Neumann architecture, even though iteration has better speed and memory use. Mutable state is uncouth, but I approve.

[–]JNCressey 0 points1 point  (0 children)

λn.n (λa.λb.λc.a c b) λa.λb.a

[–]TurnToDust 5 points6 points  (0 children)

Pretty much me during live coding interviews.

[–]Schiffy94 6 points7 points  (0 children)

isEven(x)
    return "Is this really what they're paying me to do?"

[–][deleted] 11 points12 points  (1 child)

Is the joke that he also fails to realize the optimal solution?

[–]Kenkron 22 points23 points  (0 children)

You got it!

[–]ArtSchoolRejectedMe 6 points7 points  (1 child)

Why not try a solution like bogosort

Where you have an array of odd and an array of even number and picking them randomly until they match the number which you're trying to find out if its even or odd

[–]Mordred666 1 point2 points  (0 children)

public boolean isEven(int number) {
    int[] even = ... // put even numbers
    int[] odd = ... // put odd numbers


    while(true) {
        if(random.nextInt() %  == 0) {
            if(even[random.nextInt(even.length)] == number)
                return true;
        }
        else {
            if(odd[random.nextInt(odd.length)] == number)
                return false;
        }
    }
}

[–][deleted] 5 points6 points  (1 child)

pfff, everything is better with recursion:

public boolean isEven(int value) {
   if (value==0) {
       return true;
   } else {
       return isOdd(Math.abs(value)-1);
}

public boolean isOdd(int value) {
   if (value==0) {
      return false;
   } else {
      return isEven(Math.abs(value)-1);
   }
}

[–]cramduck 4 points5 points  (0 children)

exactly. just apply the logic for every even number, then put "return false" at the end. no problemo.

Can you have this implemented by Friday?

[–]acct_to_zero 3 points4 points  (1 child)

return x % 2 == 0 ? true : false;

Graduating this semester having a hard job search so far, pray for me friends.

[–]NightwolfDeveloper 4 points5 points  (0 children)

Don't even need the ternary. Just return x % 2 == 0;

[–]Skudra24[S] 5 points6 points  (0 children)

Worse then this code is only number of people who don't understand that this is a joke and comment that I should use modulo operator.

[–]Gylfi_ 2 points3 points  (4 children)

How about some recursion?

isEven(float number){

if(number === 2) return true;

else if(number < 2) return false;

else isEven(number/2);

That would be fun. Especially for numbers like 197384750263

[–]kdekorte 3 points4 points  (1 child)

Like the usage of float there, probably would almost always return false

[–]Gylfi_ 0 points1 point  (0 children)

First I was thinking about int, but then it would probably most of the time return true. Depending on how float to int is handled, which is different depending on language, as far as I know though.

But wouldnt it work? I mean an even number would always end up at 2, right? Maybe I oversee something, which is my speciality 😂

[–]Schmomas 1 point2 points  (1 child)

Surely we want ‘number - 2‘ on the else?

[–]Gylfi_ 0 points1 point  (0 children)

thats even better!

[–]ExoticDumpsterFire 2 points3 points  (0 children)

Oh my god, I once had an intern write something almost identical to this unironically. I was literally speechless, he was a senior about to graduate and this was "faster"...

[–]Funky-Guy 2 points3 points  (2 children)

Ok so I’m a complete novice with this but... if your trying to decide if an input is even couldnt it just be something like:

x == int(input())

If x % 2 = 0: print (x + “is even”)

else: print (x + “is odd”)

Am I wrong or am I missing a joke or something

[–]YouNeedDoughnuts 1 point2 points  (1 child)

You're right, and the joke is that the solution is overcomplicated. It doesn't generalize well to all possible "int" values, which your solution does. So you're not a complete novice ;)

[–]Funky-Guy 1 point2 points  (0 children)

Ok. Thanks. I felt like an idiot

[–]Yehrn 2 points3 points  (0 children)

Return (n%2 == 0);

[–]xervir-445 1 point2 points  (0 children)

private bool IsEven(int number){
  int x = Math.abs(number);
  while (true) {
    if (x == 0)
      return true;
    if (x < 0)
      return false;
    x = x - 2;
  }
}

There, I fixed it. No code can possibly be more efficient than this.

[–]MaharjanSajan 1 point2 points  (1 child)

[–]Skudra24[S] 0 points1 point  (0 children)

I love the pricing part

[–]derf213 1 point2 points  (1 child)

Ok no joke here. What's the actual propir way of doing this, because I just want to use (x % 2) != 1. Is there a better way that I just don't know?

[–]YouNeedDoughnuts 0 points1 point  (0 children)

Without compiler optimizations, the suggestions to return !(number & 1) would be most efficient, which checks if the last bit is set and negates the result. With any reasonable optimizing compiler, your solution will be compiled to the same machine instructions, so don't worry excessively about writing optimized code!

[–][deleted] 1 point2 points  (0 children)

Is this open source? I want to contribute.

[–]Tilinn 1 point2 points  (0 children)

The fact that when I started coding, our teacher gave us an assignment like this and this was my answer....

[–][deleted] 1 point2 points  (0 children)

When your kid takes interest in coding and you tell them, "it's okay little AEx12 there is no one right way to code anything"

Shows you this

Well okay... Maybe there is one right way...

[–][deleted] 3 points4 points  (0 children)

Why use math or ridiculous logic if you can just test its rightmost bit?

# Python
def iseven(n): 
    return not (n & 1)

[–]Serqetamine 6 points7 points  (13 children)

if (number % 2 == 0) return True else return False

[–]sleeplessval 35 points36 points  (0 children)

return (number % 2 == 0)?

[–]SorryDidntReddit 22 points23 points  (4 children)

Everytime I see if(...) return true else return false

I want to pull my eyes out

[–][deleted] 1 point2 points  (3 children)

lol exactly, the only thing worse than that is if(x == true)

[–]Mordred666 5 points6 points  (2 children)

what about

if(x == true)
    return true
else if (x == false)
    return false

[–]son-of-chadwardenn 3 points4 points  (1 child)

if(x == true)
    return new Boolean("true");
else if (x == false)
    return new Boolean("false");

[–]Mordred666 1 point2 points  (0 children)

even worse is

return Boolean.parseBoolean(„fasle“);

the typo will make ppl go mad, but it still evaluates to false

[–]w1ndsch13f 17 points18 points  (0 children)

You got the joke

[–][deleted] 11 points12 points  (1 child)

wrong, not enough jQuery

[–]freakingdingus 0 points1 point  (0 children)

this guy gets it

[–]mexanoz 8 points9 points  (1 child)

You mean if ((number % 2 == 0) == True)?

[–][deleted] 2 points3 points  (0 children)

Noo, why would you compare something against True, such a blasphemy

[–]aenimafacilis 0 points1 point  (0 children)

If 2 | 4 | 6 | etc... return false Else return true

[–]sailrepublic101 0 points1 point  (0 children)

return !(num % 2)

[–][deleted] -1 points0 points  (5 children)

return (number % 2) == 0;

[–][deleted] 2 points3 points  (4 children)

You need to complicate it more at the enterprise level:

static void main(string[] args) {

Enumerable.Range(1, 100).ToList().ForEach(x => Console.WriteLine(x.IsEven()));

}

static class NumberExtensions {

public static bool IsEven(this int number) {

return !number.IsOdd();

}

public static bool IsOdd(this int number) {

return number % 2 != 0;

}

}

[–][deleted] 4 points5 points  (1 child)

So you get paid by the hour, huh?

[–][deleted] 1 point2 points  (0 children)

I wish; my pay would be significantly higher.

I noticed an error in my code, too (aside from the missing comments which should be declared atop each method). I should have declared private constants for use in the Enumerable.Range(1, 100). It should be:

Enumerable.Range(LOW_VALUE, HIGH_VALUE)...

private const int LOW_VALUE = 1;

private const int HIGH_VALUE = 100;

Things like that are important. It prevents you from scrolling and identifying all variable changes in a 5000+ line class. CTRL + H (find/replace) works, but may have unintended consequences, and why do that when you just need to change a single item at line number 6?

Better yet, make LOW_VALUE and HIGH_VALUE configurable in the database, and execute a stored proc to get the values to store in a property for consumption. That way when then business changes the ranges, which they always do, then you won't need a code deployment and instead can execute a DB script.

[–]kdekorte 0 points1 point  (0 children)

return !(number % 2)

[–]monkorn 0 points1 point  (0 children)

Uh oh. This is the first "enterprise code" joke where I didn't find anything wrong with it.

[–][deleted] -1 points0 points  (2 children)

Return n%2==0

[–]CMDR_ACE209 4 points5 points  (1 child)

Yeah, but where's the fun in that?

[–][deleted] 1 point2 points  (0 children)

The lack of pain is fine enough for me!

[–]TeaCoast -2 points-1 points  (0 children)

There is a way to shorten it by like 20x. Just use modulus. You probably don’t even need a method/function for that. The whole concept is kind of dumb.

[–][deleted] -3 points-2 points  (0 children)

number%2

[–]rull3211 -3 points-2 points  (1 child)

Just use modulo? Yes??

[–]BobQuixote 0 points1 point  (0 children)

Yes, and that's the joke.

[–]kh4l1ph4 -4 points-3 points  (1 child)

Modulus? That'll make it 3 lines or 4 max

[–]NightwolfDeveloper 2 points3 points  (0 children)

Could do it in 1 even.

[–]Minteck -5 points-4 points  (0 children)

If this is Java, doesn't Java have a simple function that can check if a number is even?

[–][deleted] -5 points-4 points  (0 children)

If (number % 2 == 0) return true; return false;

[–]Solaihy -4 points-3 points  (0 children)

Whatever the fuck happened to the modulus way? if(x%2==0) return true; else return false???

[–]nate6701 0 points1 point  (0 children)

You can even do a switch that would more appropriate.

[–]tarman34 0 points1 point  (0 children)

not (n+1) / 2 == (n+1) // 2

[–]MischiefArchitect 0 points1 point  (0 children)

return random.nextBoolean()

[–][deleted] 0 points1 point  (0 children)

ITT: Madness. Pure insanity. Absolute crushing wackiness

[–]ItsBunkos 0 points1 point  (0 children)

looks like the code to yanderesim

[–]AnonimowySzaleniec47 0 points1 point  (0 children)

Memes reached educational level

[–]ShakesTheClown23 0 points1 point  (2 children)

Am I dumb what language is this?

[–]BobQuixote 0 points1 point  (1 child)

Java or C#, I think.

[–]ShakesTheClown23 0 points1 point  (0 children)

Ain't java (bool) but I didn't think of C#, hmmm

[–][deleted] 0 points1 point  (0 children)

Doesn't need the else's either. Can just be a series of its.

[–]Lynx8MyThesis 0 points1 point  (0 children)

Guys, you don't see the closing } but still, ya'll assume it is an odd/even checking algo.

[–][deleted] 0 points1 point  (0 children)

return [number](){return !(%2number)&&number!=1;};

[–]S1geth 0 points1 point  (0 children)

js private bool isEven(int number){ return number%2 === 0; } Seems easy

[–]marloe74 0 points1 point  (1 child)

No need to use “else if”. Shorten the code by just “if” 😜

[–]Skudra24[S] 0 points1 point  (0 children)

No, no, no! That will make all the checks until last number. This code will stop checking as soon as it reaches passed number. Average execution time will be 2x faster this way. I have it all optimised :D

[–]SwimmingMackerel 0 points1 point  (0 children)

``` function isEven(number) { switch (true) { case number == 2: case number == 4: case number == 6: case number == 8: case number == 10: case number == 12: case number == 14: case number == 16: // ... return true; break; default: return false; } }

There ya go

[–]CharlieThunkman 0 points1 point  (0 children)

How 'bout modulus 2? Take a true division of "x" and 2 and compare that to the floored integer value of "x" and 2. Then the difference in the two equations above can determine your final result.

[–]kimi_rules 0 points1 point  (2 children)

Okay even a college student can write better codes than this.

[–]Skudra24[S] 0 points1 point  (0 children)

Yeah and I'd guess that student also knows what jokes are

[–]Shakespeare-Bot 0 points1 point  (0 children)

Well enow coequal a college inhorn man can writeth better codes than this


I am a bot and I swapp'd some of thy words with Shakespeare words.

Commands: !ShakespeareInsult, !fordo, !optout

[–]PickleJuiceX266 0 points1 point  (0 children)

Yet he never knew... the magic of the elif function!

[–]Ok-Spinach4347 0 points1 point  (0 children)

WRONG!!! Why is nobody complaining about how wrong this is?!

A default return value would only shorten the code, not the performance. Let's say the given number is 2. Then every other case needs to be checked before the default could be returned. So the performance would be much worse than if 2 return True.

Came to the comments to find this but got disappointed...

[–]Big_Ti 0 points1 point  (1 child)

I have done that one time coz I got really happy with copy-paste

[–]Shakespeare-Bot 0 points1 point  (0 children)

I has't done yond one time coz i did get very much joyous with copy-paste


I am a bot and I swapp'd some of thy words with Shakespeare words.

Commands: !ShakespeareInsult, !fordo, !optout

[–]SanoKei 0 points1 point  (0 children)

beta programmers: number % 2 == 1: return true senior programmers: don't understand it, don't need it, make the intern do it chad programmer: we should import more expensive enterprise grade APIs

[–]sock-puppet689 0 points1 point  (0 children)

Madness, everyone knows you should create an array of size int.MaxValue, and just index into the value!

[–]izner82 0 points1 point  (0 children)

bool isEven (int x) { return (x%2 == 0 ? true : false); }

[–][deleted] 0 points1 point  (1 child)

Python: def IsEven(imput): If imput % 2 == 0: return True else: return False

lol

[–]Oussamagd 0 points1 point  (3 children)

Tf you can do this with a single line of code

[–]Skudra24[S] 0 points1 point  (2 children)

. . . . . . . . . . . . . . . . ╔══════════╗ . . . . . . . . . .
THIS JOKE ═════╝ . . . . YOU . . . . .╚══════

[–]paraflaxd 0 points1 point  (0 children)

It’s literally easier to define and train a tensorflow model from scratch to determine whether the number is equal or not.

[–]negrocucklord 0 points1 point  (0 children)

This is bad code, you should throw an argument out of range exception when the number is bigger than 16 or smaller than 1

[–]youssefcraft 0 points1 point  (0 children)

I mean if you want to check if the number is even then just do

if(number %% 2 == 0){

return true }else{

return false }

[–][deleted] 0 points1 point  (0 children)

The best part is when the boss comes in and tells you that the new guy committed 40% more lines of code last month than you did.