**R – Xi’an’s Og**, and kindly contributed to R-bloggers)

**I** had another lazy weekend go at code golf, trying to code in the most condensed way the following task. Provided with a square matrix *A* of positive integers, keep iterating the steps

- take the highest square
*𝑥²*in*A*. - find the smallest adjacent neighbour 𝑛
- replace
*x²*with x and n with*nx*

until no square is left (with neighbour defined as either horizontally or vertically and without wrapping around). While I managed a 217 bytes solution, compared with Robin’s 179b improvement, which remains surprising readable!, the puzzle offers two further questions:

- is there a non-iterative way to find the final matrix B?
- the puzzle assumes that A satisfies that at each step, the highest square
*x²*and the smallest neighbour*n*will be unique, and that the sequence will not repeat forever. Is there a fool-proof way to check this is the case?

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

**R – Xi’an’s Og**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…