Created
July 4, 2020 02:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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