hi!!! ive been doing some homework for my python class but this one task has been stumping me ;(( I have been given this function to complete based on the task description (which ill add in the images), and ive been fiddling with it trying to get it to work (image 3) but despite running it doesnt pass the test cases. Someone please help it would be very helpful :(((. Also it is dependant on earlier lines of code which i had to complete for earlier tasks but they run fine, however for understanding here they are, they r pretty basic https://paste.pythondiscord.com/behaganice
#help me out pls :(
3 messages · Page 1 of 1 (latest)
There's a lot there to try and understand. Can you narrow this down at all?
For this function that im meant to create here,
the task is asking me to create a function called pixel_flip() that uses recursion to generate all possible new unique images from a given input image by flipping pixels from 0 to 1, considering two constraints: 1) a pixel can only be flipped if there's an adjacent pixel with the value 1, and 2) the number of pixels that can be flipped is limited by a budget.
The main part of the provided code sets up an example 3x3 image and calls the pixel_flip() function with a budget of 2. After executing the function, the code prints the number of flipped possibilities and the unflattened possibilities. and with my code this seems to run fine
`def pixel_flip(lst: list[int], orig_lst: list[int], budget: int, results: list, i: int = 0) -> None:
if i >= len(lst) or budget == 0:
if lst not in results:
results.append(lst)
return
if lst[i] == 0 and check_adjacent_for_one(orig_lst, i):
flipped_lst = lst[:i] + [1] + lst[i+1:]
pixel_flip(flipped_lst, orig_lst, budget - 1, results, i + 1)
pixel_flip(lst, orig_lst, budget, results, i + 1)`