9
The question: Given an a number n
≥ 2, how many distinct pairs of points on an n
-dimensional n x n x n x n x n x n ... x n
lattice, where the coordinates range from 0
to n - 1
, are a distance at least n
apart? The pairs {(2,1,3,1), (3,2,1,3)}
and {(3,2,1,3), (2,1,3,1)}
are not considered distinct from each other, as they consist of the same two points in reverse order. Note that the total number of pairs grows very rapidly. The number of total pairs goes 6
, 351
, 32 640
, 4 881 250
, 1 088 367 840
, etc.
Test cases:
2 -> 0 (all pairs are at most a distance of sqrt(2) < 2 apart)
3 -> 28 (They must either be (2,2,1) or a permutation apart, or (2,2,2) apart. Each corner
has three non-corner (2,2,1) points corresponding to it. And each corner is associated
with a corner pair that is a (2,2,2). Thus. 3.5 * 8 = 28.
4 -> 4,888
5 -> 1,501,948
6 -> 486,039,360 (I would like someone to verify this if possible)
Your code should work for n <= 5, at least in theory. Don't hardcode it, that's a standard loophole.
https://tio.run/##bZLbboMwDIav4Sm8SpWSAONQbRfVuhepqgmRsEaioQpU256e2UkZh/UKYv/@7Pzx9ac/t2Y3DFLVUDPD92EgddeXplJwgGN2EiYMGn3RfTed69aCBm3AluZT@aq76KhPqNOmZ4wZYZKcp8wkmnMhsucXHgZWEShDSFn1rdVlg8f8H7OITZQ77qQTCA6Dr7NuFPwN@XQA35m02lT2QxupvhGKzTG0lB8nBc45ls6jhJlzEjdd8BAQ@dxq9EkR5bH3ZlZO9jyC0fQ1dLcLk0ICISUhRymHN0A/Hcw7gpw/ayhataZTlfcWTzdLCmfB4/dy/RZzHYCqfG7E3a84dU1TlLmcC6umU2OFbzlDLkgj6M4R9EBr7Wqid8j2i@ZYVFCAliga70871d@sAVw4YbhwH1q8tIAEUIo/w8qCXZy/kgtXS6u62WaFhD1sJWy2TMc1w4Xlwy8 – Leaky Nun – 2017-12-21T02:04:40.730
^ a program that can produce results for
n=15
easily – Leaky Nun – 2017-12-21T02:05:03.930https://tinyurl.com/ya2kmb24 <-- ported to C which can calculate up to
n=20
but suffers heavily from overflow – Leaky Nun – 2017-12-21T03:51:25.393How are you measuring distance? Euclidean metric? Or given that it's a lattice are you using L_1? – Peter Taylor – 2017-12-21T09:28:33.653
@PeterTaylor from the test cases, it's clear that we're using Euclidean distance
all pairs are at most a distance of sqrt(2) apart
but that should be specified more clearly. – Giuseppe – 2017-12-21T14:10:51.377