Skip to content

Instantly share code, notes, and snippets.

View ursulams's full-sized avatar
💾
regressing

Ursula Kaczmarek ursulams

💾
regressing
View GitHub Profile
@ursulams
ursulams / mario.c
Last active March 11, 2024 13:11
cs50 mario.c
# include <cs50.h>
# include <stdio.h>
void print_row(int spaces, int bricks);
int main(void)
{
int n;
do
{
@ursulams
ursulams / day_15.R
Last active December 21, 2023 03:31
2023 advent of code day 15
input <- data.frame("label" = t(read.table("input.txt", sep = ",")))
input$row <- seq_along(input[,1])
hasher <- function(x){
current <- 0L
for(i in 1:length(x)){
current <- ((current + utf8ToInt(x[i])) * 17L) %% 256L
}
return(current)
}
@ursulams
ursulams / day_8.R
Created December 14, 2023 19:27
2023 advent of code day 8
# first star
network <- read.table("nodes.txt", header = TRUE, sep = "\n")
edges <- as.numeric(factor(unlist(strsplit(colnames(network)[1], "")))) + 1
network$node <- sapply(strsplit(gsub("[^A-Z]", " ", network[, 1]), "\\s+"), "[", 1)
network$left_node <- sapply(strsplit(gsub("[^A-Z]", " ", network[, 1]), "\\s+"), "[", 2)
network$right_node <- sapply(strsplit(gsub("[^A-Z]", " ", network[, 1]), "\\s+"), "[", 3)
network <- network[, c(2:4)]
follow <- function(node, end_node = "ZZZ") {
@ursulams
ursulams / day_9.R
Created December 13, 2023 17:27
2023 advent of code day 9
# first star
input <- type.convert(strsplit(readLines("puzzle_input.txt"), "\\s"), as.is = TRUE)
predict <- function(element) {
new_element <- element[length(element)]
while(length(element != 0) > 0) {
element <- diff(element)
new_element <- c(new_element, element[length(element)])
}
sum(new_element)
}
@ursulams
ursulams / day_6.R
Last active December 11, 2023 01:40
2023 advent of code day 6
# first star
puzzle_input <- "Time: 52 94 75 94
Distance: 426 1374 1279 1216"
df <- data.frame("times" = type.convert(unlist(strsplit(sub("^.*:\\s+(.*)\\n.*", "\\1", puzzle_input), "\\s+")), as.is = TRUE),
"distances" = type.convert(unlist(strsplit(sub(".*Distance:\\s+(.*).*", "\\1", puzzle_input), "\\s+")), as.is = TRUE))
# distance as function of (racing - button) * button with time as constant
# 0 = -1*(button^2) +- (racing * button) - distance
# get all possible values of b for any given distance
get_b <- function(t, d){
@ursulams
ursulams / day_7.R
Created December 11, 2023 00:55
2023 advent of code day 7
# first star
hands <- data.frame(read.table("hands.txt", header = FALSE, sep = " ", col.names = c("cards", "bid")))
hands$hand <- lapply(strsplit(hands$cards, ""), function(x){
type.convert(gsub("A", 14,
gsub("K", 13,
gsub("Q", 12,
gsub("J", 11,
gsub("T", 10, x))))), as.is = TRUE)
})
@ursulams
ursulams / day_4.R
Created December 5, 2023 00:12
2023 advent of code day 4
# first star
input <- read.table(file = "puzzle_input.txt", header = FALSE, sep = "\n")
matches <- mapply(function(x, y){sum(x%in%y)},
strsplit(gsub(".*:\\s+(.+)\\s+\\|.*", "\\1", input$V1),"\\s+"),
strsplit(gsub(".*\\|\\s+(.+)", "\\1", input$V1), "\\s+"))
sum(sapply(matches[matches > 0], function(x){2^(x-1)}))
# second star
total_cards <- rep.int(1L, length(row(input))) # start cumulative total for each card
@ursulams
ursulams / day_2.R
Last active December 3, 2023 20:26
2023 advent of code day 2
# part 1
df <- read.table(text = puzzle_input, header = FALSE, sep = "\n")
df$game <- as.numeric(row(df))
get_max <- function(string, pattern) {
cubes <- gsub("[^0-9,]", "", regmatches(string, gregexpr(pattern, string)))
sapply(cubes, function(x) max(as.numeric(unlist(strsplit(as.character(x), split = ",")))))
}
df$red_max <- get_max(df$V1, "\\d+\\s+red\\b")
@ursulams
ursulams / day_1.R
Last active December 3, 2023 01:25
2023 advent of code day 1
# first star
df <- read.table(text = puzzle_input, header = FALSE, sep = "\n")
df$digits <- as.numeric(paste0(sub(".*?(\\d).*", "\\1", df$V1), sub(".*(\\d+).*$", "\\1", df$V1)))
sum_cal_values <- sum(df$digits)
# second star
df$V2 <- sapply(df$V1, function(x){
gsub("one", "o1e",
gsub("two", "t2o",
gsub("three", "thr3e",

Keybase proof

I hereby claim:

  • I am ursulams on github.
  • I am uak211 (https://keybase.io/uak211) on keybase.
  • I have a public key ASDQHcuJc098xx6kzwfn56jW-GjRUlJ-y6alxgqf5e4_Ewo

To claim this, I am signing this object: