Ad
Fundamentals

Given an integer n return whether or not the integer is even. Your code may not contain any numbers, and it may contain no more than a single space (' ') character.

E.g.:

is_even(2) # True
is_even(5) # False
is_even(123456) # True
is_even(654321) # False
Code
Diff
  • #is_even=lambda n:not(n%(ord('ࠀ')>>ord('\n'))) # left in the single space here
    # this also works with more regexes:
    def is_even(n):
        return not(n%(ord('ࠀ')>>ord('\n')))
    • is_even=lambda*z:not(z[ord('`')-ord('`')]%(ord('a')//ord('!')))
    • #is_even=lambda n:not(n%(ord('ࠀ')>>ord('\n'))) # left in the single space here
    • # this also works with more regexes:
    • def is_even(n):
    • return not(n%(ord('ࠀ')>>ord('\n')))
Fundamentals

Given an integer n return whether or not the integer is even. Your code may not contain any numbers, and it may contain no more than a single space (' ') character.

E.g.:

is_even(2) # True
is_even(5) # False
is_even(123456) # True
is_even(654321) # False
Code
Diff
  • is_even=lambda n:not(n%(ord('ࠀ')>>ord('\n'))) # I can't get out the final space!
    • is_even(){__asm("mov%rdi,%rax\nshr%rax\nshl%rax\ncmp%rax,%rdi\nsete%al\nleave\nret");}
    • is_even=lambda n:not(n%(ord('ࠀ')>>ord('\n'))) # I can't get out the final space!
Fundamentals
Numbers
Data Types
Booleans

Given an integer n, create a function that returns true if that number is even, false if that number is odd.

Code
Diff
  • bool isEven(int n)
    {
      return n % 2 == 0;
    }
    • function isEven(input) {
    • return true;
    • bool isEven(int n)
    • {
    • return n % 2 == 0;
    • }
Code
Diff
  • public class Kata {
      public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
        // Implement the urinal problem, described as "given x number of people walking 
        // into a bathroom that contains y number of urinals, describe the optimate
        // placement of people so that none is standing next to the other"
        // In this case, the urinals are represented by a boolean array with 
        // true representing a person at a urinal, and false meaning the urinal is empty
        
        int pointer = 0;
        for (int i = numOfPeople; i > 0; i--) {
          if (i == 1) { urinals[urinals.length-1] = true; }
          else {
            urinals[pointer] = true;
            pointer += 1 + (urinals.length - pointer) / i;
          }
        }
        return urinals;
      }
    }
    • public class Kata {
    • public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
    • // Implement the urinal problem, described as "given x number of people walking
    • // into a bathroom that contains y number of urinals, describe the optimate
    • // placement of people so that none is standing next to the other"
    • // In this case, the urinals are represented by a boolean array with
    • // true representing a person at a urinal, and false meaning the urinal is empty
    • if (urinals.length < numOfPeople) {
    • throw new RuntimeException("Cursed input data.");
    • }
    • int peopleRemain = numOfPeople;
    • int peoplePlacePointer = 0;
    • boolean[] result = urinals;
    • while(peopleRemain > 0) {
    • if (peopleRemain == 1) {
    • // only one person is not at the urinal
    • // we'll place him to far corner of the toilet :)
    • result[urinals.length - 1] = true;
    • peopleRemain--;
    • } else {
    • // if more than one person is not at the urinal
    • // place first of them at the urinal with number peoplePlacePointer
    • result[peoplePlacePointer] = true;
    • // then increments the peoplePlacePoiner by value
    • // which depends on empty urinals count from rigth side of peoplePlacePointer and remain people count
    • // the point is to distribute resulting empty urinals so that almost equals spaces will be between people
    • peoplePlacePointer += 1 + (urinals.length - peoplePlacePointer) / peopleRemain;
    • // one less left
    • peopleRemain--;
    • int pointer = 0;
    • for (int i = numOfPeople; i > 0; i--) {
    • if (i == 1) { urinals[urinals.length-1] = true; }
    • else {
    • urinals[pointer] = true;
    • pointer += 1 + (urinals.length - pointer) / i;
    • }
    • }
    • return result;
    • return urinals;
    • }
    • }
Code
Diff
  • # changing because the other guy beat me to it
    #is_even = lambda x: not x % 2
    
    is_even = lambda x: bool(x%2-1)
    • is_even = lambda x: 1 + x&1
    • is_even = lambda e: e%2==0
    • # changing because the other guy beat me to it
    • #is_even = lambda x: not x % 2
    • is_even = lambda x: bool(x%2-1)