Create a program that generates an array of random length with random numbers, then apply a series of rules that alter the array. After the rules have been applied, print the sum of the array unless specified otherwise
The array must be a random length between 5 and 10 inclusive, with random integers between 1 and 20 inclusive. Each array length should have equal probability of happening and each integer should have an equal probability of being picked per element.
The 7 rules
The rules should act as if they were applied in sequence (eg: rule 1 acts before rule 2) and are only applied once. For proof of rule application, the array must be printed to console after each rule application and once before any rules are applied.
- If the array contains a 7, subtract 1 from every element
- If rule 1 is applied and the array now contains a 0, add 1 to each element
- If the array contains a 13, exclude the 13, and all elements that follow, from the array
- If the array contains a 2, exclude all odd numbers
- If the array contains a 20, and the third element is even, return 20 as the sum then terminate. If a 20 is present and the third element is odd, return 20 times the length of the array as the sum then terminate.
- If the sum is greater than 50, remove the last element repeatedly until it is less than or equal to 50
- If the array contains a 16, print the sum in both decimal and hexadecimal.
Here is an initial array,
[20, 2, 5, 7, 14, 8]
Rule 1 can be applied:
[19, 1, 4, 6, 13, 7]
Rule 3 is applied next:
[19, 1, 4, 6]
No other rules are needed, so the program returns 30 as the sum.
- I'm not an experienced code golfer, although I can say my personal record is in Python 3 with 369 bytes.
- The rules don't have to actually be applied in order, but have to act as if they did.