Skip to content

Instantly share code, notes, and snippets.

View whaley's full-sized avatar

Jason Whaley whaley

  • Asheville, NC
View GitHub Profile
@whaley
whaley / foo.py
Created September 13, 2019 19:13
class Foo:
def a(self):
...
def b(self):
... #this doesn't return anything, but has side effects that are important, but expensive to poll for
class UsesFoo():
def __init__(self,foo):
self.foo = foo
public abstract class Foo {
private Foo() {}
public abstract void overrideMePlease();
public static class Bar extends Foo {
@Override
public void overrideMePlease() {
System.out.print("overriden in " + this.getClass().getSimpleName());
}
fun main(args: Array<String>) {
println(createGridUntil(325489).values.max() ?: 0)
}
data class Point(val x: Int, val y: Int)
fun createGridUntil(target: Int) : Map<Point,Int>{
val initial = Point(0, 0)
val knownPointsAndScores = hashMapOf(initial to 1)
var direction = Direction.RIGHT
fun manhattan(x: Int): Int {
val y = nextOddPerfectSquareInclusive(x)
val max = sqrt(y.toDouble()).roundToInt() - 1
val min = max / 2
val f = if (max == 0) 0 else max - ((y - x) % max) //for 33, f is 2, needs to be 4
return if (f < min) max - f else f
}
fun nextOddPerfectSquareInclusive(x: Int): Int {
for (i in 1..x step 2) {
fun checksum(spreadsheet: String, lineSummer: (List<Int>) -> Int = ::minAndMax): Int {
val lines = spreadsheet.split("\n")
val rows: List<List<Int>> = lines.map { line -> line.split(Regex("""\s""")).map { num -> Integer.valueOf(num) } }
return rows.fold(0, { sum: Int, list -> sum + lineSummer(list)})
}
fun minAndMax(list: List<Int>): Int {
return abs((list.max() ?: 0) - (list.min() ?: 0))
}
@whaley
whaley / Day02.kt
Last active January 10, 2018 02:28
fun checksum(spreadsheet: String): Int {
val lines = spreadsheet.split("\n")
val rows : List<List<Int>> = lines.map { it -> it.split(Regex("""\s""")).map { it -> Integer.valueOf(it) } }
return rows.fold(0, {sum:Int, list: List<Int> -> sum + (list.max() ?: 0) - (list.min() ?: 0)})
}
fun captcha(input: String, stepping: Int = 1): Int {
val ints = input.map { Character.getNumericValue(it) }
fun calcValueAtStepping(currentIndex: Int) : Int {
val wrappedIndex = currentIndex + stepping
return if (wrappedIndex < ints.size - 1) ints[wrappedIndex] else ints[wrappedIndex % ints.size]
}
var sum = 0
for ((index, current) in ints.withIndex()) {
package com.morninghacks.aoc2017
fun captcha(input: String): Int {
val ints = input.map { Character.getNumericValue(it) }
var sum = 0
for ((index, current) in ints.withIndex()) {
val next = if (index == ints.size - 1) ints[0] else ints[index + 1]
sum += if (current == next) current else 0
}
return sum
package jackson;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public static void main(String[] outsideArgs) {
Test<Collection<Integer>, List<Integer>> t = test();
Collection<Integer> a = t.getA();
List<Integer> b = t.getB();
}
public static class Test<A, B> {
A getA() {
return null;