88
IliasIB
2y

Have another one of these

Comments
  • 15
    func isEven (n int) bool {
    if n == 0 {
    return true
    } else if n == 1 {
    return false
    } else {
    return isEven(n-2)
    }
    Some basic recursive
  • 1
    @Lahsen2016 thanks...maybe
  • 1
    public bool IsEven(int n) {
    while(n < int.MaxValue){
    n++
    }
    if(n == int.MaxValue){
    return false;
    }
    else{
    return IsEven(n);
    }
    }

    Best algo ever :3
    *I'll see my self out*
  • 2
    @Lahsen2016 dude do you 'even' Ruby

    # a is a number
    a.even? #returns true if isEven
  • 1
    Using recursive functions for something that can easily be represented by a simple Mathematical function? Seems legit. 2 legit 2 quit.
  • 32
    public boolean isEven(int i){
    return true;
    //TODO: fix 50% precision
    }
  • 2
    @gitpush
    Isn't this just an infinite loop?
  • 0
    @okkimus not really but it will take ages to finish until n is max int Val then it just returned false :p
  • 2
    @BindView you're half way there already
  • 4
    oh wait i got a good one

    boolean isEven(int i){
    boolean ret;
    for(int j=0;j<i;j++){
    ret=j%2==0;
    }
    return !ret;
    }
  • 4
    @gitpush
    Oh wait, it's not infinite loop, it just return false each time.

    While loop in the start will just increment n till it's int.MaxValue.

    Then the if-statement is true and will return false.

    Or am I missing something? :D
  • 1
    @BindView
    This solution is my absolute favorite. Can I use this in my own projects?
  • 1
    @okkimus sure, MIT license
  • 1
    @okkimus nop you are correct, I just wrote it as a joke for the best algo existed lol
  • 2
    @gitpush
    Sorry mate :D

    These obfuscated algorithms are so fun to see how programmer has thought it out :)
  • 1
    @Lahsen2016 I can bet that I can 'C' sharper than you :D

    Can someone order me a taxi for one?
  • 2
    @Lahsen2016 I will garbage collect yo ass.

    How would developers 1v1 just out of curiosity? I think a site like omegle but just a quickfire coding challenge would be cool. A simple task kind of thing.
  • 0
    Is that production code?
  • 1
    Jesus.. hate to be cruel if this is no joke, but it is horrible!

    Hope you follow @Lahsen2016's suggestion and just use the modulus operator...
  • 1
    @IliasIB But it is working 😏 ... not performant, but working.

    Also a nice aproach for a challenge: Determine the if an integer is even without Libraries (Built in / external) or the Modulus-Operator.

    For that case, it's a very smart way of solving it.
  • 2
    def isEven(n):
    return n & 0x0001 == 1
  • 1
    That's amazing.
  • 0
    @Lahsen2016 have an idea, already done. Of course xD.
  • 3
    @Pointer is it not ==0?
  • 1
    @Ryefalk Yeah, my bad, hahaha
  • 1
    hey @gitpush, wont it give you an error for increment past max value
  • 1
    @gitpush in fact, I just tested and if you increment past max value, it turns to min value, so your code will show a StackOverflow error
  • 1
    public bool IsEven(int n) {

    if(n == 2) {
    return true;
    } else if(n == 4) {
    return true;
    } else if(n==6) {
    return true;
    } else if(n==8) {
    return true;
    } ...... {

    } else if(n==(int.MaxValue - 1)) {
    return true;
    }

    return false;
    }
  • 2
    @theuser this is possible in Lang’s with eval() or dynamic code execution.

    I doubt it would fucking run but it would be a beautifully horrific monster.
  • 2
    @vhoyer the main goal of my algo is to crash the system \m/ :P
Add Comment