15
1
Description of the problem
Imagine a quarter of an infinite chessboard, as in a square grid, extending up and right, so that you can see the lower left corner. Place a 0 in there. Now for every other cell in position (x,y)
, you place the smallest non-negative integer that hasn't showed up in the column x
or the row y
.
It can be shown that the number in position (x, y)
is x ^ y
, if the rows and columns are 0-indexed and ^
represents bitwise xor
.
Task
Given a position (x, y)
, return the sum of all elements below that position and to the left of that position, inside the square with vertices (0, 0)
and (x, y)
.
The input
Two non-negative integers in any sensible format. Due to the symmetry of the puzzle, you can assume the input is ordered if it helps you in any way.
Output
The sum of all the elements in the square delimited by (0, 0)
and (x, y)
.
Test cases
5, 46 -> 6501
0, 12 -> 78
25, 46 -> 30671
6, 11 -> 510
4, 23 -> 1380
17, 39 -> 14808
5, 27 -> 2300
32, 39 -> 29580
14, 49 -> 18571
0, 15 -> 120
11, 17 -> 1956
30, 49 -> 41755
8, 9 -> 501
7, 43 -> 7632
13, 33 -> 8022
vaguely related
– RGS – 2020-02-26T22:16:58.0772Interesting, I'm curious if there's a bitwise way to express this without summing everything. – xnor – 2020-02-26T22:20:46.183
We'll see what you guys come up with :) – RGS – 2020-02-26T22:21:17.310
3
The main diagonal is A224923.
– Arnauld – 2020-02-26T22:56:01.173