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
public with sharing class day06 { | |
public static Long part2(List<String> puzzleInputLines) { | |
Long winningAttempts = 0; | |
Map<Long,Long> timeToDistance = parseSingleRace(puzzleInputLines); | |
for(Long varTime : timeToDistance.keySet()) { | |
// winningAttempts += getWaysToWinQuadratic(varTime, timeToDistance.get(varTime)); | |
Long max = binarySearchHi(varTime, timeToDistance.get(varTime)); | |
Long min = binarySearchLo(varTime, timeToDistance.get(varTime)); | |
winningAttempts = (max - min) * -1; |
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
public with sharing class day05 { | |
public static Integer part1(List<String> puzzleInputLines, String fullInput) { | |
String seedRow = puzzleInputLines.remove(0); | |
String[] seedValues = seedRow.split(': ')[1].split(' '); | |
List<Seed> seeds = new List<Seed>(); | |
for(Integer i = 0; i < seedValues.size(); i += 2) { | |
seeds.add(new Seed(Double.valueOf(seedValues[i]), Double.valueOf(seedValues[i + 1]))); | |
} |
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
public with sharing class day04 { | |
public static Integer part2(List<String> puzzleInputLines) { | |
Map<Integer,Integer> cardNumberToCopies = new Map<Integer,Integer>(); | |
Map<Integer,Integer> cardNumberToWinners = new Map<Integer,Integer>(); | |
// iterate each card | |
for(Integer i = 0; i < puzzleInputLines.size(); i++) { | |
String card = puzzleInputLines[i]; | |
Integer cardNumber = Integer.valueOf(card.substring(card.indexOf(' ') + 1, card.indexOf(':')).trim()); | |
Integer totalCardWinners = processTotalCardWinners(puzzleInputLines[i]); |
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
public with sharing class day03 { | |
public static Integer part2(List<String> puzzleInputLines) { | |
List<Integer> validGearRatios = new List<Integer>(); | |
// engine part row | |
for(Integer i = 0; i < puzzleInputLines.size(); i++) { | |
// engine part columns | |
for(Integer col = 0; col < puzzleInputLines[i].length(); col++) { | |
String[] columnChars = puzzleInputLines[i].split(''); | |
// Check if the character is * a gear |
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
public with sharing class day02 { | |
public static Integer part2(List<String> puzzleInputLines) { | |
Integer total = 0; | |
for(String line : puzzleInputLines) { | |
Map<String, Integer> maxGameCubesByColor = new Map<String, Integer>(); | |
Integer gameNumber = Integer.valueOf(line.substring(line.indexOf(' ') + 1, line.indexOf(':'))); | |
String gameRounds = line.substring(line.indexOf(':') + 1, line.length()); | |
for(String round : gameRounds.split(';')) { | |
for(String score : round.split(',')) { |
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
public with sharing class day02 { | |
public static Map<String, Integer> maxTurnCubes = new Map<String, Integer>{ | |
'red' => 12, | |
'green' => 13, | |
'blue' => 14 | |
}; | |
public static Integer part1(List<String> puzzleInputLines) { | |
Integer total = 0; | |
Set<Integer> validGameNumbers = new Set<Integer>(); |
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
public with sharing class day01 { | |
public static Map<String,String> numberMap = new Map<String,String>{ | |
'one' => '1', | |
'two' => '2', | |
'three' => '3', | |
'four' => '4', | |
'five' => '5', | |
'six' => '6', | |
'seven' => '7', | |
'eight' => '8', |
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
public with sharing class day01 { | |
public static Map<String,String> numberMap = new Map<String,String>{ | |
'one' => '1', | |
'two' => '2', | |
'three' => '3', | |
'four' => '4', | |
'five' => '5', | |
'six' => '6', | |
'seven' => '7', | |
'eight' => '8', |
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
public with sharing class Advent { | |
@AuraEnabled | |
public static Integer readPuzzleInput(String fileName, String fileContent) { | |
return read_lines(fileContent); | |
} | |
public static Integer read_lines(String puzzleInput) { | |
// Split by newline chars | |
List<String> lines = puzzleInput.split('\n'); | |
// call puzzle solution |
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
import { LightningElement } from 'lwc'; | |
import readPuzzleInput from '@salesforce/apex/Advent.readPuzzleInput'; | |
export default class AdventofCode_FileReader extends LightningElement { | |
puzzleInput; | |
puzzleInputFileName; | |
puzzleAnswer; | |
handlePuzzleInputChange(event) { | |
this.puzzleInput = event.target.files[0]; |
NewerOlder