Skip to content
loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

Probably not a very efficient way to do it, but it works:

def strongest_number(interval):
  counter = interval[0]
  numbers = []
  while counter <= interval[1]:
    if counter % 2 == 0: numbers.append(counter) 
    counter += 1
  strengths = {}
  for i in range(len(numbers)):
    result = numbers[i]
    count = 0
    while result % 2 == 0:
      result = result / 2
      count += 1
    strengths[i] = count
  largest = 0
  k = ""
  for key in strengths:
    if strengths[key] > largest:
      largest = strengths[key]
      k = key
  return numbers[k]

code of conduct - report abuse