Skip to content

Instantly share code, notes, and snippets.

@necronet
Created July 4, 2020 02:53
Show Gist options
  • Save necronet/a88ab56b925a8ba9ea62ea059d88966a to your computer and use it in GitHub Desktop.
Save necronet/a88ab56b925a8ba9ea62ea059d88966a to your computer and use it in GitHub Desktop.
Get all numbers 3 digits, divisible by 3 that follow this formula, a + 3b + c where a != 0
# Get all numbers 3 digits, divisible by 3 that follow this formula
# a + 3b + c where a != 0
library(tidyr)
count <- 0
n <- c()
for( i in 100:999) {
digits <- as.integer(substring(i, seq(nchar(i)), seq(nchar(i))))
formula <- (digits[1] + 3*digits[2] + digits[3])
if ( ( formula %% 3 ) == 0 ) {
count = count + 1
n[count] <- i
}
}
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment