2022 Hanukkah of Data • Puzzle 1
This article is originally published at https://rud.is/b
Visiting #2 and doing some $WORK
-work, but intrigued with Hanukkah of Data since Puzzle 0 was solvable with a ZIP password cracker (the calendar date math seemed too trivial to bother with).
Decided to fall back to R for this (vs Observable for the Advent of Code which I’ll dedicate time to finishing next week).
R has a {phonenumber} package, so we’ll cheat and use that despite it being very brutish in how it does the letterToNumber()
conversion.
No spoilers besides the code.
library(phonenumber)
library(tidyverse)
cust <- read_csv("~/Downloads/noahs-csv/noahs-customers.csv")
cust |>
filter(!grepl("[01]", phone)) |> # only care abt letters
mutate(
last_name = stri_replace_all_regex(name, "(II|III|IV|Jr\\.)", ""), # get rid of suffix if any
) |>
separate( # get only the last name
col = last_name,
into = c("x1", "x2", "last_name"),
sep = " ",
fill = "left"
) |>
filter(
nchar(last_name) == 10 # only complete last names
) |>
mutate(
last_name = toupper(last_name),
phone = gsub("-", "", phone) # we're going to compare so remove the '-'
) |>
select(last_name, phone) |>
mutate(
trans = strsplit(xx$last_name, "") |>
map_chr(~map(.x, letterToNumber) |> paste0(collapse="")) # feels like I cld optimize this
) |>
filter(trans == phone)
Thanks for visiting r-craft.org
This article is originally published at https://rud.is/b
Please visit source website for post related comments.