01020304050607080910111213141516171819202122232425

Advent of Code

2015/1

Not Quite Lisp

in C#

by encse

Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December 25th.

Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

Visit the website for the full story and full puzzle description.

using System.Collections.Generic;
using System.Linq;

namespace AdventOfCode.Y2015.Day01;

[ProblemName("Not Quite Lisp")]
class Solution : Solver {

    public object PartOne(string input) => Levels(input).Last().level;

    public object PartTwo(string input) => Levels(input).First(p => p.level == -1).idx;

    IEnumerable<(int idx, int level)> Levels(string input){
        var level = 0;
        for (var i = 0; i < input.Length; i++) {
            level += input[i] == '(' ? 1 : -1;
            yield return (i+1, level);
        }
    }
}

Please ☆ my repo if you like it!

© 2025 Advent of Code is a registered trademark in the US Images provided by Bing image creator