01020304050607080910111213141516171819202122232425

Advent of Code

2015/5

Doesn't He Have Intern-Elves For This?

in C#

by encse

Santa needs help figuring out which strings in his text file are naughty or nice.

A nice string is one with all of the following properties:

Read the full puzzle.

using System.Linq;

namespace AdventOfCode.Y2015.Day05;

[ProblemName("Doesn't He Have Intern-Elves For This?")]
class Solution : Solver {

    public object PartOne(string input) =>
        input.Split('\n').Count(line => {
            var threeVowels = line.Count(ch => "aeiou".Contains(ch)) >= 3;
            var duplicate = Enumerable.Range(0, line.Length - 1).Any(i => line[i] == line[i + 1]);
            var reserved = "ab,cd,pq,xy".Split(',').Any(line.Contains);
            return threeVowels && duplicate && !reserved;
        });

    public object PartTwo(string input) =>
        input.Split('\n').Count(line => {
            var appearsTwice = Enumerable.Range(0, line.Length - 1).Any(i => line.IndexOf(line.Substring(i, 2), i+2) >= 0); 
            var repeats = Enumerable.Range(0, line.Length - 2).Any(i => line[i] == line[i + 2]);
            return appearsTwice && repeats;
        });
}

Please ☆ my repo if you like it!

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