I have a programming problem I'm unsure how to solve.
I have two arrays and a function. The function works on array1 on a given range. Array2 contains ranges in array1 that are forbidden to be worked on.

@matrix The way you phrase the problem doesn't make sense to me. What are you trying to accomplish? Write a function that does something with array2's forbidden ranges? What does "works on" mean? What is the interface of the function you are given (parameters and return values and types)?

@johnbudd1350 I want to call the function (the function has 3 arguments, start and end index, and array1) on black parts individually, but the start and end of the red parts is in a different array.

@matrix Ok so for the black parts, you are given a list of ranges right? Your goal is to call the function on these ranges, and ignore the red ones? Why does array2 even matter then? You could just loop through your given ranges, and pass each one into your function along with array1. That would solve it unless I'm missing something
Follow

@johnbudd1350 I'm not given a list of ranges. I only know length of array1.

· · Web · 1 · 0 · 1
@matrix Ok. So what was in array2 again? It has a list of the red ranges?
@matrix Oh, then you just need to loop through array2 and pass in the starting and ending indices, but opposite. So if array2 looks like

[2,4,6,8]

Then you would pass in

(0,2)
(4,6)
(8, array1.length)

@johnbudd1350 Thanks, but how to do it when a range in array2 starts at 0 or ends at end of array1?
If it doesn't you first need to call the function before looping through array2, but you don't know where to end before looping through array2.
I think I might need to make a new array with the acceptable ranges and just loop through that.

@matrix @johnbudd1350 in all cases you must handle
* starting from 0
* ending at end of array1
* cases where indexes exist in both arrays and what that means

it's a fun challenge
@matrix You could check the first and last indices in array2, and change your starting pairs accordingly
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.