Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
namespace AdventOfCodeDay20
{
class MainClass
{
public static void Main (string[] args)
{
var input = 36000000;
var houseNumber = 830000;
var presents = 0;
var max = 0;
do {
presents = PresentCountForHousePart2 (houseNumber);
max = Math.Max(presents, max);
//Console.WriteLine ($"House #{houseNumber}: {presents}");
if(houseNumber%1000 == 0)
Console.WriteLine($"house #{houseNumber} presents: {presents} max: {max}");
houseNumber++;
if(houseNumber == 20) break;
} while(presents < input);
Console.WriteLine ($"House #{--houseNumber} Presents: {presents}");
}
public static int PresentCountForHouse(int houseNumber)
{
var total = houseNumber * 10;;
var max = houseNumber/2;
for (var i = 1; i <= max; i++) {
if (houseNumber % i == 0) {
total += (i * 10);
}
}
return total;
}
public static int PresentCountForHousePart2(int houseNumber)
{
var total = houseNumber * 11;
var max = houseNumber/2;
var start = (int)(houseNumber / 50) + 1;
for (var i = start; i <= max; i++) {
if (houseNumber % i == 0) {
total += (i * 11);
}
}
return total;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.