Sorry I meant if anyone knows how to do the question in RStudio
I would assume the question wants you to simulate it as a hint to build intuition on how the game works. I think once you "get" the game, as Sam has pointed out, there's not much value in simulating it.
The simulation with that intuition would simply involve starting with $-10 and looping for 20 iterations assuming the optimal case of winning $1 each time. It should be simple to write this in R.
If you didn't have that intuition, the simulation would instead randomly add 1 at a probability of 1/3 to simulate getting a 5 or 6 - or you could more directly simulate a dice roll. You'd repeatedly do this and track the maximum profit in a round. The catch to this simulation (especially as a system gets more complicated) is that the optimal result could in theory not get hit often or at all, so you would want to do many rounds to ensure it.
That approach is called monte carlo simulation and usually it would be used to track and converge on the average (expected value) rather than the extreme values. But it's still error prone compared to purely analytical approaches, consider simulating a lottery with 1/10m odds - you'd have to run tens of millions of rounds of a simulation to get accurate averages.
This game is simple, so an average and the maximum can be calculated analytically quite simply, but monte carlo simulation is good for more complex systems with lots more variables and non-linear relationships.