Goal: Nice Math Game - The Josephus Problem Source : https://www.youtube.com/watch?v=uCsD3ZGzMgE
In [1]:
elfs <- 3018458
Used the algo given in the video
In [2]:
Q1 <- (elfs-2^(floor(log(elfs, base = 2)))+1)*2-1
Q1
Used the logic to detect patern in the video to find the logic with this one
In [3]:
maxNumber <- floor(log(elfs, base = 3))
root <- 3^maxNumber
rest <- elfs-root
if(rest==0){
Q2 <- elfs
} else {
Q2 <- min(root,rest)+max(0,rest-root)*2
}
Q2
In [4]:
cat("Q1- If you give take to the elf on your left, the remaining elf is : ", Q1, '\n')
cat("Q2- If you give take to the elf facing you, the remaining elf is : ", Q2, '\n')