• lowleveldata@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    Good solution! I think you should show the last 3 lines that makes it work tho. FIFY:

    private bool IsEven(int number){
        if (number == 1) return false;
        else if (number == 2) return true;
        else if (number == 0) return true;
        else if (number == -1) return false;
        else return !IsEven(abs(number) - 1);
    }
    
  • Buttons@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I’ve actually seen this type of code produced by a human-being who was trying to write good code. It was one of the students in my introduction to programming class in university, we had to write a function that squared a number or something, and he had written hundreds of lines of if-statements. Sometimes you just use what you know to complete an assignment I guess 🤷

    • bufordt@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      I did something similar for a programming competition once because I couldn’t remember the c64 basic function to return string length.

      Once I got home I rewrote it properly because it bugged me so badly. LEN(string variable) was the command. Stupid!