I want to write about prolog.
When we started to learn prolog in the beginning of term I asked my tutor, “what is the point of learning prolog?” before, I never heard about prolog, I guess you the reader may have no idea what is prolog, I can say that although it may look useless but indeed it is very useful and interesting.
Those days, we have Computing Science assignment which prolog is most important part of it.
After doing the hardest part of the assignment, I spent 3 days, just for writing 5 lines of code, I asked different people for hint, I searched a lot, even I watched 60 minutes a video of prolog tutorial but still none of them helped me. In the fourth day I didn’t attempt to write any code, I was thinking to may just leave it, but I decided to have a day rest and start from beginning and think clear also use imagination.
Finally I found the answer; it was one of the unforgettable moments in my student life.
If you have any questions about prolog you may send me an email, I will reply as soon as I can.

Take the digits 1,2,3 up to 9 in numerical order and put either a plus sign or a minus sign or neither between the digits to make a sum that adds up to 100. For example, one way of achieving this is:

1 + 2 + 34 - 5 + 67 - 8 + 9 = 100, which uses six plusses and minuses. What is the fewest number of plusses and minuses you need to do this? I love to challenge myself with these kind of puzzles, so I solved this and here is how:

We have 9 numbers [1 to 9] and also we have three possible separators [+, - and nothing] which to fill the gap between numbers we have 8 combinations of separators, e.g. we have 1+2+3+4+5+6+7-89 which in this case we have six times plus, one minus and one time nothing.

So, I need to find all possibilities of combination which total is: 6561

Then, hook the possible combinations into numbers and check the total, easy enough. Now print the solution.

I have written this algorithm in PHP but ea…

## Comments

## Post a Comment