Skip to content

Instantly share code, notes, and snippets.

View ebrugulec's full-sized avatar
💃

Ebru Gulec ebrugulec

💃
  • Berlin, Germany
View GitHub Profile
def makeString(r: Rational) =
r.numer + "/" + r.denom
class Rational(x:Int, y:Int)
{
def numer = x
def denom = y
def add(that: Rational) =
new Rational(
numer * that.denom + that.numer * denom,
denom * that.denom)
class Rational(x:Int, y:Int)
{
def numer = x
def denom = y
def add(that: Rational) =
new Rational(
numer * that.denom + that.numer * denom,
denom * that.denom)
package classes
object rationals {
val x = new Rational(1,2)
val y = new Rational(2,3)
x.add(y)
}
package classes
object rationals {
val x = new Rational(1,3)
val y = new Rational(5,7)
val z = new Rational(3,2)
x.sub(y).sub(z)
}
class Rational(x:Int, y:Int)
package classes
object rationals {
val x = new Rational(1,3)
val y = new Rational(5,7)
val z = new Rational(3,2)
y.add(y)
}
class Rational(x:Int, y:Int)
class Rational(x:Int, y:Int)
{
private def gcd(a: Int, b:Int): Int = if (b == 0) a else gcd(b, a%b)
private val g = gcd(x,y)
def numer = x / g
def denom = y / g
def less(that: Rational) = numer * that.denom < that.numer * denom
def add(that: Rational) =
package classes
object rationals {
val x = new Rational(1,3)
val y = new Rational(5,7)
val z = new Rational(3,2)
x.less(y)
x.max(y)
}
package classes
object rationals {
val x = new Rational(1,3)
val y = new Rational(5,7)
val z = new Rational(3,2)
x - y - z
x + y
y + y
object scratch{
new week3.Rational(1,2)
}