Skip to content
Snippets Groups Projects
Commit 6199a722 authored by Ali Sinan Köksal's avatar Ali Sinan Köksal
Browse files

calendar example with Scala 2.9

parent 9740e961
No related branches found
No related tags found
No related merge requests found
import cp.Definitions._ import cp.Definitions._
import cp.Terms._ import cp.Terms._
object Calendar extends Application { object Calendar extends App {
/* maybe more readable with leapDaysUntil's final val totalDays = 10593
final val originYear = 1980
val (year, day) = ((year : Int, day : Int) => totalDays == (year - originYear) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 -
((originYear - 1) / 4 - (originYear - 1) / 100 + (originYear - 1) / 400) + day &&
day > 0 && day <= 366).solve
println("Year : %d, day : %d" format (year, day))
/* alternate version with intermediate "leapDaysUntil" variables
def yearAndDay(totalDays : Int, originYear : Int) : (Int, Int) = { def yearAndDay(totalDays : Int, originYear : Int) : (Int, Int) = {
val (y, d, _, _) = ((year : Int, day : Int, lduYear : Int, lduOrigin : Int) => totalDays == (year - originYear) * 365 + lduYear - lduOrigin + day && val (y, d, _, _) = ((year : Int, day : Int, lduYear : Int, lduOrigin : Int) => totalDays == (year - originYear) * 365 + lduYear - lduOrigin + day &&
...@@ -13,17 +22,7 @@ object Calendar extends Application { ...@@ -13,17 +22,7 @@ object Calendar extends Application {
(y, d) (y, d)
} }
println(yearAndDay(10593, 1980))
*/ */
final val totalDays = 10593
final val originYear = 1980
val (year, day) = ((year : Int, day : Int) => totalDays == (year - originYear) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 -
((originYear - 1) / 4 - (originYear - 1) / 100 + (originYear - 1) / 400) + day &&
day > 0 && day <= 366).solve
println("Year : %d, day : %d" format (year, day))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment