See 1st link below under Related Questions.
This exact question was answered.
In a variant of the game Nim, two players alternate taking turns in removing 1, 2, or 3, beans from a pile. The object is to remove the last bean. If the initial pile has 29 beans, should you want to go first or second to guarantee a win?
1 answer