5 Added test case for tall matrices edited Mar 23 '18 at 14:55 Andreï Kostyrka 1,22477 silver badges1717 bronze badges (Note that this pseudocode works only for slopes less than 1; for tall grids, a similar treatment should be done, but with a loop over y. See this section for the two cases.) Agatha imagines a matrix as a rectangle, draws a diagonal line in it, and Bresenham’s algorithm determines which elements of a matrix belong to the diagonal. Then she takes their sum, and this is what she wants to implement in as few bytes as possible because she is a poor student and cannot afford large-capacity HDDs to store her code. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5.[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] → 1+5+8+12 → output: 26. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. Agatha imagines a matrix as a rectangle, draws a diagonal line in it, and Bresenham’s algorithm determines which elements of a matrix belong to the diagonal. Then she takes their sum, and this is what she wants to implement in as few bytes as possible because she is a poor student and cannot afford large-capacity HDDs to store her code. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. (Note that this pseudocode works only for slopes less than 1; for tall grids, a similar treatment should be done, but with a loop over y. See this section for the two cases.) Agatha imagines a matrix as a rectangle, draws a diagonal line in it, and Bresenham’s algorithm determines which elements of a matrix belong to the diagonal. Then she takes their sum, and this is what she wants to implement in as few bytes as possible because she is a poor student and cannot afford large-capacity HDDs to store her code. [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] → 1+5+8+12 → output: 26. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. 4 Explained an unclear case edited Mar 23 '18 at 9:50 Andreï Kostyrka 1,22477 silver badges1717 bronze badges Note that some sources (e. g. the Wikipedia’s pseudocode above) use the condition check error≥0.5, while other sources use error>0.5. You should use the originally posted one (error≥0.5), but if the alternative error>0.5 is shorter in your code, then you are allowed to implement it (since this is code golf), but mention it explicitly. See test case 4. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5.[[1,2,3,4,5],[6,7,8,9,10]] → 1+2+8+9+10 (using the ≥ error condition) → output: 30. However, if it would be shorter to use the strict inequality > in your code, then the allowed output is 1+2+3+9+10=25, but you should mention it separately. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. Note that some sources (e. g. the Wikipedia’s pseudocode above) use the condition check error≥0.5, while other sources use error>0.5. You should use the originally posted one (error≥0.5), but if the alternative error>0.5 is shorter in your code, then you are allowed to implement it (since this is code golf), but mention it explicitly. See test case 4. [[1,2,3,4,5],[6,7,8,9,10]] → 1+2+8+9+10 (using the ≥ error condition) → output: 30. However, if it would be shorter to use the strict inequality > in your code, then the allowed output is 1+2+3+9+10=25, but you should mention it separately. [[-0.3,0.5]] → output: 0.2. [[3.1],[2.9]] → output: 6. [[-5]] → output: -5. 3 error in test case edited Mar 23 '18 at 9:27 Andreï Kostyrka 1,22477 silver badges1717 bronze badges [[1,2,3],[4,5,6],[7,8,9]] → 1+5+9 → output: 1415. [[1,2,3],[4,5,6],[7,8,9]] → 1+5+9 → output: 14. [[1,2,3],[4,5,6],[7,8,9]] → 1+5+9 → output: 15. Tweeted twitter.com/StackCodeGolf/status/977100712172769281 occurred Mar 23 '18 at 8:32 2 extra dot edited Mar 23 '18 at 1:01 Andreï Kostyrka 1,22477 silver badges1717 bronze badges 1 asked Mar 23 '18 at 0:44 Andreï Kostyrka 1,22477 silver badges1717 bronze badges