Sha256: 5b2e3961651725c92ecbadf10b7c6b72c100f91bc3989cd250ac470ca47ffd7c

Contents?: true

Size: 1.04 KB

Versions: 142

Compression:

Stored size: 1.04 KB

Contents

import Plant.Plant

class Garden(children: List[String], plantsStr: String) {
  private val plantRows = plantsStr.split("\\r?\\n")
  private val chunkedRows = plantRows.map(s => s.grouped(2).toList).toList
  private val childPlants = chunkedRows.head.zip(chunkedRows.tail.head).map{case (s1, s2) => s1 + s2}
  private val sortedChildren = children.sorted
  private val gardenMap = sortedChildren.zip(childPlants).toMap

  def plants(child: String): List[Plant] = {
    val plantChars = gardenMap.getOrElse(child, "")
    plantChars.map(c => Plant.withName(c.toString)).toList
  }
}

object Garden {
  def defaultGarden(plantsStr: String): Garden =
    new Garden(List("Alice", "Bob", "Charlie", "David", "Eve", "Fred", "Ginny",
      "Harriet", "Ileana", "Joseph", "Kincaid", "Larry"), plantsStr)

  def apply(children: List[String], plantsStr: String): Garden = new Garden(children, plantsStr)
}

object Plant extends Enumeration  {
  type Plant = Value

  val Grass = Value("G")
  val Clover = Value("C")
  val Radishes = Value("R")
  val Violets = Value("V")
}

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.97 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.96 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.95 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.94 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.93 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.92 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.91 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.90 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.89 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.88 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.87 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.86 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.85 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.84 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.83 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.82 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.81 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.80 tracks/scala/exercises/kindergarten-garden/example.scala
trackler-2.2.1.79 tracks/scala/exercises/kindergarten-garden/example.scala