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 hackerrank | |
/** | |
* Created by Janis Rumnieks on 06/03/2016. | |
*/ | |
object GrowthDirection extends Enumeration { | |
val LEFT, STAY, RIGHT = Value | |
} | |
import GrowthDirection._ // kāpēc bez šī nevar ???????? |
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
/** | |
* Created by janisrumnieks on 07/03/2016. | |
* Hackerrank -> Functional Programming -> Recursion -> Filter Elements (10) | |
* https://www.hackerrank.com/challenges/filter-elements | |
*/ | |
object FilterElements /* rename this to Solution for Hackerrank */ extends App { | |
// helper functions | |
def countElementsR(occurrences: Int, list: List[Int]):List[Int] = list match { | |
case i::rest => if (rest.count(_ == i) >= occurrences-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
object FilterElements4 /* rename this to Solution for Hackerrank */ extends App { | |
// helper functions | |
def occurringElements(occur: Int, list: List[Int]):Set[Int] = { | |
list.groupBy(identity).mapValues( _.size ).filter{ case(key,value) => value >= occur }.keys.toSet | |
} | |
def occurringListElements (list: List[Int], occurringElements: Set[Int]): List[Int] = { | |
if (list == Nil || occurringElements.isEmpty) Nil | |
else { |
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
object FilterElements4 /* rename this to Solution for Hackerrank */ extends App { | |
// helper functions | |
def occurringElements(occur: Int, list: List[Int]):Set[Int] = { | |
list.groupBy(identity).mapValues( _.size ).filter{ case(key,value) => value >= occur }.keys.toSet | |
} | |
def filterListByOccurrences(list: List[Int], occurringElements: Set[Int]): List[Int] = { | |
if (list == Nil || occurringElements.isEmpty) Nil | |
else { |
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
/** | |
* Created by janisrumnieks on 07/03/2016. | |
* Hackerrank -> Functional Programming -> Recursion -> Filter Elements (10) | |
* https://www.hackerrank.com/challenges/filter-elements | |
*/ | |
object FilterElements4 /* rename this to Solution for Hackerrank */ extends App { | |
// helper functions | |
def occurringElements(occur: Int, list: List[Int]):Set[Int] = { | |
list.groupBy(identity).mapValues( _.size ).filter{ case(key,value) => value >= occur }.keys.toSet |
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
/** | |
* Created by janisrumnieks on 09/03/2016. | |
* https://www.hackerrank.com/challenges/sequence-full-of-colors | |
*/ | |
case class Colours (red:Int, green:Int, yellow:Int, blue:Int) { | |
def add (colour:Char) = colour match { | |
case 'R' => Colours(red+1, green, yellow, blue) | |
case 'G' => Colours(red, green+1, yellow, blue) | |
case 'Y' => Colours(red, green, yellow+1, blue) | |
case 'B' => Colours(red, green, yellow, blue+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
/** | |
* Created by janisrumnieks on 11/04/2016. | |
* https://www.hackerrank.com/challenges/super-digit | |
*/ | |
object SuperDigit extends App { | |
def sumDigits ( i: BigInt ): BigInt = i.toString.toList.map( _.toString.toInt ).foldLeft (0) ( _+_ ) | |
def doSuper ( i: BigInt ): BigInt = if (i>9) doSuper(sumDigits(i)) else i | |
val in = io.StdIn |
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
object MagicListMerger { | |
def listCartesian ( list: List[List[Int]] ): List[List[Int]] = ??? | |
val sourceList = | |
List( | |
List(1,2,3), | |
List(10,20), | |
List(100,200,300,400) |
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
def listCartesian[T] ( list: List[List[T]] ): List[List[T]] = { | |
def cartesianFor2 (list1: List[List[T]], list2: List[List[T]]): List[List[T]] = | |
for { | |
l1 <- list1 | |
l2 <- list2 | |
} yield l1 ++ l2 | |
list map ( sublist => sublist map ( (item: T) => List(item) ) ) reduce ( cartesianFor2 ) | |
} |
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 org.apache.spark.ml.Pipeline | |
import org.apache.spark.ml.classification.RandomForestClassifier | |
import org.apache.spark.ml.feature.{IndexToString, VectorIndexer, StringIndexer} | |
import org.apache.spark.sql.SparkSession | |
//import spark.implicits._ | |
/** | |
* Created by Janis Rumnieks on 15/08/2016. | |
*/ |
OlderNewer