A grid of varying size only containing numbers in the range
00-99, the following four characters:
<, and spaces to fill (and new-lines of course).
The result of the sum (integer) when you follow the path.
How does this work?
You start at the arrow with the highest number, and follow the path the arrows point to.
For each of the four arrows we'll do a different arithmetic calculation:
>= Addition (+);
<= Subtraction (−);
^= Multiplication (* or × or ·);
v= Real / Calculator Division (/ or ÷);
(NOTE: The symbols between parenthesis are just added as clarification. If your programming language uses a completely different symbol for the arithmetic operation than the examples, then that is of course completely acceptable.)
- You can choose the input (to some extent). A string-array would be most logical I think, but a symbol/newline-separated single string is also fine. (Full functions as input that are simply executed in the actual code snippet aren't allowed!)
- Trailing spaces for the input are optional.
0-9will have a leading
0so all numbers plus arrow are of an equal three-character length.
The number & arrow will always have the following format:
Dbeing a digit;
Abeing one of the four arrows).
- You use the current value with the previous arithmetic operation (the example below explains this better).
- The final arithmetic operation can be ignored because of the rule above.
- It is possible to have DDA's in the input-grid that aren't being used in the path to the resulting sum.
- There won't be any test-cases for arrows that form a loop.
- There won't be any test-cases for dividing by 0.
- There won't be any test-cases where dividing creates a decimal sum-result. You only have to worry about integers.
- EDIT: Since there weren't any answer yet, I decided to change the grids slightly to perhaps make it easier. I know this is usually not recommended to do with challenges, but since no answers were given yet, I think this will make it slightly easier, giving more (/any) answers:
The spaces between de DDA's are random. There could even be no spaces in between at all.All DDA's and spaces are grouped per three. Also, it is possible to have no spaces between DDA's at all.
94> 66v 05v 08< 43> 03> 00^
Path it follows:
Path it follows | Current sum value ________________________________________ 94> | 94 (highest value) 66v | 160 (+) 08< | 20 (/) 05v | 15 (-) 03> | 5 (/) 00^ | 5 (+) 43> | 215 (*) '>' after 43 is ignored because it's the last number
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
94> 66v -> 215 05v 08< 43> 03> 00^ 77> 80v55^02< -> -19 20> 14^ 22>11>15>80>14v -> -16 18^17> 10v 00^ 90v43^02v 07^11<15<22v01< 99>98>97>96>95>94v -> 102 93>92> 91v 03<