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:
# include <cs50.h> | |
# include <stdio.h> | |
void print_row(int spaces, int bricks); | |
int main(void) | |
{ | |
int n; | |
do | |
{ |
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) | |
} |
# 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") { |
# 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) | |
} |
# 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){ |
# 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) | |
}) |
# 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 |
# 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") |
# 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", |
I hereby claim:
To claim this, I am signing this object: