10 points total, plus up to 3 points extra credit
X = 10 X = -10
repeat(squid,4,[squid,squid,squid,squid])should succeed. The goal
repeat(clam,3,L)should succeed with
L = [clam,clam,clam](and no other possibilities). Also try repeat(squid,N,L) and repeat(X,N,L).
Hint: if you get a message ``Fatal Error: Trail overflow'' for any of the possibilities, you should put in an additional condition on one of your rules. (Are you searching for a list with a negative length?)
cp ~borning/clpr/resistors.clpr .You shouldn't need to modify this file. You can then read in both the resistors file and your own additions (say in a file hw9.clpr) using this command in CLP(R):
[resistors, hw9].
Define one or more rules that define how a switch operates. The rule(s) should take 3 arguments: 2 leads, and a position. The position will be either open or closed, and your switch should define the appropriate constraints depending on the position.
Using the switch and the other rules in resistors.clpr you can define a simple_circuit rule that builds the following circuit. This rule should have two arguments: the state of the switch, and the amperes shown by the ammeter.
To help you get started here's a definition:
simple_circuit(State,Amps) :- battery(B1,B2,10), ammeter(A1,A2,Amps), switch(S1,S2,State), resistor(R1,R2,100), electrical_ground(G), connect([B2,A1]), connect([A2,S1]), connect([S2,R1]), connect([R2,B1,G]).Try invoking simple_circuit with the switch open, and then closed; and also with the switch state left as a variable.
Use this rule to find the current when S1 is open and the other switches are closed. Also use the rule to find all settings for the switches such that the current is at most 0.04 amperes. Finally, if you closed all the switches for this circuit with a real device, something bad would probably happen. What happens with the CLP(R) program? Why? (Put your answer to this question in a comment.)
attu% script hw9-transcript attu% echo "Name: <your name here>" Name: <your name here> attu% clpr ...... attu% ^d Script done, output file is hw9-transcript
Then use the SPDT switch to build and test this circuit:
~borning/clpr/ibm-progs/smmThis solves the cryptarithemtic puzzle SEND+MORE=MONEY. Adapt this to solve DOUBLE+DOUBLE+TOIL=TROUBLE.