Reputation: 55
I am working on the question from this site, one of the question is asking to return Goldbach conjecture in a given range.
My answer works fine for small ranges, but for large range (e.g. 2 - 2000), it only return part of the solution like the following:
[(2, (2, 0)); (4, (2, 2)); (6, (3, 3)); (8, (3, 5)); (10, (3, 7));
(12, (5, 7)); (14, (3, 11)); (16, (3, 13)); (18, (5, 13)); (20, (3, 17));
(22, (3, 19)); (24, (5, 19)); (26, (3, 23)); (28, (5, 23)); (30, (7, 23));
(32, (3, 29)); (34, (3, 31)); (36, (5, 31)); (38, (7, 31)); (40, (3, 37));
(42, (5, 37)); (44, (3, 41)); (46, (3, 43)); (48, (5, 43)); (50, (3, 47));
(52, (5, 47)); (54, (7, 47)); (56, (3, 53)); (58, (5, 53)); (60, (7, 53));
(62, (3, 59)); (64, (3, 61)); (66, (5, 61)); (68, (7, 61)); (70, (3, 67));
(72, (5, 67)); (74, (3, 71)); (76, (3, 73)); (78, (5, 73)); (80, (7, 73));
(82, (3, 79)); (84, (5, 79)); (86, (3, 83)); (88, (5, 83)); (90, (7, 83));
(92, (3, 89)); (94, (5, 89)); (96, (7, 89)); (98, (9, 89)); (100, (3, 97));
(102, (5, 97)); (104, (3, 101)); (106, (3, 103)); (108, (5, 103));
(110, (3, 107)); (112, (3, 109)); (114, (5, 109)); (116, (3, 113));
(118, (5, 113)); (120, (7, ...)); ...]
I tried to use the solution provided by the website, but same thing happens. I wonder if there is a way to return the complete list of solutions.
Thanks!
Upvotes: 2
Views: 80
Reputation: 3739
This is because the toplevel doesn't show values that are too long. You can change this lenght by using a pragma:
#print_length n;;
The other solution, perhaps better, is to write your own printing function. ;)
Upvotes: 3
Reputation: 66818
I think you mean that the toplevel is only showing a prefix of the list. You can solve this by writing your own code to show the list.
Something like this would work:
let p (a, (b, c)) = Printf.printf "(%d, (%d, %d))\n" a b c
let printMyList l = List.iter p l
Upvotes: 5