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
List(("A", 1), ("B", 2)).map(second) | |
def second[A, B](a: (A, B)) = (a._2, a._1) | |
def second2[A, B](a: (A, B)) = a match { | |
case (x, y) => (y, x) | |
} | |
def second3[A, B]: (A, B) => (B, A) = { case(a, b) => (b, a) } | |
def second4[A, B]: (A, B) => (B, A) = { case(a, b) => b -> a } |
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
SELECT | |
(data->'backofficeInformation'->'customerNumber')::int, | |
identities->'countryCode' | |
FROM customers | |
cross join lateral jsonb_array_elements(data->'personalInformation'->'identities') identities | |
WHERE (data->'backofficeInformation'->'customerNumber')::int = 900198808 | |
and (identities->>'isTaxCountry')::boolean = true | |
--same as |
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
val combinationsLetters = (for { | |
(i, idi) <- List("A", "B", "C", "D", "E").zipWithIndex | |
(j, idj) <- List("A", "B", "C", "D", "E").zipWithIndex.take(idi) | |
(k, _) <- List("A", "B", "C", "D", "E").zipWithIndex.take(idj) | |
} yield (i, j, k)) | |
val combinationsNumbers = (for { | |
(i, idi) <- List("1", "2", "3").zipWithIndex | |
(j, _) <- List("1", "2", "3").zipWithIndex.take(idi) | |
} yield (i, j)) |
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
(ns griffin.spec.journal-entry | |
(:require [clojure.spec.alpha :as s])) | |
(s/def ::id uuid?) | |
(s/def ::account-id uuid?) | |
(s/def ::type #{:credit :debit}) | |
(s/def ::amount pos-int?) | |
(s/def ::line-item (s/keys :req-un [::account-id ::amount ::type])) | |
(s/def ::line-items (s/coll-of ::line-item :min-count 2)) | |
(s/def ::journal-entry (s/keys :req-un [::id ::line-items])) |
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
object MissingNumber extends App { | |
def missingNumber(nums: Array[Int]): Int = { | |
val found = new Array[Int](nums.length) | |
for (n <- nums) { | |
if (n < nums.length) found(n) = 1 | |
} | |
val missing = found.indexOf(0) |
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
object MissingPositive extends App { | |
def missingPositive(nums: Array[Int]): Int = { | |
//val m1: Map[Int, Int] = (0 until nums.length).foldLeft(Map[Int, Int]())((m, i) => if (nums(i) > 0) m + (i -> 1) else m) | |
val found = scala.collection.mutable.Map[Int, Int]() | |
var min = Integer.MAX_VALUE |
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
object MissingPositive extends App { | |
def missingPositive(nums: Array[Int]): Int = { | |
val found: Map[Int, Int] = nums.foldLeft(Map[Int, Int]())((m, i) => if (i >= 0) m + (i -> 1) else m) | |
val min = nums | |
.filter(e => e > 0) | |
.foldLeft(Integer.MAX_VALUE)((m, i) => i.min(m)) | |
if (min >= 0) { | |
var count = 1 |
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
object CanSum extends App { | |
def canSum(n: Int, coins: Array[Int]): Boolean = { | |
if (n == 0) return true | |
for (coin <- coins) { | |
val rest = n - coin | |
if (rest >= 0) return canSum(rest, coins) | |
} |
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
object CanSum extends App { | |
def canSum(n: Int, coins: Array[Int]): Boolean = { | |
if (n == 0) return true | |
if (n < 0) return false | |
for (coin <- coins) { | |
val rest = n - coin | |
return canSum(rest, coins) |
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
object HowSum extends App { | |
def howSum(n: Int, coins: Array[Int]): Array[Int] = { | |
if (n == 0) return Array[Int]() | |
if (n < 0) return null | |
for (coin <- coins) { | |
val rest = n - coin | |
val ints = howSum(rest, coins) |