Skip to content

Instantly share code, notes, and snippets.

View alexispurslane's full-sized avatar

Alexis Purslane alexispurslane

View GitHub Profile
@alexispurslane
alexispurslane / make-error-now.rkt
Last active September 25, 2015 23:19
My neural network code.
(define td '((((1) (1)) ((0))) (((1) (0)) ((1))) (((0) (1)) ((1))) (((0) (0)) ((1)))))
(SGD (build-network '(2 3 1)) td 30 2 3.0 td)
(ns project-euler.problem11)
(defn walk [grid x y & {:keys [predx predy]
:or {predx identity
predy identity}}]
(loop [cx x, cy y, lst []]
(if (nil? (get-in grid [cx cy]))
lst
(let [nx (predx cx)
ny (predy cy)
(ns project-euler.fast-problem12)
(defn fast-divisors [n]
(if (zero? n)
0
(loop [x 1, l 1]
(if (= x (int (Math/sqrt (inc n))))
l
(recur (inc x) (if (zero? (rem n x))
(+ l 2)
(ns project-euler.problem12)
;; See fast-problem12.clj for an optimized version of this code that will run in a reasonable amount of time.
(defn divisors [n]
(for [x (range 1 (inc n)) :when (zero? (rem n x))] x))
(defn problem12 [divs]
(loop [triangle 0, n 1]
(if (> (count (divisors triangle)) divs)
(ns project-euler.problem13)
;; I get the feeling this was supposed to be hard becouse you'd have to optimize, but Clojure is just to awesome for that.
;; The capatcha code was harder to figure out...
(defn problem13 [nums]
(subs (str (reduce + nums)) 0 10))
(defn run-problem []
(problem13 [37107287533902102798797998220837590246510135740250 ;; SUCH WOW. MUCH NUMBER.
(ns project-euler.fast-problem14)
;; I've decided to stop posting the slow versions of these. Their effectivly useless at this point except for me showing off.
(defn chain-step [n]
(cond
(even? n) (/ n 2)
(odd? n) (inc (* 3 n))))
(defn fast-chain-length [n]
@alexispurslane
alexispurslane / self-aware?.md
Last active February 13, 2016 01:14
Self Aware?

I'm going to start using my Gists like a blog

Disclaimer: I'm no expert in AI or theology or anything like that, in fact, I'm not particularly good at Relational Logic Programming.

About a week ago, I was touching up on my Logic Programming skills and checking out Relational Programming (with the fantastic works of Will Byrd), and I noticed that someone had written a miniKanren interpreter for Scheme. So I translated it into Racket, and played around with it a little. And what I saw scared me just a bit. See, let's start by defining self-awareness. I'm just going to use Google for this:

self-a·ware·ness
noun
conscious knowledge of one's own character, feelings, motives, and desires

@alexispurslane
alexispurslane / ideas.md
Last active February 13, 2016 01:12
Blog Post Ideas/Roadmap

Some ideas for blog posts

These are some ideas that I have for blog posts that I intend to make in the future (probably next week and the week after).

  • Why Clojure I think is the best Lisp yet
  • Haskell is basically math (why, how, and in what way?)
  • Clojure most of the benefits of Haskell
  • You're selling JavaScript short
  • Why Hygenic Macros are Less Powerful than Regular Macros
  • Why ES6 is not a good idea
@alexispurslane
alexispurslane / youre-selling-js-short.md
Last active June 25, 2017 02:35
You're Selling JavaScript Short

JavaScript is an interesting language, to say the least. It's got closures and lambdas, it has prototypal inheritance, and it runs on every machine on arguably the most portable virtual machine/interpreter ever made (the browser). It's got its warts, sure, but every language does. In fact, it has some pretty terrible warts, and I'm just going to put this out there, I really don't think we should use JS servers and large applications. But for all that, it is a very interesting language to use.

When people criticize JS, or comment on its weirdness, one of the most common responses I hear is "But it's basically Scheme. So you're all blind and JS is based on the best language ever." OK, maybe I'm exaggerating, but I hear that kind of thing a lot. So lets debunk that. Now, you're probably wondering when I'll start actually saying nice things about JS. I'm getting to that. So, off the top of my head, here is what made Scheme, well, Scheme:

  • Lambdas
  • Closures
@alexispurslane
alexispurslane / purpose.md
Last active February 13, 2016 01:15
My Blogs Purpose

My Blog's Purpose

I intend to write 1-5 paragraph essays once a day, or more than once, about my views on technology, computer science and math. I want to keep my posts short and interesting.