Sha256: 240e1a3bafc35fdae5e4645c480adb228ae5c9cf2a3be78404141577741ee275

Contents?: true

Size: 723 Bytes

Versions: 203

Compression:

Stored size: 723 Bytes

Contents

import TriangleType.TriangleType

class Triangle(a: Int, b: Int, c: Int) {
  def triangleType: TriangleType =
    if (List(a, b, c).count(_ <= 0) > 0 || !checkInequality) TriangleType.Illogical
    else if (a == b && b == c) TriangleType.Equilateral
    else if (a == b || a == c || b == c) TriangleType.Isosceles
    else TriangleType.Scalene

  private def checkInequality = a + b >= c  &&  a + c >= b && b + c >= a
}

object Triangle {
  def apply(a: Int, b: Int, c: Int) = new Triangle(a, b, c)
}

object TriangleType extends Enumeration {
  type TriangleType = Value

  val Equilateral = Value("Equilateral")
  val Isosceles = Value("Isosceles")
  val Scalene = Value("Scalene")
  val Illogical = Value("Illogical")
}

Version data entries

203 entries across 203 versions & 1 rubygems

Version Path
trackler-2.1.0.48 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.47 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.46 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.45 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.44 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.43 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.42 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.41 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.40 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.39 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.38 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.37 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.36 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.34 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.33 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.32 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.31 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.30 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.29 tracks/scala/exercises/triangle/example.scala
trackler-2.1.0.28 tracks/scala/exercises/triangle/example.scala