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
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 |
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
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()); | |
} |
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
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 |
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
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) { |
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
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)) | |
} |
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
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)}) | |
} |
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
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()) { |
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 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 |
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 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; |
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
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; |
NewerOlder