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
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; |
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
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; |
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
#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) { |
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
#include <stdio.h> | |
#include <stdlib.h> | |
struct element { | |
long next; | |
long value; | |
}; | |
void print_list(void* memory, long list_id) { | |
while (list_id != -1) { |
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
(defn valid*? [phrase] | |
(let [words (map sort (str/split phrase #" "))] | |
(= (count words) (count (set words))))) |
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
(defn valid? [phrase] | |
(let [words (str/split phrase #" ")] | |
(= (count words) (count (set words))))) |
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 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)] |
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
(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)))))) |
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
(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) |
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
(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)))))) |