Skip to content

Instantly share code, notes, and snippets.

@frank-leap
Last active August 29, 2015 14:19
Show Gist options
  • Save frank-leap/3b87b6ff2e5a8afc9854 to your computer and use it in GitHub Desktop.
Save frank-leap/3b87b6ff2e5a8afc9854 to your computer and use it in GitHub Desktop.
s4di - Chapter 1 - Exercises
package chapter1
import math._
import math.BigInt._
import util._
object ExercisesCh1 {
3 //> res0: Int(3) = 3
pow(sqrt(3),2) //> res1: Double = 2.9999999999999996
"crazy" * 3 //> res2: String = crazycrazycrazy
10 max 2 //> res3: Int = 10
BigInt(2) pow 1024 //> res4: scala.math.BigInt = 17976931348623159077293051907890247336179769789423
//| 0657273430081157732675805500963132708477322407536021120113879871393357658789
//| 7688144166224928474306394741243777678934248654852763022196012460941194530829
//| 5208500576883815068234246288147391311054082723716335051068458629823994724593
//| 8479716304835356329624224137216
val prime = probablePrime(100, Random) //> prime : scala.math.BigInt = 914190763102492330116727428763
prime toString 36 //> res5: String = 2gmren6i782dxdji7f6j
"Hello".head //> res6: Char = H
"Hello" take 1 //> res7: String = H
"Hello".last //> res8: Char = o
"Hello" takeRight 1 //> res9: String = o
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment