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
import java.io._ | |
import java.math._ | |
import java.security._ | |
import java.text._ | |
import java.util._ | |
import java.util.concurrent._ | |
import java.util.function._ | |
import java.util.regex._ | |
import java.util.stream._ |
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
import java.io._ | |
import java.math._ | |
import java.security._ | |
import java.text._ | |
import java.util._ | |
import java.util.concurrent._ | |
import java.util.function._ | |
import java.util.regex._ | |
import java.util.stream._ |
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
import java.io._ | |
import java.math._ | |
import java.security._ | |
import java.text._ | |
import java.util._ | |
import java.util.concurrent._ | |
import java.util.function._ | |
import java.util.regex._ | |
import java.util.stream._ |
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
// https://www.hackerrank.com/challenges/the-birthday-bar/problem | |
import scala.io._ | |
import scala.annotation.tailrec | |
object Solution { | |
// Complete the birthday function below. | |
def birthday(s: Array[Int], d: Int, m: Int): Int = { |
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
import scala.io._ | |
trait Date { | |
def toDDMMYYYY: String = ??? | |
} | |
case class ConcreteDate(day: Int, month: String, year: Int) extends Date { | |
override def toDDMMYYYY = s"$day.$month.$year" | |
} | |
case object EmptyDate extends Date |
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
// https://www.hackerrank.com/challenges/migratory-birds/problem | |
// | |
// Input Output | |
// +-----------------------+----------+ | |
// | 6 | 4 | | |
// | 1 4 4 4 5 3 | | | |
// +-----------------------+----------+ | |
// | 11 | 3 | | |
// | 1 2 3 4 5 4 3 2 1 3 4 | | | |
// +-----------------------+----------+ |
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
import scala.collection.mutable.Stack | |
class Peg(val disks: Stack[Int], val name: String) | |
def solveHanoi_1(n: Int): Unit = { | |
val A = Peg(Stack[Int](1 to n: _*), "A") | |
val B = Peg(Stack[Int](), "B") | |
val C = Peg(Stack[Int](), "C") | |
val evenSeq = Seq((A, B), (A, C), (B, C)) |
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
// Purpose: show scala basic features in terms of grammar, readability, shortness, easy translation from human to machine | |
// How many of you know a programming language? | |
// Opening with the fizzbuzz | |
for (i <- Range.inclusive(1, 16)) { | |
println( | |
if (i % 3 == 0 && i % 5 == 0) "FizzBuzz" | |
else if (i % 3 == 0) "Fizz" | |
else if (i % 5 == 0) "Buzz" | |
else i |
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
type Boolian = (Any, Any) => Any | |
val troo = (a: Any, _: Any) => a | |
val fols = (_: Any, b: Any) => b | |
// Logic | |
val not = (b: Boolian) => b(fols, troo) | |
not(troo) == fols |
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
// How to Write Controllable Futures in Scala | Rock the JVM | |
// https://www.youtube.com/watch?v=72kurKY7fX8 | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Promise | |
val aFuture = Future { | |
42 | |
} |