0

This is the question. I have no idea how to approach this whatsoever. So there is no code which I tried.

A function is given with 4 parameters

  1. The RGB value of the first colour as an integer Eg: red = 220 green = 020 blue = 060 is given as 220020060
  2. The RGB value of the second colour is also an integer
  3. Number of equally distanced waypoints between the range of the two colours (non-negative integer)
  4. the nth colour of out of that waypoints

If the parameters are (220020060, 189252201, 3, 1) The answer should be 212078095

  • There's no universally accepted way to get "waypoints" between two colors. Here's my best stab at it: https://stackoverflow.com/a/49321304/5987 – Mark Ransom Aug 16 '22 at 03:32

1 Answers1

1

here is a simpler implementation that is a little easier to follow:

def solution(rgb1 : str, rgb2 : str, waypoints : int, target : int):
    rgb1 = list(map(lambda num : int(num), wrap(rgb1, 3)))
    rgb2 = list(map(lambda num : int(num), wrap(rgb2, 3)))

    return list(map(lambda num : int(num), listLerp(rgb1, rgb2, target / (waypoints + 1))))

def lerp(start : int, end : int, percent : float):
    return (1 - percent) * start + percent * end

def listLerp(start : list[int], end : list[int], perent : float):
    return list(map(lambda num1, num2 : lerp(num1, num2, perent), start, end))

It is a little different because it uses strings as inputs to preserve rgb values like 002345678 without striping the zeros from the front. It also returns the values as an array of ints because it is easier.

omzz15
  • 39
  • 5