Skip to content

Instantly share code, notes, and snippets.

View gituser768's full-sized avatar

Dany gituser768

View GitHub Profile
@gituser768
gituser768 / bst-check.md
Last active December 11, 2015 00:24
A brief explantion of binary search trees and a simple Clojure implementation. Included is a function which tests whether a given tree is a BST.

Binary Search Trees

A Binary Search Tree (BST) is a data structure consisting of nodes, each of which has a value and references to two other nodes; one with a value larger than the current node's value, and one with a value smaller. If there are no values larger (or smaller) than the value at the current node, then the reference contains the null pointer.

Consequentially, operations on binary trees are most naturally defined recursively. As such, Clojure is perfect for this week's task!

@gituser768
gituser768 / string_permutations.md
Last active October 10, 2017 08:03
Finding all permutations of a string in Clojure

Permutations of a String

The task of listing every permutation of a string is trivial when the string contains only two characters. Using this knowledge, the same problem can be solved for a string of three characters relatively easily. Accordingly, the permutations of a string of length n are easy to list if we know the permutations of a substring of length n-1.

This property is easy to see, if not obvious within a few minutes of thinking about this problem. Since the problem can be simply defined recursively, it can also be solved recursively with relative ease. In this solution, I use Clojure to demonstrate that recursion lends itself nicely to functional programming.

Brainstorming With Example Input

@gituser768
gituser768 / Gorillarepl.md
Last active December 18, 2015 02:04
A Gorilla REPL session playing around with complex matrices with apache commons FieldElement types
@gituser768
gituser768 / quine.md
Last active December 14, 2023 10:52
A quine written in Clojure with a brief explanation of how I wrote it

Quines.

A quine is a program which produces its own sourcecode as its output. Typically, the trick is to use a format string with a call to a print or printf function. Since lisps can easily treat sourcecode as any other data, writting a quine in lisp is not as mind-bending an excersise as in other languages (see the examples here). Additionally, access to anonymous functions in Clojure makes it easy to get the recursion required for a quine.

Approach

Writing a quine initially seems a daunting task, but once it's broken down a bit, it becomes surprisingly easy. Armed with lambdas and syntax quoting, all we need to do is write a function which returns the argument passed to it wrapped in lambda syntax, and applied to the argument wrapped in syntax quoting.

mylist = [1, 4, 6, 2, 5, 1, 4, 5, 5, 59, 3, 4, 5]
def move_to(v, oldi, newi):
tmp = v[oldi]
del v[oldi]
v.insert(newi, tmp)
def qsort(v):
pivot_index = len(v)
(def my-list
[1 2 7 9 2 4 27 3 8 109 384 921 84 81722 94 92 7 4929 48 78 733 98 9 7 7 7 7 6 5 4332 9 2 1])
(defn qsort
"Quicksort implementation"
[v]
(let [pivot (last v)]
(cond
(> (count v) 1)
(->> (vector ;; TODO Is there a better way to join three vectors?
#include <GL/freeglut.h>
#include <vector>
#include <cmath>
const double pi = 3.141593;
typedef struct PhysVector {
float x;
float y;
};
@gituser768
gituser768 / grav.cpp
Last active October 20, 2024 10:18
A simple physics simulator with OpenGL
#include <GL/freeglut.h>
#include <vector>
#include <cmath>
const double pi = 3.141593;
typedef struct PhysVector {
float x;
float y;
};
@gituser768
gituser768 / agent.json
Created April 28, 2017 17:49
Agent 5128 for 315 N Lindenwood Dr, Olathe, Kansas
{
"addressList": [
{
"address1": "4520 Main St",
"address2": "Suite 1000",
"addressID": null,
"addressType": null,
"city": "Kansas City",
"country": "United States",
"isActive": true,
@gituser768
gituser768 / company.json
Created April 28, 2017 17:50
Fetching company 35416 for agent 5128
{
"branchID": 38467,
"branchLogo": null,
"branchName": null,
"ccrAgentID": 337853,
"ccrEmail": "[email protected]",
"ccrFirstName": "Dustin",
"ccrLastName": "Ibarra",
"ccrPhone": "(816) 303-2868",
"csrAgentID": 223349,