# GC7X6EW MIND-BENDER

**geocacheR**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I stumbled upon a nice little puzzle in Gloucestershire, England:

Arrange the numbers 1 to 16, so each two numbers next to each other, add up to a square number. (You can only use each number once).

Devastatingly succinct. But potentially tricky. I reached out, as I always do, to R to help narrow the possibilities:

library(tidyverse)<br>library(magrittr)</code><br><code>v <- 1:16<br>dafr <- crossing(a=v, b=v) %>%<br> filter(a < b) %>% <br> mutate(s = a + b) %>% <br> filter((a + b) %in% ((1:5)^2)) %>% <br> print()

Here made every combination of two different numbers, summed each pair and thrown out all the ones that don’t sum up to 1, 4, 9, 16, or 25. And there are only sixteen pairs remaining! We need fifteen, and each number must be used at most twice. Two numbers appear three times, so that is the rogue pair which can be discarded.

Furthermore, two numbers can only form a square-pair once each: 8 (which when added to 1 makes 9), and 16 (which makes 25 in combination with 9). They become our end members:

`8 ... 16`

And since their partners are known,

`8 1 ... 9 16`

Now it’s a purely mechanical task of picking out the remaining pair for each number, working towards the middle. Try it!

**leave a comment**for the author, please follow the link and comment on their blog:

**geocacheR**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.