Skip to content

Instantly share code, notes, and snippets.

@johnboker
Created December 21, 2015 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnboker/7fc75dd06d62afb0ea97 to your computer and use it in GitHub Desktop.
Save johnboker/7fc75dd06d62afb0ea97 to your computer and use it in GitHub Desktop.
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