Skip to content

Instantly share code, notes, and snippets.

View pakaufmann's full-sized avatar

Patrick Kaufmann pakaufmann

  • innoQ GmbH
  • Switzerland
View GitHub Profile
@pakaufmann
pakaufmann / TranslatedFieldType.php
Created May 15, 2012 13:16 — forked from qrizly/TranslatedFieldType.php
Changed a couple of things. Languages are now dynamic and a default language can be used which won't be written into a translation object but directly into the object itself so it can be used like in this blog post: http://knplabs.fr/blog/I%28blah...blah.
<?php
namespace ExampleBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Edge5\TestProjectBundle\Form\addTranslatedFieldSubscriber;
@pakaufmann
pakaufmann / Movie-generator.yml
Created July 19, 2012 13:00
Translatable Field type for Admingeneratorgenerator
params:
model: Admingenerator\PropelDemoBundle\Model\Movie
namespace_prefix: Admingenerator
bundle_name: PropelDemoBundle
fields:
movieI18ns:
label: Translations
dbType: collection
formType: translatable_collection
addFormOptions:
if([topController respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[topController presentViewController:controller animated:YES completion:nil];
}
else
{
[topController presentViewController:controller animated:YES completion:nil];
}
object Day1 extends Challenge {
override def runFirst(): Unit = {
val startPosition = Position.start
val endPosition = loadInput().foldLeft(startPosition) {
case (p, ("R", l)) =>
p.turnRight().walk(l.toLong)
case (p, ("L", l)) =>
p.turnLeft().walk(l.toLong)
}
object Day5 extends Challenge {
val doorId = "abbhdwsy"
override def runFirst(): Unit = {
val password = hashes().filter(_.startsWith("00000")).take(8).map(_.charAt(5)).mkString
println(password)
}
def hashes(): Iterator[String] = {
Iterator.iterate(("", 0)) {
object Day6 extends Challenge {
val lines = loadFile("day6.txt").getLines().toList.transpose.map(groupByChars)
override def runFirst(): Unit = {
println(lines.map(_.maxBy(_._2)._1).mkString)
}
override def runSecond(): Unit = {
println(lines.map(_.minBy(_._2)._1).mkString)
}
object Day7 extends Challenge {
val ips = loadFile("day7.txt").getLines().toList
override def runFirst(): Unit = {
println(ips.count(supportsTLS))
}
override def runSecond(): Unit = {
println(ips.count(supportsSSL))
}
object Day9 extends Challenge {
override def runFirst(): Unit = {
val compressed = loadFile("day9.txt").mkString
println(decompress(compressed))
}
override def runSecond(): Unit = {
val compressed = loadFile("day9.txt").mkString
println(decompress(compressed, v2 = true))
}
object Day21 extends Challenge {
override def runFirst(): Unit = {
val instructions = parseInstructions(loadFile("day21.txt").getLines().toSeq).toList
val scrambled = instructions.foldLeft("abcdefgh") { (pw, instruction) =>
instruction match {
case SwapPosition(from, to) =>
pw.updated(to, pw(from)).updated(from, pw(to))
case SwapLetter(char1, char2) =>
pw.replace(char1, '_').replace(char2, char1).replace('_', char2)
object Day24 extends Challenge {
override def runFirst(): Unit = {
val map = createMap(loadFile("day24.txt").getLines().toSeq)
val destinations = map.filter(_._2 >= 2).keys
val start = map.find(_._2 == 2).get._1
val lengths = destinations.flatMap { destination =>
val others = destinations.filterNot(_ == destination)
others.map(o => (destination, o) -> findShortestPath(destination, o, map))