Weekly Code Puzzle #1: Results

At Bloc, we kicked off our first weekly code puzzle this past week. For our first puzzle, we were challenged to complete Counting in the Amazon.

Here are the results.

Beauty Contest Award

For the most beautiful submission, Mike Jewett takes the cake:

def count_arara(n):  
    if (n == 0): return ""
    if (n == 1): return "anane"
    if (n == 2): return "adak"
    return "adak " + count_arara (n-2)

OMG RECURSION Award

For using the most recursive solution, Dave Paola takes home the OMG RECURSION award:

def count_arara(n)  
  if n == 1
    "anane"
  elsif n == 2
    "adak"
  else
    if (n % 2) == 0
      "#{count_arara(n-2)} #{count_arara(2)}"
    else
      "#{count_arara(n-1)} #{count_arara(1)}"
    end
  end
end  

"How little code can I write?" Award

For the least amount of code, Stan Idesis takes home the "How little code can I write?" this week:

def count_arara (n)  
  (Array.new((n / 2).floor, "adak") << ((n % 2) == 0 ? nil : "anane")).join(" ").rstrip
end  

"How much code can I write?" Award

Opposingly, Ben Neely blew us away with his object-oriented approach:

class Anane:  
  def __init__(self):
    self.anane = "anane"

  def __str__(self):
    return self.anane

class Adak:  
  def __init__(self):
    self.adak = "adak"

  def __str__(self):
    return self.adak

class Count:  
  def __init__(self):
    self.count_array = []

  def increment_by_two(self):
    self.count_array.append(Adak())

  def increment_by_one(self):
    self.count_array.append(Anane())

  def __str__(self):
      return ' '.join(map(str, self.count_array))



def count_arara(n):  
    count = Count()
    for i in range(0, n/2):
        count.increment_by_two()

    if n % 2 == 1:
        count.increment_by_one()

    return str(count)

"Who's on First?" Award

Last but not least, this week's code puzzle winner, for solving the puzzle first, goes to Jared Rader:

def count_arara(n)  
  return 'anane' if n == 1

  remainder = n % 2
  quotient = n / 2

  if remainder == 0 
    return ('adak ' * quotient).strip
  elsif n > 2
    return ('adak ' * quotient) + 'anane'
  end
end  

Jared walks home with the illustrious Trump Board Game:

Join us again next week! Thanks to Christian Schlensker for organizing.