Skip to content

Instantly share code, notes, and snippets.

@tabdelmaguid
Created February 23, 2012 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabdelmaguid/1890672 to your computer and use it in GitHub Desktop.
Save tabdelmaguid/1890672 to your computer and use it in GitHub Desktop.
Farmer's weights
import scala.math._
def stone_weights(w: Int) : List[Int] = w match {
case 1 => List(1)
case _ =>
val one_third : Int = ceil((w-1).toDouble/3).toInt
w - one_third :: stone_weights (one_third)
}
println(stone_weights(40));
@scsibug
Copy link

scsibug commented Feb 24, 2012

Very elegant, awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment