Haskell
strongest :: (Int, Int) -> (Int, Int) -> (Int, Int) strongest (strongestIndex, strongestValue) (index, value) | value > strongestValue = (index, value) | value == strongestValue && index < strongestIndex = (index, value) | otherwise = (strongestIndex, strongestValue) strength :: Int -> Int strength 0 = 0 strength number | odd number = 0 | otherwise = 1 + strength (div number 2) strongestBetween :: Int -> Int -> Int strongestBetween lowerbound upperbound = fst $ foldl1 strongest $ zip interval $ map strength interval where interval :: [Int] interval = [lowerbound..upperbound] main :: IO () main = do print $ strongestBetween 1 2 -- 2 print $ strongestBetween 5 10 -- 8 print $ strongestBetween 48 56 -- 48 print $ strongestBetween 129 193 -- 192
Try it.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell
Try it.