This file contains hidden or 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
doubleOddElements :: [Int] -> [Int] | |
doubleOddElements [] = [] | |
doubleOddElements (x: []) = [x] | |
doubleOddElements (x0 : x1 : xs) = (x0 : x1 * 2 : doubleOddElements xs) | |
digits :: Integral x => x -> [x] | |
digits 0 = [] | |
digits x = digits (x `div` 10) ++ [x `mod` 10] | |
isLuhn :: Int -> Bool |
This file contains hidden or 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
trait Cartesian[T] { | |
def cartesianProduct(input: List[Set[T]]): Set[List[T]] | |
} |
This file contains hidden or 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/filter-elements */ | |
object Solution extends App { | |
def filterElements(list: List[Int], times: Int, processed: Set[Int] = Set.empty): List[Int] = { | |
if (list.isEmpty) Nil | |
else { | |
val elem = list.head | |
val x = if (processed.contains(elem)) { | |
Nil // already seen | |
} else { | |
if (list.count(_ == elem) >= times) List(elem) // right count |