Created
December 21, 2015 06:33
-
-
Save johnboker/7fc75dd06d62afb0ea97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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