Skip to content

Instantly share code, notes, and snippets.

💭
Perpetually confused.

Christopher Kruse ballpointcarrot

Block or report user

Report or block ballpointcarrot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ballpointcarrot
ballpointcarrot / aoc5.clj
Created Dec 6, 2018
Advent of Code 2018 - Day 5
View aoc5.clj
(ns aoc.aoc5)
(defn polymer-drop [[c1 c2]]
(cond
(= c1 c2) false
(or (nil? c1) (nil? c2)) false
(= (Character/toLowerCase c1) (Character/toLowerCase c2)) true
:else false))
(defn shrink [input]
@ballpointcarrot
ballpointcarrot / aoc3.clj
Last active Dec 3, 2018
Advent of Code 2018 - Day 3
View aoc3.clj
(ns aoc.aoc3
(:require [clojure.string :as s]
[clojure.set :as set]))
(defrecord Claim [claim-number squares])
(defn convert-to-grid
"Converts a claim into a sequence of 'taken' squares."
[claim grid-width]
;; Named groups would be great here, but Clojure doesn't support this natively.
@ballpointcarrot
ballpointcarrot / aoc2.clj
Created Dec 3, 2018
Advent of Code 2018 - Day 2
View aoc2.clj
(ns aoc.aoc2)
(defn reduce-twos-threes
"check the given frequency map n for twos or threes matches, and update
the memo map to indicate if the string has a match. Used for a reducer."
[memo n]
(let [t-memo (transient memo)]
(if (some (fn [[k v]] (= v 2)) n) (assoc! t-memo :twos (inc (:twos t-memo))))
(if (some (fn [[k v]] (= v 3)) n) (assoc! t-memo :threes (inc (:threes t-memo))))
(persistent! t-memo)))
@ballpointcarrot
ballpointcarrot / aoc1.clj
Created Dec 2, 2018
Advent of Code - 2018 - Day 1
View aoc1.clj
(ns aoc1)
(defn calibrate-1
"Simple solution for part 1 of AoC 2018 Day 1"
[input-file]
(let [raw-input (slurp input-file)
freqs (map #(Integer. %) (clojure.string/split-lines raw-input))]
(reduce + freqs)))
;; Below contents are from part 2, which didn't work well.
View keybase.md

Keybase proof

I hereby claim:

  • I am ballpointcarrot on github.
  • I am ballpointcarrot (https://keybase.io/ballpointcarrot) on keybase.
  • I have a public key whose fingerprint is 3ACB 1562 B92F BD0E 50A9 1985 B1E5 55FB 2A02 1EC4

To claim this, I am signing this object:

View ingestor.clj
(ns clj.image-db-clj.ingestor
(:use net.cgrand.enlive-html)
(:import java.net.URL))
(defn parse_page
"Retrieve all link references from the specified url"
[url]
(-> url URL. html-resource select [:a] ))
(defn folder-filter [anchor-tag]
@ballpointcarrot
ballpointcarrot / content.rb
Created May 23, 2012
Generic substitution with Procs
View content.rb
class Content
MATCHERS = [{:regex => /\[Contact\]/i, :proc => Proc.new{|options| options[:contact].name}},
{:regex => /\[Site\]/i, :proc => Proc.new{|options| options[:site].name}}]
attr_accessor :body
def prepare_form_letter(contact, site)
parsed = self.body
MATCHERS.each do |matcher|
parsed.gsub!(matcher[:regex], matcher[:proc].call({:contact => contact, :site => site}))
@ballpointcarrot
ballpointcarrot / letter_count.c
Created Oct 8, 2011
Letter Distribution Calculator
View letter_count.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "letter_count.h"
int main (int argc, char const* argv[])
{
int i;
for (i=1;i<argc; i++){
letter_distribution_of(argv[i]);
@ballpointcarrot
ballpointcarrot / main.go
Created Sep 17, 2011
opengl tutorial 0
View main.go
package main
import(
"fmt"
"gl"
"gl/glu"
"os"
"sdl"
)
@ballpointcarrot
ballpointcarrot / sum_squares.rb
Created Apr 20, 2011
A simple solution to finding the difference of the "square of the sums" and the "sum of the squares."
View sum_squares.rb
def sums(n)
(1..n).inject(0){|sum,i| sum + i**2}
end
def squares(n)
(1..n).inject(0){|sum, i| sum + i} ** 2
end
puts squares(100) - sums(100)
You can’t perform that action at this time.