We all often hear the idiom "walk through the array" to mean "map the function over the following array". However, I need it done (now!), so I want you to run through the array.
How do I run?
Imagine there's a wild pack of wolves behind you
Running through an array is like walking through one, except you can skip over elements. Yes, it's sometimes messy, but it (generally) works. "Which elements are skipped?", you may ask. Well, this is done at random. Let's walk through running through the array!
ebe the current element.
randomgenerate a random float in
random() < 0.5, then you go the next element and then to step 1. (You may generate a number by other means, so long as their is an (ideally) equal chance of skipping and remaining. E.g., you can use choose an element from a two-member set and perform the action based on the result.)
- Otherwise, you perform function
Given an array/list/string like either
A and a number
K, run through the array, adding
K to each member accessed. Output/return this array.
A will only contain non-negative integers, and
K will only ever be a non-negative integers. This is a code-golf, so the shortest program in bytes wins.
Test cases (examples)
K, A => possible K' [1, 2, 3, 4], 0 => [1, 2, 3, 4] [1, 2, 3, 4], 1 => [1, 3, 3, 5] [0, 0, 0, 0], 2 => [2, 0, 0, 2]