Skip to content

Instantly share code, notes, and snippets.

@necronet
Created July 13, 2020 04:05
Show Gist options
  • Save necronet/3a36dc84eb8c50e833776e3f73668bf2 to your computer and use it in GitHub Desktop.
Save necronet/3a36dc84eb8c50e833776e3f73668bf2 to your computer and use it in GitHub Desktop.
Find the largest residual of 2 digits number that can be divided by the sum of itself
# Find the largest residual of 2 digits number that can be divided by the sum of itself
# maxres(ab/(a+b))
library(tidyr)
count <- 0
max_index <- 0
for( i in 10:99) {
digits <- as.integer(substring(i, seq(nchar(i)), seq(nchar(i))))
aplusb <- digits[1] + digits[2]
if (max_index < ( i %% aplusb)){
max_index <- ( i %% aplusb)
number <- i
}
}
print(max_index)
print(number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment