# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

5 Pages

### Jugs

Course: CS 242, Fall 2009
School: Rochester
Rating:

Word Count: 1078

#### Document Preview

Representation ;;; for N Jug Problem} ;;; Chris Brown} ;;; generate successors for n-jug problem ;;; For N jugs, state is N+1 long list giving the current contents ;;; of all the jugs. ;;; The zeroth jug is an infinite source and sink of water and is thus ;;; treated a little differently. ;;; But that means there is only ONE operation, &quot;pour from jug1 into jug2&quot;, ;;; whose arguments...

Register Now

#### Unformatted Document Excerpt

Coursehero >> New York >> Rochester >> CS 242

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Representation ;;; for N Jug Problem} ;;; Chris Brown} ;;; generate successors for n-jug problem ;;; For N jugs, state is N+1 long list giving the current contents ;;; of all the jugs. ;;; The zeroth jug is an infinite source and sink of water and is thus ;;; treated a little differently. ;;; But that means there is only ONE operation, "pour from jug1 into jug2", ;;; whose arguments (jug1, jug2) are the operation's description (op-desc). ;;; A node is a triple (3-long list) of ;;; (state, op-desc, parent) ;;; disallow ;;; previously generated states (use hashtable) ;;; filling full jug ;;; pouring from empty jug ;;; try to fill jug from self ;; Here's all you need for a hash function (setf visited (make-hash-table :test #'equal)) (defun not-visited (state) (not (gethash state visited))) (defun mark-visited (state) (setf (gethash state visited) 1)) ;;; initialize some obvious variables: capacities is how big the jugs are ;;; (we want jug0 to have nonzero contents for a test later but we don't care ;;; what its capacity is) (defconstant n 3) (setf capacities '(0 3 5)) (setf init-state '(1 0 0) ) (setf goal-state '(1 0 4)) (setf start-node (list init-state nil nil)) (setf nodes nil) ;;; clearly initial state is going to be visited... (mark-visited init-state) ;;; super-simple accessor functions for our node "structure" (defun state-of (node) (car node)) (defun op-of (node) (cadr node)) (defun anc-of (node) (caddr node)) ;;; given a state and two jugs, what is the new state? (defun new-state ( s j1 j2) (let ((cont1 0) (cont2 0) (news nil)) ; remember contents of two jugs (setf cont1 (nth j1 s)) (setf cont2 (nth j2 s)) ; now lots of tests to "do the right thing" (cond ; don't fill self from self ( (= j1 j2) (setf news nil)) ; don't fill from empty jug ( (= cont1 0) (setf news nil)) ; don't fill full jug ( (= cont2 (nth j2 capacities)) (setf news nil)) ; fill j2 from reservoir ( (zerop j1) (setf news (copy-list s)) (setf (nth j2 news) (nth j2 capacities))) ; dump j1 into reservoir ( (zerop j2) (setf news (copy-list s)) (setf (nth j1 news) 0 )) ; finally the "general" case -- ; j1 is empty or has cont j1- (cap(j2)- contj2), whichever is > ; j2 is full or has conts j2 + j1, whichever is < (t (setf news (copy-list s)) (setf (nth j1 news) (max 0 (- cont1 (- (nth j2 capacities) cont2)))) (setf (nth j2 news) (min (nth j2 capacities) ( + cont1 cont2 ))))) ; return new state news ) ;end let ) ;end defun ;;; Generate all successors... examine every (j1, j2) ;;; pair to see which new states to add to sucessor list. ;;; new-state can return nil (ignore) or an already-visited ;;; state (ignore using hash table). (defun gen-succs (node) (let ((succs nil) (newnode nil) (jug1 0) (jug2 0)) (dotimes (jug1 n) (dotimes (jug2 n) ; generate a new state...it's either OK, nil (bad choice of j1,j1) ; or visited (setf newstate (new-state (state-of node) jug1 jug2)) (when (and newstate (not-visited newstate)) ; mark visited and create new node, stick on succ. list. (mark-visited newstate) (setf newnode (list newstate (list jug1 jug2) node )) (setf succs (cons newnode succs)) ))) ; return sucessors to the search routine succs ) ; end let ) ; end defun ;;; results ;(setf sux (gen-succs start-node )) ;(((1 0 5) (0 2) ((1 0 0) NIL NIL)) ((1 0) 3 (0 1) ((1 0 0) NIL NIL))) ;(setf sux1 (gen-succs (car sux ))) ;(((1 3 2) (2 1) ((1 0 5) (0 2) ((1 0 0) NIL NIL))) ((1 3 5) (0 1) ((1 0 5) (0 2) ((1 0 0) NIL NIL)))) ;; OK, seems to make sense. Probably OK to start pushing and popping.... ;;;;;;;;;;;;;;;-----------klip here, below is not all lisp ------------ ;;;;;;;;;;;NOT SO FAST ????? ;;;;;;;;;;;;;;;;; CB: I got the following critique of the above code: S: is student's critique, CB: gives my thoughts: S: There are a couple tiny bugs in the provided code. CB has asked me to post my corrections. CB: thanks for writing them up! S: In new-state, the let statement is missing some parentheses. It should be: (defun new-state (s j1 j2) (let ((cont1 0) (cont2 0) (news nil)) ... CB: I don't think so. In my Lisp manuals, the syntax is something like (let (() () ) The entire rest of your subroutine ) So the code is evaluated in the scope of the let command. Let isn't strictly a function, it's an operator. In any event it actually COULD work either way, but my let was designed to keep variables local. S: new-state also has some logic errors. The ordering of the rules should be: (original order in parentheses) 1. don't fill self from self (1) 2. fill jug2 from reservoir (4) 3. don't fill from empty jug (2) 4. dump jug1 into reservoir (5) 5. don't fill full jug (3) 6. general case (6) The problem with the original logic is that the 0th jug is always empty (at least, in our implementation) so rule 3 was kicking in too early. There was another reason problem, though I don't fully remember it. I think we moved the "dump jug1 into reservoir" rule up since rule 5 was kicking in too early, but I could be wrong. CB: Aha, no, you can't have the 0th jug empty for just that reason. OR you could actually treat it totally differently. I found it easy to give it some amount (in my code above, 1 gallon). That way it does not show up as empty to that rule, but when you do pour from it of course you don't change its quantity: it's got to act ever-full and ever-empty and that's where the two special "rese...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Rochester - CS - 242
Quagent Manipulation through Natural Language UnderstandingComputer Science 242: Artificial Intelligence April 16, 2004Rob Van Dam and Greg BriggsAbstract: Artificial intelligence algorithms designed to simulate an agent with the Quake II environment w
Rochester - CS - 242
Intelligent Autonomous Agents in QuakeDavid Ganzhorn, William de Beaumont University of Rochester February 27th, 2004 Abstract For several weeks we researched and developed agents that interact with Quake2UR, a version of Quake2 that has been modified by
Rochester - CS - 242
Modeling Priority Management Strategies Using UR-Quagents and JESSTom O'NeillHarry GlaserLeland AldridgeCSC242, Dept. of Computer Science, University of Rochester cfw_toneill, hglaser, la002k@mail.rochester.eduAbstractComplex agents with intelligent
Rochester - CS - 242
1 Title: Learning Exercises Authors: Corey Proscia and Alexander Wang, CSC 242, University of Rochester Date: April 21, 2006Abstract: Intelligent agents can maximize utility in repeated trials through learning from past experiences. We compared tabulatio
Rochester - CS - 242
Creating a Computer CopAn Integrated Approach to Recognizing Human Eating Activity Peter Barnum, Dominic Marino, Evan Merz, Matt Pelmear, and Dasun Peramunage Under Randall Nelson University of Rochester May 2003 Abstract Food damage causes untold dollar
Rochester - CS - 242
CS 242 Final Project: Reinforcement LearningAlbert Robinson May 7, 2002IntroductionReinforcement learning is an area of machine learning in which an agent learns by interacting with its environment. In particular, reward signals are provided to the age
Rochester - CS - 242
Artificial Intelligence Beating Human Opponents in PokerStephen Bozak University of Rochester Independent Research Project May 08, 2006Abstract In the popular Poker game, Texas HoldEm, there are never more than three moves an agent can make. However, th
Rochester - CS - 242
A Sudoku SolverCSC 242: Artificial Intelligence Mike SchermerhornIntroduction The standard Sudoku puzzle consists of a nine by nine grid, broken into nine three by three boxes. Each of the eightyone squares must be filled in with a number between one an
Rochester - CS - 242
FinalCSC 242 5 May 2000Write your NAME legibly on the bluebook. Work all problems. Best strategy is not to spend more than the indicated time on any question (minutes = points, total of 140). Open book, open notes. Note to Instructor: use of book may be
Rochester - CS - 242
Second MidtermCSC 242 10 May 2002Write your NAME legibly on the bluebook. Work all problems. Best strategy is not to spend more than the indicated time on any question (minutes = points). Open book, open notes. 1. Grammar: 30 mins. We all remember: Wenn
Rochester - CS - 242
MidtermCSC 242 March 2006Write your NAME legibly on the bluebook. Work all problems. You may use two double-sided pages of notes. Please hand your notes in with your bluebook. The best strategy is not to spend more than the indicated time on any questio
Rochester - CS - 242
Midterm Answers, with FFQ(TM) featureCSC 242 March 2007Write your NAME legibly on the bluebook. Work all problems. You may use two double-sided pages of notes. Please hand your notes in with your bluebook. The best strategy is not to spend more than the
Rochester - CS - 242
WebCT - Start-Up Info for StudentsYour instructor has elected to put course materials online this term using WebCT. This information sheet will help you get started using it.How do I get to my course in WebCT?Open a browser and point tohttp:/webct.roc
Rochester - CS - 242
g C cf bcdeG a E 8A U @ 89 7! 6 5 4 3 ' ) )% ( &quot; '&amp; %\$ # &quot;! 1 20 H X VW UQT RS QIP HG FBCDE S Y `C f C cf bcdeG a E X VW U H UQT RS QIP HG FBCDE S Y `C% \$) \$&quot; ) ) 2 # 2 % \$% ! #&quot; ! # 3 )0 ) &amp; 1 #&quot; ' # #1 &quot; ( ' # #) #) ( )0 P C #bcdeG a E Y X VW S U
Rochester - CS - 173
Descsription and Experience of my projectXiaoqing Tang November 20, 2008This scheme program can solve the N-puzzle problem, though N can't be too large. Generally it should be less than 5. The program can't guarantee for all inputs with N greater or equ
Rochester - CS - 173
Garrett Hall CSC 173 Prolog, Week 3-4 OverviewI created a compact scanner, parser, and evaluator that can calculate basic arithmetic expressions. First it prompts the user to type an expressionparser.pl -? test. Input:Then it outputs the result of each
Rochester - CS - 173
LogicChris Brown October 21, 2008If there is a lot of prose in your answers (as opposed to math), consider using a textprocessor! Write mathematics correctly if in doubt see the courses Helper Tools page in the Resources section of the course homepage.
Rochester - CS - 173
BASIC INFORMATIONXiaoqing Tangxiaoqing.tang@rochester.eduProgramming - CWeek 3-4LISTOFFILESchar_classes.cchar_classes.h(character classes. They're unmodified.)format.c(main program code file of calculating a single expression)grammar(the parse
Rochester - CS - 282
Chapter 7Network Flow7.5 Bipartite MatchingSlides by Kevin Wayne. Copyright @ 2005 Pearson-Addison Wesley. All rights reserved.1MatchingMatching. Input: undirected graph G = (V, E). M &quot; E is a matching if each node appears in at most edge in M. Max
Rochester - CS - 282
CSC282 Fall 2005 Homework #61. CLRS 14.1-5 (p. 307) 2. CLRS 14.2-2 (p. 310) 3. CLRS 14.2-3 (p. 310) 4. CLRS 14.2-4 (p. 310) 5. CLRS 14-1 (p. 318)
Rochester - CS - 282
Recurrence: Solve, Prove, Ruminate.Chris Brown September 14, 20051SolveThe problemT (0) = 0T (n) =1 n1 T (i) + cn, n &gt; 0. n i=0Prove your answer. What is the asymptotic order of T (n)? What can you say about generalizations?2Solution (creating a
Washington - ENVH - 453
ENVH 453 October 7, 2008 Problem Set #2 Due 14 October, 2008 I. Select the single best answer. In some cases, a better answer might exist, but has not been included among the choices. Provide your best answer where appropriate, and be prepared to offer it
SUNY IT - MKT - 301
MKT 301 Principles of Marketing Management Dr. John W. Barnes4:00 5:50 PM MW Donovan 1242 Fall 2004Course Description: MKT 301 provides a description and analysis of the ways in which products move to points of consumption within the global economy. Top
SUNY IT - MKT - 301
MKT 301: PRINCIPLES OF MARKETING MANAGEMENT 10:40-11:50 AM MWF; Donovan1242 Fall 2004 Course Syllabus Instructor: John W. Barnes, Ph.D Office: Donovan 1258A Office Hours: MWF 2:00-4:00 PM; And by appointment. Phone: (315) 792-7807 E-Mail: barnesj2@sunyit.
University of Florida - FIN - 4504
Name _Answer Key_ Section (circle one): 4:05 PM, 6:15 PM, 8:20 PM Homework #3 FIN 4504 Karceski Fall 2003 Due on Wednesday, December 10 at the beginning of class Answer all questions (1 through 22). Multiple choice: Please circle the best/most correct res
Minnesota - JERP - 0001
Parent Education Course Comparison - August 28, 2004FE 5698: Introduction to Parent Education: History and Philosophy (1 cr) Overview of the history, philosophy and implementation of parent education programs. This course is required for employment in th
UCCS - CS - 401
Apache Web Server A PAtCHy server: developed by the Apache group formed 2/95 around a number of people who provided patch files for NCSA httpd 1.3 by Rob McCool. History-http:/www.apache.org/ABOUT_APACHE.html First official public release (0.6.2) in Apri
East Los Angeles College - KX - 08126
Kingston University LondonLibrary ServicesEARTH SCIENCE &amp; GEOGRAPHYEarth Science &amp; Geography Journals: Human GeographyAll journals appear on the main Library Catalogue. Take care to note down when the Library began to subscribe to the journal title to
Delaware - CISC - 2602008
Homework: (each of 5 questions are worth 1.5 grade points: max 7.5 points per homework)1. Write the truth table, then draw the logic diagram for 2-bit (AND, XOR, NOR) and a 1-bit NOT. (you may cut and paste the spare parts on the next slide but must labe
Monmouth IL - HONORS - 210
1 Anna E. Prohaska Honors 210 Professor P. Draves September 28, 2005 Personal Born on February 25, 1986 to Dennis and Mary Ann Prohaska was a little girl, and they called her Anna. Like many college students I have been forced to identify myself by my maj
Oakland University - CSE - 60833
INTRODUCTION TO PARALLEL ALGORITHMS AND PROGRAMMINGCSE 40833/60833 - FALL 2007Instructor Scott Emrich Ofce: 351 Fitzpatrick Hall Phone: (574)631-0353; E-mail: semrich@nd.edu Ofce hours: 10-11:30am, Wed and Fri and by appointment Overview This course wil
Michigan State University - EXAMS - 260
EEP 260: Study Guide for Exam I 2007Topics covered: Whats Development? Whats the Food Problem? How Can LDCs Increase Their Food Production? Source of Questions: Questions will draw on the readings (study questions), lectures, and videos. Structure of the
UMass (Amherst) - RESEC - 460
RESEC 460 - FAMILY ECONOMICS T,Th: 11:15 -12:30 137 Hasbrouck Spring 2003 Professor: M.J. Alhabeeb Office: 212A Stockbridge Hall Phone: 545-5010 Office Hours: T,Th: 3:45-5:00, or by appointment Course Description and Objectives: The major objective of thi
Toledo - GGR - 117
UNIVERSITY OF TORONTO AT MISSISSAUGAGGR117: WHERE ON EARTH?2004/2005 LANDSCAPES OF S-ONTARIO: WHERE?. WHEN. WHAT?. WHY? EXERCISE-1 OBJECTIVES The major objective of this assignment is to learn landscape interpretation, to understand the interrelationshi
UCSD - MAE - 250
MATS 258/MAE 250 - Medical Device Materials and Applications (UC San Diego, Spring 2009)Instructors: Dr. Eunsung Park (Medtronic), Stents, Pacemakers, Implant Materials/Devices Prof. Sungho Jin (UCSD), Advanced/Functional Materials for Implants, Imaging/
Washington - CS - 466
Features High-performance, Low-power AVR 8-bit Microcontroller Advanced RISC Architecture 131 Powerful Instructions Most Single-clock Cycle Execution 32 x 8 General Purpose Working Registers Fully Static Operation Up to 16 MIPS Throughput at 16 MHz On-c
Washington - CS - 466
MAX232, MAX232I DUAL EIA-232 DRIVER/RECEIVERSLLS047H FEBRUARY 1989 REVISED FEBRUARY 2002D D D D D D D D DDOperates With Single 5-V Power Supply LinBiCMOS Process Technology Two Drivers and Two Receivers 30-V Input Levels Low Supply Current . . . 8 mA
Washington - CS - 466
r rTSL230R-LF, TSL230AR-LF, TSL230BR-LF PROGRAMMABLE LIGHT-TO-FREQUENCY CONVERTERSTAOS079 - JANUARY 2006D High-Resolution Conversion of Light D D D D D D D DIntensity to Frequency With No External Components Programmable Sensitivity and Full-Scale Out
Washington - CS - 466
User ManualTDS3000 Series Digital Phosphor Oscilloscopes 071-0274-01This document supports firmware version 2.00 and above.Copyright Tektronix, Inc. All rights reserved. Tektronix products are covered by U.S. and foreign patents, issued and pending. In
Washington - CS - 466
Intel StrongARM SA-1100 MicroprocessorDevelopers ManualAugust 1999Order Number: 278088-004Information in this document is provided in connection with Intel products. No license, express or implied, by estoppel or otherwise, to any intellectual propert
Washington - CS - 466
aFEATURES 2-Axis Acceleration Sensor on a Single IC Chip Measures Static Acceleration as Well as Dynamic Acceleration Duty Cycle Output with User Adjustable Period Low Power &lt;0.6 mA Faster Response than Electrolytic, Mercury or Thermal Tilt Sensors Bandw
Washington - CS - 466
\$SSOL.DWLRQ1RWHV7KLVSDJHDQGDOOOLQNHGGR.XPHQWVKDYHEHHQZULWWHQE\/HLWQHU+DUDOG 7KH.UHDWLRQRIPDNHILOHV 0DNHILOHVSURYLGHWKHSRVVLELOLW\RIWUDQVODWLQJRZQSURJUDPVHIIL.LHQWO\ +HUH,GHV.ULEHKRZ\RXKDYHWRDOWHUWKHPDNHILOHVIRU\RXURZQSURJUDPV PDNHGR.SGI 7KH.RPELQDWLRQRI
Oakland University - EG - 120
Spring 2000 means - EG 120 - Test 1 : 27.5 / 30 Test 2 : 24.0 / 30 Test 3 : 21.3 / 30 Project : 13.5 / 15 (with a max of 18 with extra credit) Final Exam : 35.3 / 50
Cornell - ENGRD - 221
ENGRD 221 Prof. N. Zabaras HOMEWORKS 7 &amp; 8 Handed out: Thursday, 11 October 2007 Due: Monday, 22 October 2007 by 5 pm10/11/2007Notes: 1. Drop HW off in the designated homework box in Upson 123 2. Be sure that you indicate your recitation section (and yo
National Taiwan University - MKT - 846
Decision MakingMKT 846 Professor WestAgenda Lookingback.What clues can our &quot;information processing model&quot; provide? Evaluating Ad Effectiveness The Art of Persuasion Whatshould Levi Strauss &amp; Co. be doing? Relating attitudes to choiceThe role of
Wisc Eau Claire - WCC - 0708
2007 Blugold Open Hosted by University of Wisconsin Eau Claire Whitetail Golf Course September 21st, 2007 = WOMENS TEAM SCORE = = 6k Open = 1. 57 UW-La Crosse ( 24:20 2:01:39) = 1 6 Kristen Howe 24:07 2 7 Meghan Dugan 24:08 3 9 Katelyn Williams 24:13 4 11
Washington University in St. Louis - CSE - 131
CSE 131 Quest 1: Conditional Statements and TestingLab Section C, 2:30-4pm Wednesday, September 29, 2004This is an exam. You may use your notes and you may also use the CSE 131 web site. You may ask the TAs to clarify the directions, but there is to be
Michigan State University - CPS - 360
CPS 360 Review: Worksheet I Part I: Problems These questions are designed to make you restate what the major focus of this course is. 1. In this course, we have said we use computers for one main purpose. What is that purpose?2. In this course, we want t