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
let positions x (arr: 'a []) = | |
let n = arr.Length - 1 | |
let idxs = [|0..n|] | |
Array.zip idxs arr | |
|> Array.filter (fun (_, v) -> v = x) | |
|> Array.map (fun (idx, _) -> idx) | |
positions 'b' [|'a';'b';'a';'a';'b'|] | |
// [|1; 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
(fn best-hand | |
[hand] | |
(let [ranks (map second hand) | |
suits (map first hand) | |
rank-freqs (sort (vals (frequencies ranks)))] | |
(letfn [(flush? [hand] | |
(apply = suits)) | |
(straight? [hand] | |
(let [straight-hands (set (map set (partition 5 1 [\A \2 \3 \4 \5 | |
\6 \7 \8 \9 \T |
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 vowels | |
#{\a \e \i \o \u}) | |
(defn count-vowels | |
[s] | |
(count (keep vowels (.toLowerCase s)))) |
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
{:starters | |
(["Marcus" 17] | |
["Baba" 16] | |
["Sami" 14] | |
["Tuomas" 14] | |
["Kabu" 14] | |
["Jesse" 11] | |
["Lydä" 9] | |
["Jonde" 9] | |
["Jebu" 9] |
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
set nocompatible | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim/ | |
call vundle#rc() | |
Plugin 'gmarik/Vundle.vim' | |
Bundle 'tpope/vim-classpath' | |
Bundle 'tpope/vim-leiningen' | |
Bundle 'tpope/vim-projectionist' |
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
factorial = { 1 } | |
setmetatable(factorial, { __index = function(table, key) | |
table[key] = table[key - 1] * key | |
return table[key] | |
end, __call = function(table, n) | |
for i = 1, n do | |
print(table[i]) | |
end | |
end }) |
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
private ExpectedCondition<Boolean> element(final By findCondition) { | |
return new ExpectedCondition<Boolean>() { | |
@Override | |
public Boolean apply(WebDriver from) { | |
RenderedWebElement element = (RenderedWebElement) | |
driver.findElement(findCondition); | |
return element.isDisplayed(); | |
} | |
}; | |
} |
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
(defn char-counter [str] | |
(reduce | |
(fn [m c] | |
(assoc m c (inc (get m c 0)))) | |
{} | |
str)) |
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
val n: Option[Int] = None | |
val res = n.map(_ + 4).map(_ + 100) | |
res.getOrElse(0) // => 0 | |
val n: Option[Int] = Some(10) | |
val res = n.map(_ + 4).map(_ + 100) | |
res.getOrElse(0) // => 114 |
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
(letfn [(factorial [n i] | |
(if (> i 1) | |
(factorial | |
(* n i) | |
(dec i)) | |
n))] | |
(factorial 1 5)) |
OlderNewer