05-04-2017 08:00 AM
Hey guys,
I've stumbled onto a small problem. I have an array that contains 500 elements with values between 1 and 10. What I want to do is find all the values below a certain threshold and multiply them with a constant.
So for example I want to find all the elements with a value lower than three and then multiply them by two, all the other elements that have a value higher than three stay the same as before.
Is there a simple way of doing this?
Kind regards,
Victor
Solved! Go to Solution.
05-04-2017 08:07 AM
Use a for loop with auto-indexing enabled on the input array tunnel, do the comparison and multiplication, and then auto-index it back into an array.
05-04-2017 08:07 AM
Yes. A For Loop that auto-indexes on the array. It either feeds the element through, or multiplies it by two.
05-04-2017 08:48 AM - edited 05-04-2017 08:53 AM
Just because I need kudos today
EDIT: I hope I beat GerdW
05-04-2017 08:49 AM - edited 05-04-2017 08:50 AM
05-04-2017 09:47 AM - edited 05-04-2017 09:50 AM
Implemented the way the problem was stated.
The other solutions look cool and may not use loops, but they use some unusual "hacks" to do that. It may not be as clear to someone else reading the code as to what is going.
I'd prefer clarity.
Question to original poster.
You said values less than 3 get multiplied. Values greater than 3 stay the same.
What do you want done when the value EQUALS 3?
05-04-2017 10:03 AM
i want kudos too 😉
05-04-2017 10:07 AM - edited 05-04-2017 10:07 AM
@jwscs wrote:
i want kudos too 😉
Sorry. No kudoes. A conditional tunnel determines whether a value is included in the output array or not. You created code that only outputs an array of values that were multiplied discarding all the ones that weren't.
05-04-2017 10:13 AM
you got me 😉
05-04-2017 10:25 AM
@RavensFan wrote:
The other solutions look cool and may not use loops, but they use some unusual "hacks" to do that. It may not be as clear to someone else reading the code as to what is going.
HACK? when did "Elementary Arithmetic" operations become HACKS?