We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Tower Breakers, Again!
Tower Breakers, Again!
Sort by
recency
|
22 Discussions
|
Please Login in order to post a comment
My Code Works At Python Pass all test casses. check this out !
import os import sys import math
Complete the towerBreakers function below.
def towerBreakers(arr): d = 0 for x in arr: d ^= primeFactors(x) if d != 0: return 1 else: return 2
def primeFactors(n): count = 0 flag = True while n % 2 == 0: if flag: count += 1 flag = False n //= 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: count += 1 n //= i if n > 2: count += 1 return count
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
Here is Tower Breakers Again problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-tower-breakers-again-problem-solution.html
I did not see anything in the problem statement that the tower has to be broken into prime numbers first. Where is that from? thanks
!/bin/python3
import os import sys import math #
Complete the towerBreakers function below.
# def towerBreakers(arr): # # Write your code here. # d=0 for x in arr: d^=primeFactors(x) if(d!=0): return 1 else: return 2
def primeFactors(n): count=0 flag= True while n % 2 == 0: if(flag): count+=1 flag=False n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: count+=1 n = n / i
if n > 2: count+=1 return count
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
My Code with comments : https://github.com/offamitkumar/HackerRank/blob/master/Algorithms/Game%20Theory/Tower%20Breaker%2C%20Again.cpp