Skip to content

Instantly share code, notes, and snippets.

View quoll's full-sized avatar
💭
Back to Asami

Paula Gearon quoll

💭
Back to Asami
View GitHub Profile
package buffer;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class BufferList {
public static int ELEMENT_SIZE = 2 * Integer.BYTES;
@quoll
quoll / BufferList.java
Created August 19, 2019 04:30
List Example with Buffer in Java
package buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class BufferList {
// size of the data that represents an element in the buffer
public static int ELEMENT_SIZE = 2 * Integer.BYTES;
public static int NULL = -1;
@quoll
quoll / offset-list2.c
Created August 18, 2019 13:26
Linked list with bytes
#include <stdio.h>
#include <stdlib.h>
struct element {
unsigned char next;
unsigned char value;
};
void print_list(void* memory, unsigned char list_id) {
while (list_id != (unsigned char)-1) {
#include <stdio.h>
#include <stdlib.h>
struct element {
long next;
long value;
};
void print_list(void* memory, long list_id) {
while (list_id != -1) {
@quoll
quoll / valid-.clj
Created February 9, 2018 16:21
Second valid? function
(defn valid*? [phrase]
(let [words (map sort (str/split phrase #" "))]
(= (count words) (count (set words)))))
@quoll
quoll / valid.clj
Created February 9, 2018 16:05
valid? function
(defn valid? [phrase]
(let [words (str/split phrase #" ")]
(= (count words) (count (set words)))))
@quoll
quoll / util.clj
Created February 7, 2018 06:12
Updates test reports
(ns test-diff.util
(:require [clojure.test]
[clojure.data]))
(defmethod clojure.test/assert-expr '= [msg form]
(let [args (rest form)
report (clojure.test/assert-predicate msg form)]
(concat (butlast report)
(list
`(let [[f# s#] (clojure.data/diff ~@args)]
@quoll
quoll / day3-.clj
Last active January 26, 2018 04:36
(defn day3* [input]
(loop [i 2 mem [1 1]]
(let [[x y] (coords i)
v (apply + (for [p [-1 0 1] q [-1 0 1]
:let [f (offset (+ x p) (+ y q))]
:when (< f i)]
(get mem f)))]
(if (> v input)
v
(recur (inc i) (conj mem v))))))
(defn square [x] (* x x))
(defn offset [x y]
(let [ms (max (Math/abs x) (Math/abs y))
sq (dec (* 2 ms))
base (square sq)
side (inc sq)
hside (/ side 2)]
(cond
(and (= x ms) (< y ms)) (- (+ base hside) y)
@quoll
quoll / day3-.clj
Last active January 26, 2018 03:59
(defn day3* [input]
(loop [i 2 field (init fieldr)]
(let [[x y] (coords i)
x' (+ fieldr x)
y' (+ fieldr y)
v (apply + (for [p [-1 0 1] q [-1 0 1] :when (not (= 0 p q))]
(get-in field [(+ y' q) (+ x' p)])))]
(if (> v input)
v
(recur (inc i) (assoc-in field [y' x'] v))))))