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
| #!/usr/bin/env bash | |
| echo "Install all AppStore Apps manuallyfirst!" | |
| read -p "Press any key to continue... " -n1 -s | |
| echo '\n' | |
| echo "Install xcode-select --install if not done yet!" | |
| read -p "Press any key to continue... " -n1 -s | |
| echo '\n' |
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
| import org.openjdk.jmh.annotations.*; | |
| import org.openjdk.jmh.infra.Blackhole; | |
| import java.io.BufferedReader; | |
| import java.io.InputStream; | |
| import java.io.InputStreamReader; | |
| import java.util.concurrent.TimeUnit; | |
| @BenchmarkMode(Mode.AverageTime) | |
| @OutputTimeUnit(TimeUnit.NANOSECONDS) |
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
| public class Anagram { | |
| private static final long [] FIRST_26_PRIMES = new long [] { | |
| 2, | |
| 3, | |
| 5, | |
| 7, | |
| 11, | |
| 13, | |
| 17, |
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
| ;; x-1 y-1 | x y-1 | x+1 y-1 | |
| ;; x-1 y | x y | x+1 y | |
| ;; x-1 y+1 | x y+1 | x+1 y+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
| (-> (empty-board 9 9 10) | |
| (init [1 1]) | |
| (flag [0 1]) | |
| (explore [0 2]) | |
| (display)) |
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
| (defn init | |
| [board start-idx] | |
| (if-not (started? board) | |
| (init-game board start-idx) | |
| board)) | |
| (defn explore | |
| [board idx] | |
| (if-not (or (pos? (nth (:flags board) idx)) | |
| (pos? (nth (:explored board) idx)) |
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
| (defn- init-game | |
| [board start-idx] | |
| (explore-cell | |
| (-> (place-mines board start-idx) | |
| (place-warnings)) | |
| start-idx)) |
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
| (defn- explore-cell | |
| ([board idx] | |
| (explore-cell board #{} #{idx})) | |
| ([board explored remaining] | |
| (if (empty? remaining) | |
| board | |
| (let [curr (first remaining) | |
| explored (conj explored curr) | |
| remaining (disj remaining curr) | |
| board (set-explored board curr) |
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
| (defn- nice-neighbours | |
| [board idx] | |
| (let [mines (:mines board) | |
| explored (:explored board) | |
| neighbours (neighbours board idx) | |
| is-set? (fn [[k v]] (pos? v))] | |
| (when | |
| (not-any? is-set? (select-keys mines neighbours)) | |
| (->> (select-keys explored neighbours) | |
| (remove is-set?) |
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
| (defn- place-warnings | |
| [board] | |
| (->> (keep-indexed #(if (pos? %2) %1) (:mines board)) | |
| (mapcat (partial neighbours board)) | |
| (frequencies) | |
| (reduce-kv set-warning board))) |
NewerOlder