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
(ns mapsexample.core) | |
;; Version 1: | |
;; Given a list of items, loop through them, adding one at a time with `assoc`. | |
(defn build-map-1 [items] | |
(loop [n 0 ;; index to loop through the items | |
my-map (hash-map)] ;; or just {} for an empty hash-map | |
(if (>= n (count items)) | |
my-map |
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
(ns demo.bruteforce) | |
(defn sha-512 [s] | |
(let [digester (java.security.MessageDigest/getInstance "SHA-512")] | |
(->> (.digest digester (.getBytes s)) | |
(map (partial format "%02x")) | |
(apply str)))) | |
(def charset | |
(into [""] (map str "abcdefghijklmnopqrstuvwxyz"))) |
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
(ns demo.main | |
(:import [goog.crypt Sha512] | |
[goog.string format]) | |
(:require [goog.crypt])) | |
(defn sha-512 [s] | |
(let [digester (doto (goog.crypt.Sha512.) .reset (.update s))] | |
(->> (.digest digester) goog.crypt.byteArrayToHex))) | |
(defn four-digits [n] |
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
(ns programando.core) | |
(def primes [2 3 5 7 11 13 17 19 23 29]) | |
(defn index-to-letter [i] | |
(char (+ i (int \a) -1))) | |
(defn factors [n fs ps] | |
(if (> n 1) | |
(let [p (first ps)] |
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
denis@carbon:~/Projects/janet/littleserver$ janet -v | |
1.6.1-dev-0457966 | |
denis@carbon:~/Projects/janet/littleserver$ jpm --verbose build | |
generating executable c source... | |
found native /usr/local/lib/janet/circlet.so... | |
found native /usr/local/lib/janet/json.so... | |
compiling and linking build/lserve... | |
cc -std=c99 -Wall -Wextra -I/usr/local/include/janet -O2 -o build/lserve build/lserve.c /usr/local/lib/janet/circlet.a /usr/local/lib/janet/json.a /usr/local/bin/../lib/libjanet.a -lm -ldl -lrt -lpthread | |
/usr/local/lib/janet/json.a(json.static.o): In function `_janet_mod_config': |
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
(ns capicuas.core) | |
(defn reverso [res n] | |
(if (zero? n) | |
res | |
(recur (+ (* 10 res) (rem n 10)) (quot n 10)))) | |
(defn palin? [n] | |
(= n (reverso 0 n))) |
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 reverso(n): | |
res = 0 | |
while (n > 0): | |
res = (res * 10) + (n % 10) | |
n = n//10 | |
return res | |
def palin(n): | |
return n == reverso(n) |
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
(ns capicuas.part2) | |
(defn reverso [res n] | |
(if (zero? n) | |
res | |
(recur (+' (* 10 res) (rem n 10)) (quot n 10)))) | |
(defn not-palin? [n] | |
(not= n (reverso 0 n))) |
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
(ns grancapicua.core) | |
(defn reverso [res n] | |
(if (zero? n) | |
res | |
(recur (+ (* 10 res) (rem n 10)) (quot n 10)))) | |
(defn capicua? [n] | |
(= n (reverso 0 n))) |
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
;; An example InputStream made of 128 bytes: | |
(defn bytes-is [] | |
(java.io.ByteArrayInputStream. (into-array Byte/TYPE (range 128)))) | |
(defn b64encode [s] | |
(String. (.encode (java.util.Base64/getEncoder) (.getBytes s)))) | |
;; Now we read the input stream *in memory* (with slurp) and encode as base64: | |
(-> (bytes-is) slurp b64encode) | |
;; => "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJC...n8=" |