Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions R/16. Power digit sum/kkulma.R
Original file line number Diff line number Diff line change
@@ -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)


12 changes: 12 additions & 0 deletions R/19.Counting Sundays/kkulma.R
Original file line number Diff line number Diff line change
@@ -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")
15 changes: 15 additions & 0 deletions R/20. Factorial digit sum/kkulma.R
Original file line number Diff line number Diff line change
@@ -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)


13 changes: 13 additions & 0 deletions R/24.Lexicographic permutations/kkulma.R
Original file line number Diff line number Diff line change
@@ -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, ]

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: | | | | | | | | | | |
Expand Down