diff --git a/R/16. Power digit sum/kkulma.R b/R/16. Power digit sum/kkulma.R new file mode 100644 index 0000000..1e16f4f --- /dev/null +++ b/R/16. Power digit sum/kkulma.R @@ -0,0 +1,15 @@ +power_digit_sum <- function(num, ...) { + tidy_num <- formatC(num, ...) + num_char <- as.character(tidy_num) + num_split <- unlist(strsplit(num_char, split = "")) + sum(as.numeric(num_split)) +} + +# show that the example works +power_digit_sum(2^15) + +# solution +# 1200 +power_digit_sum(2^1000, format = "f", digits = 0) + + diff --git a/R/19.Counting Sundays/kkulma.R b/R/19.Counting Sundays/kkulma.R new file mode 100644 index 0000000..a09a0b3 --- /dev/null +++ b/R/19.Counting Sundays/kkulma.R @@ -0,0 +1,12 @@ +library(lubridate) +library(dplyr) + +base <- data.frame( + date = seq(as.Date("1901-01-01"), as.Date("2000-12-31"), by = "day") +) + +# solution +# 171 +base %>% + dplyr::mutate(dname = lubridate::wday(date, label = TRUE)) %>% + dplyr::filter(lubridate::day(date) == 1 & dname == "Sun") diff --git a/R/20. Factorial digit sum/kkulma.R b/R/20. Factorial digit sum/kkulma.R new file mode 100644 index 0000000..6ef4750 --- /dev/null +++ b/R/20. Factorial digit sum/kkulma.R @@ -0,0 +1,15 @@ +power_digit_sum <- function(num, ...) { + tidy_num <- formatC(num, ...) + num_char <- as.character(tidy_num) + num_split <- unlist(strsplit(num_char, split = "")) + sum(as.numeric(num_split)) +} + +# show that the example works +power_digit_sum(factorial(10), format = "f", digits = 0) + +# solution +# 645 +power_digit_sum(factorial(100), format = "f", digits = 0) + + diff --git a/R/24.Lexicographic permutations/kkulma.R b/R/24.Lexicographic permutations/kkulma.R new file mode 100644 index 0000000..0e963e9 --- /dev/null +++ b/R/24.Lexicographic permutations/kkulma.R @@ -0,0 +1,13 @@ +library(gtools) + +base <- 0:9 + +# run permutations +perm <- permutations(n = 10, + r = 10, + v = base) + +# solution +# 2 7 8 3 9 1 5 4 6 0 +perm[1000000, ] + diff --git a/README.md b/README.md index b794d72..b36a28c 100644 --- a/README.md +++ b/README.md @@ -45,15 +45,15 @@ Happy Contributing! 😃 | 13 | [Large sum](https://projecteuler.net/problem=13) | :white_check_mark: | | | :white_check_mark: | | | | | | | | | | 14 | [Longest Collatz sequence](https://projecteuler.net/problem=14) | | | | | | | | | | | | | | 15 | [Lattice paths](https://projecteuler.net/problem=15) | | | | | | | | | | | | | -| 16 | [Power digit sum](https://projecteuler.net/problem=16) | | :white_check_mark: | | :white_check_mark: | | | | | | | | | +| 16 | [Power digit sum](https://projecteuler.net/problem=16) | | :white_check_mark: | | :white_check_mark: | | | | | | :white_check_mark: | | | | 17 | [Number letter counts](https://projecteuler.net/problem=17) | | | | :white_check_mark: | | | | | | | | | | 18 | [Maximum path sum I](https://projecteuler.net/problem=18) | | | | :white_check_mark: | | | | | | | | | -| 19 | [Counting Sundays](https://projecteuler.net/problem=19) | | | | | | | | | | | | | -| 20 | [Factorial digit sum](https://projecteuler.net/problem=20) | | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | | | | | | | +| 19 | [Counting Sundays](https://projecteuler.net/problem=19) | | | | | | | | | | :white_check_mark: | | | +| 20 | [Factorial digit sum](https://projecteuler.net/problem=20) | | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | | | | :white_check_mark: | | | | 21 | [Amicable numbers](https://projecteuler.net/problem=21) | | | | | | | | | | | | | | 22 | [Names scores](https://projecteuler.net/problem=22) | | | | :white_check_mark: | | | | | | | | | | 23 | [Non-abundant sums](https://projecteuler.net/problem=23) | | | | | | | | | | | | | -| 24 | [Lexicographic permutations](https://projecteuler.net/problem=24) | | | | | | | | | | | | | +| 24 | [Lexicographic permutations](https://projecteuler.net/problem=24) | | | | | | | | | | :white_check_mark: | | | | 25 | [1000-digit Fibonacci number](https://projecteuler.net/problem=25) | | | | :white_check_mark: | | | | | | | | | | 26 | [Reciprocal cycles](https://projecteuler.net/problem=26) | | | | | | | | | | | | | | 27 | [Quadratic primes](https://projecteuler.net/problem=27) | | :white_check_mark: | | | | | | | | | | |