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
{:hash "#️⃣" | |
:keycap_star "*️⃣" | |
:zero "0️⃣" | |
:one "1️⃣" | |
:two "2️⃣" | |
:three "3️⃣" | |
:four "4️⃣" | |
:five "5️⃣" | |
:six "6️⃣" | |
:seven "7️⃣" |
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 secrets | |
import string | |
alphabet = string.ascii_letters + string.digits | |
print(''.join(secrets.choice(alphabet) for i in range(16))) |
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 newton | |
[f fprime tol max-iteration x] | |
(if (<= max-iteration 0) | |
nil | |
(let [y (f x) | |
yprime (fprime x) | |
x-new (- x (/ y yprime))] | |
(if (<= (Math/abs(- x-new x)) (* tol (Math/abs x-new))) | |
x-new | |
(newton f fprime tol (dec max-iteration) x-new))))) |
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
package week6 | |
import scala.io.Source | |
object mnemonics { | |
val in = Source.fromURL("https://raw.github.com/jpalmour/progfun/master/forcomp/src/main/resources/forcomp/linuxwords.txt") | |
val words = in.getLines.toList filter (word => word forall (chr => chr.isLetter)) | |
val mnem = Map( |
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
(def words | |
(clojure.string/split-lines (slurp "https://lamp.epfl.ch/files/content/sites/lamp/files/teaching/progfun/linuxwords.txt"))) | |
(def mnem | |
{\2 "ABC" \3 "DEF" \4 "GHI" \5 "JKL" \6 "MNO" \7 "PQRS" \8 "TUV" \9 "WXYZ"}) | |
(def char-code | |
(into {} (for [[k vs] mnem | |
v vs] | |
[v k]))) |
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 tri? | |
[n] | |
(= (last (take-while #(>= n %) tri-numbers)) n)) | |
(tri? 10) | |
;; true | |
(tri? 11) | |
;; false |
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
def is_tri(n): | |
for tri in tri_gen(): | |
if tri > n: | |
return False | |
elif tri == n: | |
return True | |
else: | |
continue | |
is_tri(10) |
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 number-generator | |
([] (number-generator 0)) | |
([i] (lazy-seq (cons i | |
(number-generator (inc i)))))) | |
(def numbers (number-generator)) | |
(take 6 numbers) | |
;; (0 1 2 3 4 5) |
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 tri-gen | |
([] (tri-gen 0 1)) | |
([tri-num n] | |
(lazy-seq (cons tri-num | |
(tri-gen (+ tri-num n) (inc n)))))) | |
(def tri-numbers (tri-gen)) | |
(take 7 tri-numbers) | |
;; (0 1 3 6 10 15 21) |
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
def tri_gen(): | |
tri_num = 0 | |
n = 1 | |
while True: | |
yield tri_num | |
tri_num += n | |
n += 1 | |
tri_numbers = tri_gen() | |
next(tri_numbers) # 0 |
NewerOlder