Advertisement
roman_gemini

Common Fractions

Jun 22nd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.27 KB | None | 0 0
  1.   def isFraction(a: Int, b: Int): Boolean = a % b == 0
  2.  
  3.   def fractions(a: Int): List[Int] =
  4.     (1 until a).filter(isFraction(a, _)).toList
  5.  
  6.   def commonFractions(a: Int*): List[Int] =
  7.     a.map(fractions).reduce(_ intersect _)
  8.  
  9.   println(commonFractions(100, 250, 125))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement