-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Binary Addition - Is this a triangle? - Two to One - Convert Number to Reversed Array of Digits - Your order, please!
- Loading branch information
Showing
11 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sierikov.codewars.kyu6 | ||
|
||
object YourOrderPlease { | ||
def order(str: String): String = { | ||
str.split(" ").sortBy(_.filter(_.isDigit)).mkString(" ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
object BinaryAddition { | ||
def addBinary(a: Int, b: Int): String = (a + b).toBinaryString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
object IsThisTriangle { | ||
|
||
def isTriangle(a: Int, b: Int, c: Int): Boolean = { | ||
a + b > c && a + c > b && b + c > a | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
object TwoToOne { | ||
def longest(s1: String, s2: String): String = (s1 ++ s2).distinct.sorted | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/scala/sierikov/codewars/kyu8/ConvertNumberToReversedArrayDigits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
object ConvertNumberToReversedArrayDigits { | ||
def digitize(n: Long): Seq[Int] = n.toString.reverse.map(_.asDigit) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/scala/sierikov/codewars/kyu6/YourOrderPleaseSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package sierikov.codewars.kyu6 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldBe | ||
|
||
class YourOrderPleaseSpec extends AnyFlatSpec { | ||
|
||
private val tests = List( | ||
("is2 Thi1s T4est 3a", "Thi1s is2 3a T4est"), | ||
("4of Fo1r pe6ople g3ood th5e the2", "Fo1r the2 g3ood 4of th5e pe6ople"), | ||
("", "") | ||
) | ||
|
||
tests.foreach { case (input, expected) => | ||
it should s"return $expected given $input" in { | ||
YourOrderPlease.order(input) shouldBe expected | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/scala/sierikov/codewars/kyu7/BinaryAdditionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldBe | ||
|
||
class BinaryAdditionSpec extends AnyFlatSpec { | ||
|
||
private val tests = List( | ||
(1, 1, "10"), | ||
(0, 1, "1"), | ||
(1, 0, "1"), | ||
(2, 2, "100"), | ||
(51, 12, "111111"), | ||
(0, 0, "0"), | ||
(100, 100, "11001000") | ||
) | ||
|
||
tests.foreach { case (a, b, expected) => | ||
it should s"return $expected for $a + $b" in { | ||
BinaryAddition.addBinary(a, b) shouldBe expected | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/scala/sierikov/codewars/kyu7/IsThisTriangleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldBe | ||
|
||
class IsThisTriangleSpec extends AnyFlatSpec { | ||
private val tests = Seq( | ||
(1, 2, 2, true), | ||
(7, 2, 2, false), | ||
(1, 2, 3, false), | ||
(1, 3, 2, false), | ||
(3, 1, 2, false), | ||
(5, 1, 2, false), | ||
(1, 2, 5, false), | ||
(2, 5, 1, false), | ||
(4, 2, 3, true), | ||
(5, 1, 5, true), | ||
(2, 2, 2, true), | ||
(-1, 2, 3, false), | ||
(1, -2, 3, false), | ||
(1, 2, -3, false), | ||
(0, 2, 3, false) | ||
) | ||
|
||
tests.foreach { case (a, b, c, expected) => | ||
it should s"return $expected when sides are ($a, $b, $c)" in { | ||
IsThisTriangle.isTriangle(a, b, c) shouldBe expected | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldBe | ||
|
||
class TwoToOneSpec extends AnyFlatSpec { | ||
|
||
private val tests = List( | ||
("aretheyhere", "yestheyarehere", "aehrsty"), | ||
("loopingisfunbutdangerous", "lessdangerousthancoding", "abcdefghilnoprstu"), | ||
("inmanylanguages", "theresapairoffunctions", "acefghilmnoprstuy") | ||
) | ||
|
||
tests.foreach { case (a, b, expected) => | ||
it should s"return $expected for ${a.take(5)}.. and ${b.take(5)}" in { | ||
TwoToOne.longest(a, b) shouldBe expected | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/scala/sierikov/codewars/kyu8/ConvertNumberToReversedArrayDigitsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldBe | ||
|
||
class ConvertNumberToReversedArrayDigitsSpec extends AnyFlatSpec { | ||
private val tests = List( | ||
(35231L, Seq(1, 3, 2, 5, 3)), | ||
(348597L, Seq(7, 9, 5, 8, 4, 3)), | ||
(0L, Seq(0)), | ||
(23582357L, Seq(7, 5, 3, 2, 8, 5, 3, 2)), | ||
(984764738L, Seq(8, 3, 7, 4, 6, 7, 4, 8, 9)), | ||
(45762893920L, Seq(0, 2, 9, 3, 9, 8, 2, 6, 7, 5, 4)), | ||
(548702838394L, Seq(4, 9, 3, 8, 3, 8, 2, 0, 7, 8, 4, 5)) | ||
) | ||
|
||
tests.foreach { case (input, expected) => | ||
it should s"return $expected for $input" in { | ||
ConvertNumberToReversedArrayDigits.digitize(input) shouldBe expected | ||
} | ||
} | ||
} |