Skip to content

crabasa/CS231-constraint-programming

 
 

Repository files navigation

constraint-programming

Authors: This code was written by myself and Brandt Dudziak (brandtdudziak)

The code generates solutions to the following problems:

  1. (party.pl) Write a Prolog program that finds a good set of people to invite to a party. You start with the following information:

The names of some people, with their sexes; a list of interesting people; a list of funny people; the party affiliations of some of the people (Democrat, Independent, Republican); some pairs of people who know each other; some pairs of people who dislike each other; and availability of people.

Your task is to write a program to find a list of people who fit as many of the following criteria as you can manage to program:

  1. The guest set must have exactly N members
  2. Each guest must be a male or a female
  3. There must be a day on which each guest is available
  4. At least one interesting person is a guest
  5. At least one funny person is a guest
  6. Numbers of men and women are equal
  7. Everyone knows someone else
  8. No one dislikes anyone else
  9. No mixing Democrats and Republicans

  1. (tea.ecl) "Mrs. Spooner called this morning," said the honest grocer to his assistant. "She wants twenty pounds of tea at 2s. 4 1/2d. per lb. Of course we have a good 2s. 6d. tea, a slightly inferior at 2s. 3d., and a cheap Indian at 1s. 9d., but she is very particular always about her prices."

"What do you propose to do?" asked the innocent assistant.

"Do?" exclaimed the grocer. "Why, just mix up the three teas in different proportions so that the twenty pounds will work out fairly at the lady's price. Only don't put in more of the best tea than you can help, as we make less profit on that, and of course you will use only our complete pound packets. Don't do any weighing."

How was the poor fellow to mix the three teas? (1s = 12d, one shilling is twelve pence).

  1. (barrels.ecl) A man bought an odd lot of wine in barrels and one barrel containing beer, with sizes 15, 31, 19, 20, 16, and 18 gallons. He sold a quantity of the wine to one man and twice the quantity to another, but kept the beer to himself. The puzzle is to point out which barrel contains beer.

  2. (digits.ecl) The nine digits 1-9 are used to form one three-digit and three two-digit numbers so that the product of the three digit number and the first two-digit number is the same as the product of the second and third two-digit numbers. E.g. 158 multiplied by 23 is 3,634, and 79 multiplied by 46 is also 3,634. Write an eclipse program to find all such arrangements of digits, and one that will find the arrangement with the largest product.

  3. (eggs.ecl) A woman was carrying a basket of eggs to market when a passer-by bumped her. She dropped the basket and all the eggs broke. The passer-by, wiching to pay for her loss, asked 'How many eggs were in your basket?'

'I don't remember exactly,' the woman replied, 'but I do recall that whether I divided the eggs by 2, 3, 4, 5, or 6 there was always one egg left over. When I took the eggs out in groups of seven, I emptied the basket.' Find the least possible number of eggs.

  1. (hay.ecl) Farmer Tompkins had five trusses of hay, which he told his man Hodge to weigh before delivering them to a customer. The stupid fellow weighed them two at a time in all possible ways, and informed his master that the weights in pounds were 110, 112, 113, 114, 115, 116, 117, 118, 120, and 121. Now, how was Farmer Tompkins to find out from these figures how much every one of the five trusses weighed singly?

  2. (lights.ecl) Each of the squares in a game grid can be in one of two states, lit (white) or unlit (red). If the player clicks on a square then that square and all squares in the same row and column will toggle between the two states. Each mouse click constitutes one move and the objective of the puzzle is to light all 16 squares with the fewest moves.

  3. (space.ecl) I have allocated distinct positive integers to the letters of the alphabet. By adding up the values of the letters in their names, I have obtained the following scores for some members of the solar system: PLUTO 40, URANUS 36, NEPTUNE 29, SATURN 33, JUPITER 50, MARS 32, EARTH 31, MOON 36, VENUS 39, MERCURY 33, SUN 18. Find the value of PLANETS.

  4. (casks.ecl) A farmer leaves 45 casks of wine, of which 9 each are full, three-quarters full, half full, one-quarter full, and empty. His five nephews want to divide the wine and the casks without changing wine from cask to cask in such a way that each receives the same amount of wine and the same number of casks, and further so that each receives at least one of each kind of cask, and no two of them receive the same number of every kind of cask.

  5. (party.ecl) Redo the party problem (1.) as a constrain program.

About

Solving logic puzzles for Programming Language Paradigms using ECLiPSe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Prolog 100.0%