diff --git a/38 b/38 new file mode 100755 index 0000000..fa518d4 Binary files /dev/null and b/38 differ diff --git a/38.c b/38.c new file mode 100644 index 0000000..5657510 --- /dev/null +++ b/38.c @@ -0,0 +1,57 @@ +#include +#include +#include + +bool hasUniqueDigits (int i) { + int a = i % 10; + i /= 10; + int b = i % 10; + i /= 10; + int c = i % 10; + i /= 10; + int d = i % 10; + return a != b && a != c && a != d && + b != c && b != d && + c != d; +} + +bool isPandigital (int i, int j) { + int a = i % 10; + i /= 10; + int b = i % 10; + i /= 10; + int c = i % 10; + i /= 10; + int d = i % 10; + + int e = j % 10; + j /= 10; + int f = j % 10; + j /= 10; + int g = j % 10; + j /= 10; + int h = j % 10; + j /= 10; + int k = j % 10; + + return a != 0 && b != 0 && c != 0 && d != 0 && e != 0 && f != 0 && g != 0 && h != 0 && k != 0 && + a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != k && + b != c && b != d && b != e && b != f && b != g && b != h && b != k && + c != d && c != e && c != f && c != g && c != h && c != k && + d != e && d != f && d != g && d != h && d != k && + e != f && e != g && e != h && e != k && + f != g && f != h && f != k && + g != h && g != k && + h != k; +} + +int main () { + int n = 9182; + for (int i = 9183; i <= 9876; i++) { + if (hasUniqueDigits (i)) { + if (isPandigital (i, 2 * i)) + n = i; + } + } + printf ("%d%d\n", n, 2 * n); +} diff --git a/38.txt b/38.txt new file mode 100644 index 0000000..3862fae --- /dev/null +++ b/38.txt @@ -0,0 +1,27 @@ +Given a certain tuple (1, 2, ..., n), only a certain range of integers i are allowed to produce a nine-digit concatenation. +(1, 2): 1 * _ _ _ _ = _ _ _ _ + 2 * _ _ _ _ = _ _ _ _ _ + 5000 <= i <= 9999 +(1, 2, 3): 1 * _ _ _ = _ _ _ + 2 * _ _ _ = _ _ _ + 3 * _ _ _ = _ _ _ + 100 <= i <= 333 +(1, 2, 3, 4): 1 * _ _ = _ _ + 2 * _ _ = _ _ + 3 * _ _ = _ _ + 4 * _ _ = _ _ _ + 25 <= i <= 33 +(1, 2, 3, 4, 5): 1 * _ = _ + 2 * _ = _ _ + 3 * _ = _ _ + 4 * _ = _ _ + 5 * _ = _ _ + 5 <= i <= 9 +(1, 2, 3, 4, 5, 6): 1 * _ = _ + 2 * _ = _ + 3 * _ = _ + 4 * _ = _ _ + 5 * _ = _ _ + 6 * _ = _ _ + i == 3 +In the given example, 9 x (1, 2, 3, 4, 5) = 918273645. Then to produce a larger concatenation, with the given restrictions on i, we can only use i x (1, 2), where 9183 <= i <= 9876. Then only 693 values of i need to be tested.