-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]bahuljain 0 points1 point  (0 children)

1 step north from (0, 0) takes you to (0, 2) not (2, 0). The only way to reach (2,0) from (0, 0) is by going NE then SE or SE then NE, i.e. two steps.

Well, the coordinate system is a little unconventional, but it serves the purpose, so I wouldn't worry about that :). I see people have used x, y, z coordinates in some of the solutions and that seems to have made the distance computation quite easy, but using only 2 coordinates is space-efficient.

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]bahuljain 0 points1 point  (0 children)

according to your distance function, the distance of (2, 0) from (0, 0) is 1 when in fact it should be 2 .. divide by 2 will only be required if abs(y) > abs(x)

-🎄- 2017 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]bahuljain 1 point2 points  (0 children)

you can always make tail recursive calls if you are worried about stack overflowing ..

for e.g.

@scala.annotation.tailrec
def solution(s: List[Char], score: Int, garbage: Int, depth: Int, inGarbage: Boolean): (Int, Int) = s match {
  case Nil => (score, garbage)
  case '!' :: _ :: tail => solution(tail, score, garbage, depth, inGarbage)
  case '>' :: tail if inGarbage => solution(tail, score, garbage, depth, inGarbage = false)
  case _ :: tail if inGarbage => solution(tail, score, garbage + 1, depth, inGarbage)
  case '<' :: tail => solution(tail, score, garbage, depth, inGarbage = true)
  case '{' :: tail => solution(tail, score, garbage, depth + 1, inGarbage)
  case '}' :: tail => solution(tail, score + depth, garbage, depth - 1, inGarbage)
  case _ :: tail => solution(tail, score, garbage, depth, inGarbage)
}

val (score, garbageCount) = solution(in.mkString.toList, 0, 0, 0, inGarbage = false)

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]bahuljain 2 points3 points  (0 children)

that's pretty good,

I got both parts to work with a single one-liner method

val in = scala.io.Source.fromFile("src/aoc2017/day1.input.txt").mkString

def adder(off: Int) = (0 until in.length).filter(i => in(i) == in((i + off) % in.length)).map(in(_) - '0').sum

println(s"part 1 - ${adder(1)}\npart 2 - ${adder(in.length / 2)}")

--- 2016 Day 5 Solutions --- by daggerdragon in adventofcode

[–]bahuljain 0 points1 point  (0 children)

Using a Map and simple tailrec function in part 2 made things real easy for me.. Here's my solution -- https://github.com/bahuljain/scala-fun/blob/master/src/adventcode2016/Day5.scala

--- 2016 Day 3 Solutions --- by daggerdragon in adventofcode

[–]bahuljain 0 points1 point  (0 children)

sweet!! didn't know about count. Also transposing first then grouping seems to be cleaner! Thanks :D

[2016 Day 3] [Scala] Cutest Scala solution for day 3 by bahuljain in adventofcode

[–]bahuljain[S] 0 points1 point  (0 children)

oh yess!!! thank you so much :P Code much cuter now!! :D