Skip to content

@tabdelmaguid /farmers-weights.scala
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

Very elegant, awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.