-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp40.pl
30 lines (26 loc) · 788 Bytes
/
p40.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
correct_digit(Number, Nth, Ith, Digit):-
number_chars(Number, Chars),
length(Chars, Jth),
S is Ith + Jth,
Nth =< S,
Index is Nth - Ith,
nth1(Index, Chars, DigitRaw),
number_chars(Digit, [DigitRaw]),
!.
correct_digit(Number, Nth, Ith, Digit):-
number_chars(Number, Chars),
length(Chars, Jth),
Number2 is Number + 1,
I2 is Ith + Jth,
correct_digit(Number2, Nth, I2, Digit).
correct_digit(Nth, Digit):-
correct_digit(1, Nth, 0, Digit).
charles(X):-
correct_digit(1, Digit1),
correct_digit(10, Digit10),
correct_digit(100, Digit100),
correct_digit(1000, Digit1000),
correct_digit(10000, Digit10000),
correct_digit(100000, Digit100000),
correct_digit(1000000, Digit1000000),
X is Digit1 * Digit10 * Digit100 * Digit1000 * Digit10000 * Digit100000 * Digit1000000.