Jug problem.

Slides:



Advertisements
Similar presentations
Paragraph Formatting Lesson 4.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Type Checking.
1.2 Row Reduction and Echelon Forms
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture15: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture11: Variants of Turing Machines Prof. Amos Israeli.
Chapter 1: An Introduction to Computer Science Invitation to Computer Science, C++ Version, Third Edition.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2) ICS 535 Design and Implementation.
Computer Science 1620 Programming & Problem Solving.
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 12 Pointers and linked structures. 2 Introduction  The data structures that expand or contract as required during the program execution is called.
03 - CONCENTRATION - DILUTIONS CHEMISTRY 30 – UNIT 2 – SOLUBILITY – CH. 16 IN TEXT.
Fundamentals of Python: From First Programs Through Data Structures
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
 You can use google docs to construct tests or surveys that can be given online.  Multiple choice, matching, or fill in one word answers work well with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Chapter P Prerequisites: Fundamental Concepts of Algebra
General Programming Introduction to Computing Science and Programming I.
Programming Concepts Chapter 3.
3 DIFFERENTIATION RULES. The functions that we have met so far can be described by expressing one variable explicitly in terms of another variable. 
3 DERIVATIVES. The functions that we have met so far can be described by expressing one variable explicitly in terms of another variable.  For example,,
Problems, Problem Spaces and Search
Equations, Inequalities, and Mathematical Models 1.2 Linear Equations
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma.
Formal Languages, Automata and Models of Computation
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
1 1.2 Linear Equations in Linear Algebra Row Reduction and Echelon Forms © 2016 Pearson Education, Ltd.
BUS 642 Week 2 Exercises Complete the following exercises: In your text book Complete Making Research Decisions 1, page 50 In text answer Terms in Review,
Formal Languages, Automata and Models of Computation
JavaScript/ App Lab Programming:
Understand Problem Solving Tools to Design Programming Solutions
Introduction to Computing Science and Programming I
Chapter 16: Sample Size “See what kind of love the Father has given to us, that we should be called children of God; and so we are. The reason why the.
Algorithms and Problem Solving
Introduction to programming
Microsoft Excel.
Microsoft Office Access 2010 Lab 2
ALGORITHMS part-1.
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Introduction To Flowcharting
CSE 105 theory of computation
Introduction to Computer Programming
7.5 Properties of Exponents and Scientific Notation
Recursion 12-Nov-18.
Lecture 4A Repetition Richard Gesick.
Unit# 9: Computer Program Development
Tips for taking the FCAT.
Number and String Operations
Programming Fundamentals (750113) Ch1. Problem Solving
Recursion 2-Dec-18.
Recursion 2-Dec-18.
Linear Equations in Linear Algebra
Recursion 29-Dec-18.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Theme 2-3 Knowledge Information Processing
Understanding Problems and how to Solve them by using Computers
Chapter 4-8 Scientific Notation
Recursion 23-Apr-19.
Tips for taking the FCAT.
Linear Equations in Linear Algebra
Jug Problem by C-language
Presentation transcript:

Jug problem

What is Jug problem? 4 litter Jug 3 litter Jug Use only 2 kinds of jugs above, get 2 litter water. No tics on each jug.

It’s easy for us…? Please consider. Answer is in the next page…

An example of answer Fill up 3l jug. Move water in 4l jug into 3l jug as much as you can. Empty 3l jug. Move all water in 4l jug into 3l jug. Fill up 4l jug. 2 litter water remains in 4l jug.

Solve this problem by OPS5 Find the order of operation for jugs and water. Of course, we should consider that program and programmer don’t know the answer. What type of data (class) do we need? What rules do we need?

Move water from 4l jug to 3l jug. Image of program Status of jugs Fill up 4l jug Rule Rule Move water from 4l jug to 3l jug. Rule Rule Rule Rule Each rule will be executable depending on the status of jugs. (System choose a rule from executable rules.) Repeating rule execution, finish execution when goal status is satisfied.

What rule do we need? Write all actions for each status of jugs. Ex:If 4l jug is not full, full up 4l jug. Formal expression: if x < 4 then (x,y)-> (4,y) Here, (x,y) means amount of water in 4l and 3l jug respectively. Exercise 1  Write all actions in Japanese(or English) and the formal expression.

Make a rule Convert a written description to a form of rule. (p rule1 (youki ^4l < 4 ^3l <Y>) --> (make youki ^4l 4 ^3l <Y>) ) Ordinary, class should be defined before rule description, however, in this tutorial, we define rule before class definition, then class will be defined depending on the rule description.

Class definition Define classes according to the rule. Consider about the rule in previous page… (literalize youki 4l 3l ) Exercise 2   Convert all actions in Ex.1 into the format of rule in OPS5. Caution: It is insufficient this class definition. If you add some attribute in making rule, you should modify class definition. Making rule and class definition process will be repeated.

Rule for goal Goal status is (x,y)=(2,0), then goal rules will be… (p gole   (youki ^4l 2 ^3l 0) --> (write |Goal!|(crlf)) (halt) )

Infinite loop problem… Infinite loop will occur if you make only rules about jugs. Initial:(0,0) Fill up 4l jug (4、0) Empty 4l jug A rule for avoiding appearance of same status repeatedly is needed not to get into a infinite loop. Fill up 4l jug (0、0) (4、0)

How to deal with the problem If same status is appeared, the last one is not needed. Initial:(0,0) Fill up 4l jugs (4、0) Empty 4l jugs Same status (0、0) This status is cause of a infinite loop. Remove it. Exercise 3: Make a rule of this operation. It is needed some way to compare new or old data.

From here… In following pages, class and rules definition is described. These are just examples. It is not only one way to define class and rules. There are many kinds of programs to solve this problem. In this theme, all programs that can solve this problem are accepted.

Class definition Class definition is following. (literalize youki 4l 3l goukei num) “goukei” keeps the value of the total amount of water. “num” keeps the value to compare old and new data for avoiding infinite loop.

Rule definition Rule example (p rule If 3l jug is not full and total amount of water is less than or equal to 3l, move all water in 4l jug into 3l jug (p rule (youki ^4l {<X> > 0} ^3l {<Y> < 3} ^goukei <= 3 ^num <N>) --> (make youki ^4l 0 ^3l (compute <X> + <Y>) ^goukei (compute <X> + <Y>) ^num (compute <N> + 1 )) (write |4l=0, 3l=|(compute <X> + <Y>)(crlf)) ) *In command part, ”make” command is appropriate, because it can not compare old and new data if “modify” command is used. “^num” is a attribute for compare new or old data. In each making of the data, num is increased.

Rule for Infinite loops (p cut (youki ^4l <X> ^3l <Y> ^goukei <G> ^num <N>) (youki ^4l <X> ^3l <Y> ^goukei <G> ^num < <N>) --> (remove 1) ) 容器の状態が同じデータが2つあり、 1番目の条件要素のnumが<N>で、 2番目の条件要素のnumが<N>より小さいとき、 1番目の条件要素の方が新しいので、削除する

Additional explanation It is almost by implement the explanation so far. If some error occurs, please check spaces between words or symbols.(Space is needed in any borders between words or symbols. Otherwise, errors will occur.) Furthermore, it is able to set priority for each rules. Please refer the additional explanations in the text book.