Skip to content

Instantly share code, notes, and snippets.

View nickforce's full-sized avatar
🤘
Prompt engineer

Nick Johnson nickforce

🤘
Prompt engineer
View GitHub Profile
@nickforce
nickforce / day01.mjs
Last active July 10, 2023 05:14
day01_adventofcode_2022_part1
import * as fs from 'fs';
const elves = fs.readFileSync("day01.txt", { encoding: "utf-8" })
.replace(/\r/g, "")
.trim()
.split("\n\n"); // split on newline
function findMaxCaroliesElve() {
const calories = elves.map((elf) => {
const calories = elf.split("\n").map(Number);
@nickforce
nickforce / day01.mjs
Created July 10, 2023 05:15
day01_adventofcode_2022_part2
import * as fs from 'fs';
const elves = fs.readFileSync("day01.txt", { encoding: "utf-8" })
.replace(/\r/g, "")
.trim()
.split("\n\n"); // split on newline
function findTop3CalorieElves() {
const calories = elves.map((elf) => {
const calories = elf.split("\n").map(Number);
@nickforce
nickforce / new_repo.md
Last active July 19, 2023 05:27
New repo

…or create a new repository on the command line

echo "# test222" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/nickforce/test222.git
git push -u origin main
@nickforce
nickforce / AdventofCode_FileReader.html
Created December 2, 2023 05:44
AdventofCode_FileReader
<template>
<lightning-card title="Puzzle File Reader">
<div class="slds-p-around_medium">
<lightning-input type="file" label="Select File" onchange={handlePuzzleInputChange}></lightning-input>
{puzzleInputFileName}
<div class="slds-p-top_small">
<lightning-button label="Read Puzzle Input" onclick={uploadPuzzleInput} disabled={disabled}></lightning-button>
</div>
</div>
</lightning-card>
@nickforce
nickforce / AdventofCode_FileReader.js
Created December 2, 2023 05:44
AdventofCode_FileReader
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];
@nickforce
nickforce / Advent.cls
Created December 2, 2023 05:45
Advent
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
@nickforce
nickforce / day01.cls
Created December 2, 2023 05:46
day01
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',
@nickforce
nickforce / day01.cls
Created December 2, 2023 07:04
day01_part2
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',
@nickforce
nickforce / day02.cls
Created December 2, 2023 21:20
day02-part1
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>();
@nickforce
nickforce / day02.cls
Last active December 2, 2023 21:30
day02-part2
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(',')) {