Tower Breakers

  • + 0 comments

    My answer with Typescript.

    Firsts & second attemp i was try to calculate every tower / every move can do. correct but take too many time.

    Thirt attemp, I realized every player will reduce tower to 1 when they can, so i just need to know numbers of tower that divide to 2 tp know the winner, a exception is the tower already height 1, so whatever numbers of tower, player move firsts will lose, the winner is 2.

    function towerBreakers(n: number, m: number): number {
        if (m == 1) return 2
        return n % 2 == 0 ? 2 : 1
    }