## more games of life Another puzzle in memoriam of John Conway in The Guardian:

Find the ten digit number, abcdefghij. Each of the digits is different, and

• a is divisible by 1
• ab is divisible by 2
• abc is divisible by 3
• abcd is divisible by 4
• abcde is divisible by 5
• abcdef is divisible by 6
• abcdefg is divisible by 7
• abcdefgh is divisible by 8
• abcdefghi is divisible by 9
• abcdefghij is divisible by 10

Which brute force R coding by checking over random permutations of (1,2,…,9) [since j=0] solves within seconds:

```while(0<1)
if (prod(!(x<-sum(10^{0:8}*sample(1:9)))%/%10^{7:0}%%2:9))break()
```

into x=3816547290. And slightly less brute force R coding even faster:

```while(0<1){
e=sample(c(2,6,8))#even
o=sample(c(1,3,7,9))#odd
if((!(o+e+o)%%3)&
(!(10*o+e)%%4)&
(!(o+e+o+e+5+4)%%3)&
(!sum(10^{6:0}*c(o,e,o,e,5,4,o))%%7)&
(!(10*o+e)%%8)&
(!(sum(o)+sum(e))%%9)){
print(sum(10^{9:0}*c(o,e,o,e,4,5,o,e,o,0)));break()}}
```

### 6 Responses to “more games of life”

1. ΓΔ 047 Says:

Another approach without random sampling

library(tidyverse)
library(gtools)
df <- permutations(9, 9, v = 1:9)
df <- as.data.frame(df)
names(df) %
mutate(j = 0) %>%
filter(e == 5) %>%
filter_at(vars(b, d, f, h), ~ . %% 2 == 0) %>%
mutate(
cd = paste0(c, d) %>% as.numeric(),
fgh = paste0(f, g, h) %>% as.numeric(),
abcdefg = paste0(a, b, c, d, e, f, g) %>% as.numeric()
) %>%
filter((a + b + c) %% 3 == 0) %>%
filter((d + e + f) %% 3 == 0) %>%
filter(fgh %% 8 == 0) %>%
filter(abcdefg %% 7 == 0) %>%
filter(cd %% 4 == 0) %>%
select(-c(cd, fgh, abcdefg))

• ΓΔ 047 Says:

The code did not paste correctly. Here is an image of it https://ibb.co/X75V4pt

• xi'an Says:

Thanks a lot, I alas cannot test it as tidyverse does not install.

• ΓΔ 047 Says:

You could test it here https://rdrr.io/snippets/

• xi'an Says:

Thanks again!

2. more games of life | R-bloggers Says:

[…] article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.