# Solutions

This page lists explanations and solutions to all riddles. Looking up the solution to quickly might spoil the fun!

Level 0.1

The goal of this training exercise is mainly to teach you how to insert the solution into the url. Calculate 17 to the power of 3, which is 4913, and change the url to https://msf5.neocities.org/rriddle/4913.html. ``` 17 ^ 3  4913 ``` Solution: 4913

Level 0.2

The goal of this training exercise is to spare you from wasting time trying to read the data in future riddles. Use the code given in the task description to read the data. It can be useful to create a function like that: ``` library(tidyverse) library(rvest) read_rriddle_data <- function(page, table = T) { dat <- paste0("https://msf5.neocities.org/rriddle/", page, ".html") %>% read_html() %>% html_nodes(".data") %>% html_text() %>% str_trim() if(table) dat <- read_delim(dat, " ") else dat <- str_squish(dat) return(dat) } dat <- read_rriddle_data(4913) # use table=F if you want to read plain text ``` Then simply calculate the correlation of x and y und take the first 4 decimal places: ``` cor(dat\$x, dat\$y)  0.7559289 ``` Solution: 7559

Level 1

It is important to get a feeling for the data you are working with. The first step should often be to simply create a scatter plot of the data and look for interesting features. If yo do this with the given data, you see a Tyrannosaurus Rex. The solution is only 4 symbols long, so it is "trex". ``` plot(dat) ``` Solution: trex

Level 2

Your goal is to find all the letters in the long string containing mainly special characters. This can be easily done with the stringr package. ``` library(tidyverse) str_extract_all(dat, "[a-zA-Z]") []  "e" "q" "u" "a" "l" "i" "t" "y" ``` [a-zA-Z] is a so called regular expression. It finds all the lower and upper case letters from a to z. Solution: equality

Level 3

You need to find alle lower case letters which have EXACTLY 3 upper case letters to the left and to the right. It works similar to level 2, the regular expression is just more complicated. ``` library(tidyverse) dat %>% str_extract_all("[a-z]+[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]+") %>% unlist() %>% str_extract_all("[A-Z]{3}[a-z]{1}[A-Z]{3}") %>% unlist() %>% str_sub(4, 4)  "l" "i" "n" "k" "e" "d" "l" "i" "s" "t" ``` Solution: linkedlist

Level 4

You have to decrypt the encrypted message by shifting alle letters by 4 positions in the alphabet. This is one way to do it: ``` library(tidyverse) dat %>% str_split("") %>% unlist() %>% plyr::mapvalues(letters, c(letters[5:26], letters[1:4])) %>% paste0(collapse = "")  "i hope you didnt translate it by hand. thats what computers are for. doing it by hand is inefficient and thats why this text is so long. using plyr::mapvalues is one way to do it. anyway, the solution is pandabear." ``` Solution: pandabear

Level 5

Calculating with dates per hand is very tidious, because you have to consider leap years, different month lengths, etc.. Luckily, it is easy in R. After reading the data with the function from level 0.2, the birth and death dates are already of class "Date". This means we can perform mathematical operations on them directly. ``` sum(dat\$death - dat\$birth) Time difference of 92454 days ``` Solution: 92454

Level 6

This riddle is a bit more complicated. We have to find every information the calendar has to offer. The year is 1xx6. This leaves us with 100 possible years. February has 29 days, so it is a leap year. Jaunary 1st is a Thursday. ``` years <- as.numeric(c(paste0(10, 0:9, 6), paste0(1, 10:99, 6))) years <- years[lubridate::leap_year(years)] years[weekdays(as.Date(paste0(years, "-01-01"))) == "Donnerstag"] # depending on your system language this might be "Thursday" or Thursday in your language  1176 1356 1576 1756 1976 ``` 5 years are left. The description says "Tip: It is not the most recent date, but the second most recent." So we are looking for a person born at 1756-01-27. Also the calendar is in German. If we google the date, the first hit is Mozart. Solution: mozart

Level 7

You have to read the color values of specific pixels given in the table. Load the image with png::readPNG() after downloading it. Images are often stored as 3 color values, red, green, blue between 0 and 255, for each pixel. 255,0,0 ist pure red, 255,255,255 is white. Use dim() to see the dimensions of the image array. You can see that it is length*width*3. Extract the specific color value from each pixel. After that, you have to convert the resulting numbers into letters and symbols with Unicode/UTF-8/ASCII encoding, the most common way to encode text. ``` p <- png::readPNG("your_path_to_downloaded_image") d <- read_rriddle_data("mozart") d\$color <- as.numeric(as.character(plyr::mapvalues(d\$color, c("r", "g", "b"), 1:3))) # change to index of layer in array p <- p*255 # convert to 0-255 # read every pixel color value given in the data n <- c() for (i in 1:nrow(d)) { n <- c(n, p[d[i,]\$x, d[i,]\$y, d[i,]\$color]) } intToUtf8(n) # convert to letters and symbols using utf8 encoding  "Good, you found the hidden message! This is a small image, and a simple method of hiding text in a picture. There could be entire documents saved in normally looking images! Anyway, the next level is: daisy" ``` Solution: daisy