I made an R solve that's not exactly R I think, but does the job. This is that R-type with extra steps.