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
package com.recbuc.receipts | |
import scala.annotation.tailrec | |
object SecondMinimum { | |
def main(args: Array[String]): Unit = { | |
val regular = List(5, 3, 2, 5, 1, 3, 1, -1, 2, -1, 5) // expected -1 | |
val sorted = regular.sorted // expected -1 | |
val distinct = sorted.distinct //expected 1 | |
val reverse = distinct.reverse //expected 1 |
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.ListBuffer | |
import scala.io.Source | |
import scala.util.Random | |
val sourceLines = Source.fromURL("http://www.coverfire.com/files/quotes.txt","UTF-8").getLines() | |
val quotes = new ListBuffer[String] | |
sourceLines.reduceLeft((a,b) => if (b.nonEmpty) a + " " + b else {quotes.+=(a.trim); ""}) | |
val randomQuote = quotes.apply(Random.nextInt(quotes.size)) |