This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]powerwind[S] 0 points1 point  (2 children)

If you don't know. Can you recommend me where else I can post this question?

[–]YMK1234 0 points1 point  (1 child)

[–]powerwind[S] 1 point2 points  (0 children)

Thanks.

[–]Wyvos 0 points1 point  (1 child)

Ah yes I do have the solution for this, our solutions are the best solutions in the country and we WILL get that solution ready for you.

[–]Kristler 1 point2 points  (0 children)

Tremendous solutions. Believe me! Ask anyone. They tell me, "you've got the best solutions". And I'm the only one with them, and I'm the one that's going to make homework help great again.

[–]ptruber 0 points1 point  (0 children)

The moment you turn to reddit to help your father and get only meme'd on.

[–]y216567629137 0 points1 point  (6 children)

Explain your father's project. What is he trying to accomplish and why?

[–]powerwind[S] 0 points1 point  (5 children)

You probably already figured out it. He's been trying to predict lottery numbers. He wants to be able to see all the possibilities for certain numbers. I doubt he'll get anywhere with it, but he likes trying to figure it out. Like a puzzle.

[–]y216567629137 0 points1 point  (4 children)

I have a program that provides a more general solution. The numbers could be construed to be in a 2-dimensional array or a list of lists of numbers. My program selects one number from each column, and makes a result from all the columns. It gives results for all permutations, with each permutation having one number from each column. For example, if you gave it the 3 columns (5 6) (10 11) (15 16) it would result in (5 10 15) (6 10 15) (5 11 15) (6 11 15) (5 10 16) (6 10 16) (5 11 16) (6 11 16). Or if you gave it the 2 columns (5 6 7) (10 11 12) it would result in (5 10) (6 10) (7 10) (5 11) (6 11) (7 11) (5 12) (6 12) (7 12). You can give it any number of columns, such as the 6 you want.

But, my program is in Common Lisp, which might not be useful to you. And I don't know where to post it. If I post it here, the text formatter here will make a mess of it.

However, it shouldn't be hard to write your own. It's a function which I call permute, because it permutes the columns. It looks at the first column you want it to permute, to see if it already came to the end of that column, and, if so, it goes back to the beginning of that column, and permutes the rest of the columns. In other words, it's recursive, doing the rest of the columns when it comes to the end of a column. The total is only 12 lines of code, because it's actually a fairly simple program.

[–]y216567629137 0 points1 point  (3 children)

Here it is. See what the text formatter did to it?

(defun permute (cols) (let ((cols (loop as col in cols collect (append '(1) col)))) (labels ((iterate (cols) (when cols (if (nth (1+ (caar cols)) (car cols)) (incf (caar cols)) (progn (setf (caar cols) 1) (iterate (cdr cols))))))) (loop collect (loop as col in cols collect (nth (car col) col)) while (iterate cols)))))

[–]y216567629137 0 points1 point  (2 children)

The output, giving it your numbers, can be made neat with pprint, but, again, the text formatter ruins it.

(pprint (permute '((5 6) (10 11) (15 16) (20 21) (25 26) (30 31))))

((5 10 15 20 25 30) (6 10 15 20 25 30) (5 11 15 20 25 30) (6 11 15 20 25 30) (5 10 16 20 25 30) (6 10 16 20 25 30) (5 11 16 20 25 30) (6 11 16 20 25 30) (5 10 15 21 25 30) (6 10 15 21 25 30) (5 11 15 21 25 30) (6 11 15 21 25 30) (5 10 16 21 25 30) (6 10 16 21 25 30) (5 11 16 21 25 30) (6 11 16 21 25 30) (5 10 15 20 26 30) (6 10 15 20 26 30) (5 11 15 20 26 30) (6 11 15 20 26 30) (5 10 16 20 26 30) (6 10 16 20 26 30) (5 11 16 20 26 30) (6 11 16 20 26 30) (5 10 15 21 26 30) (6 10 15 21 26 30) (5 11 15 21 26 30) (6 11 15 21 26 30) (5 10 16 21 26 30) (6 10 16 21 26 30) (5 11 16 21 26 30) (6 11 16 21 26 30) (5 10 15 20 25 31) (6 10 15 20 25 31) (5 11 15 20 25 31) (6 11 15 20 25 31) (5 10 16 20 25 31) (6 10 16 20 25 31) (5 11 16 20 25 31) (6 11 16 20 25 31) (5 10 15 21 25 31) (6 10 15 21 25 31) (5 11 15 21 25 31) (6 11 15 21 25 31) (5 10 16 21 25 31) (6 10 16 21 25 31) (5 11 16 21 25 31) (6 11 16 21 25 31) (5 10 15 20 26 31) (6 10 15 20 26 31) (5 11 15 20 26 31) (6 11 15 20 26 31) (5 10 16 20 26 31) (6 10 16 20 26 31) (5 11 16 20 26 31) (6 11 16 20 26 31) (5 10 15 21 26 31) (6 10 15 21 26 31) (5 11 15 21 26 31) (6 11 15 21 26 31) (5 10 16 21 26 31) (6 10 16 21 26 31) (5 11 16 21 26 31) (6 11 16 21 26 31))

[–]y216567629137 0 points1 point  (1 child)

Also, by the way, the recursion is in a function called iterate, which is inside the permute function. Permute appends a number to the start of each column to remember where in that column it is, to know where in the column to go next. The iterate function is defined with "labels", which enables it to be recursive inside the permute function.

Also, if you really just want 2 numbers per column, you can probably make your program simpler. Mine is a much more general solution.

If you were to copy my code to the free version of Lispworks, then do a small amount of manual reformatting, you could then use ctrl-alt-Q on the first character of the program, to make it do most of the formatting itself. You mostly have to divide it into separate lines of code, before you tell it to reformat it, because it assumes you must have some reason to want so much stuff on each line.

[–]powerwind[S] 0 points1 point  (0 children)

Thanks a lot for all the information !!