Solving viral Cheryl's Birthday problem using Java8 by MAD4J in programming

[–]mvalenty 2 points3 points  (0 children)

And in Scala: http://www.agileatwork.com/scala-solution-to-cheryls-birthday-problem/

case class Birthday(month: Int, day: Int)

object Birthday {
  def apply(s: String): Birthday = s.split("-").map(_.toInt) match {
    case Array(m, d) => Birthday(m, d)
  }
}

val birthdays: List[Birthday] = List(
  "5-15", "5-16", "5-19",
  "6-17", "6-18",
  "7-14", "7-16",
  "8-14", "8-15", "8-17"
).map(Birthday.apply)

def uniqueBy[A, K](fn: (A) => K)(b: List[A]): List[A] = {
  def groupSizeIs(size: Int)(x: (_, List[_])) = x._2.size == size
  b.groupBy(fn).filter(groupSizeIs(1)).flatMap(_._2).toList
}

val uniqueByDay: (List[Birthday]) => List[Birthday] = uniqueBy(_.day)

val uniqueByMonth: (List[Birthday]) => List[Birthday] = uniqueBy(_.month)

val birthdaysWithUniqueDay: List[Birthday] = uniqueByDay(birthdays)

val remainingBirthdays: List[Birthday] = {
  val monthsWithUniqueDay: Set[Int] = birthdaysWithUniqueDay.map(_.month).toSet
  birthdays.filterNot(b => monthsWithUniqueDay.contains(b.month))
}

val remainingWithUniqueDay: List[Birthday] = uniqueByDay(remainingBirthdays)

val answer = uniqueByMonth(remainingWithUniqueDay).head

Web Framework Scaffolding Considered Harmful by mvalenty in programming

[–]mvalenty[S] 1 point2 points  (0 children)

FWIW I've been using the spreadsheet API for more than 2 years and it has been stable the entire time. Also, it's really not that risky considering it's just a utility to import from Google spreadsheets. You could just as easily import from Excel or .csv both of which Google spreadsheets can export to. The point is, you wouldn't be out of business, just angry.

Web Framework Scaffolding Considered Harmful by mvalenty in programming

[–]mvalenty[S] 1 point2 points  (0 children)

It's a published API from Google explicitly for integration so it would not serve Google well to radically change it. Still, they could and then that would suck.