PROLOG MORE PROBLEMS.

Slides:



Advertisements
Similar presentations
YOSI! BLUE (30 sec play) Ball moves to X1 from X2
Advertisements

An Introduction to Calculus. Calculus Study of how things change Allows us to model real-life situations very accurately.
EOG Vocabulary Week of March 28, 2011 Math Words: Fractions and Properties.
Chapter 4 Section 3 Matrix Multiplication. Scalar Multiplication Scalar Product - multiplying each element in a matrix by a scalar (real number) –Symbol:
Maximal Independent Subsets of Linear Spaces. Whats a linear space? Given a set of points V a set of lines where a line is a k-set of points each pair.
Rule Learning – Overview Goal: learn transfer rules for a language pair where one language is resource-rich, the other is resource-poor Learning proceeds.
Discrete Math Recurrence Relations 1.
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Patterns to help you learn your times tables!
Inverting a Singly Linked List Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.
Error-Correcting codes
Outcome: Determine the square root of perfect squares.
4.1 Introduction to Matrices
LA TABLA DEL 5 5X1= 5X2= 5X3= 5X4= 5X5= 5X6= 5X7= 5X8= 5X9= 5X10=
2 x0 0 12/13/2014 Know Your Facts!. 2 x1 2 12/13/2014 Know Your Facts!
2 x /18/2014 Know Your Facts!. 11 x /18/2014 Know Your Facts!
2 x /10/2015 Know Your Facts!. 8 x /10/2015 Know Your Facts!
2.4 – Factoring Polynomials Tricky Trinomials The Tabletop Method.
Strategies – Multiplication and Division
SAT Encoding For Sudoku Puzzles
PERMUTATIONS AND COMBINATIONS
1 Lecture 5 PRAM Algorithm: Parallel Prefix Parallel Computing Fall 2008.
5 x4. 10 x2 9 x3 10 x9 10 x4 10 x8 9 x2 9 x4.
Parallel algorithms for expression evaluation Part1. Simultaneous substitution method (SimSub) Part2. A parallel pebble game.
DIRECTIONAL ARC-CONSISTENCY ANIMATION Fernando Miranda 5986/M
Linear Programming – Simplex Method: Computational Problems Breaking Ties in Selection of Non-Basic Variable – if tie for non-basic variable with largest.
CS 478 – Tools for Machine Learning and Data Mining Clustering: Distance-based Approaches.
The Problem of K Maximum Sums and its VLSI Implementation Sung Eun Bae, Tadao Takaoka University of Canterbury Christchurch New Zealand.
Optimization of order-picking using a revised minimum spanning table method 盧坤勇 國立聯合大學電子工程系.
Multiplication Facts Practice
A Case Study  Some Advice on How to Go about Solving Problems in Prolog  A Program to Play Connect-4 Game.
Variational Inference Amr Ahmed Nov. 6 th Outline Approximate Inference Variational inference formulation – Mean Field Examples – Structured VI.
Probabilistic sequence modeling II: Markov chains Haixu Tang School of Informatics.
Graeme Henchel Multiples Graeme Henchel
The Project Problem formulation (one page) Literature review –“Related work" section of final paper, –Go to writing center, –Present paper(s) to class.
0 x x2 0 0 x1 0 0 x3 0 1 x7 7 2 x0 0 9 x0 0.
C2 Part 4: VLSI CAD Tools Problems and Algorithms Marcelo Johann EAMTA 2006.
Adding & Subtracting Mixed Numbers. Objective: To develop fluency in +, –, x, and ÷ of non-negative rational numbers. Essential Question: How.
Constraint Networks (cont.) Emma Rollón Postdoctoral researcher at UCI April 1st, 2009.
PROLOG 8 QUEENS PROBLEM.
7x7=.
Open to the left column 2 nd flap, and copy the following onto it.
X = 11 X 2 = 9 X = 3 Check: X = 3 x 3 +2 = 11 We can solve this equation by:
Elimination Day 2. When the two equations don’t have an opposite, what do you have to do? 1.
Using square roots to solve quadratic equations. 2x² = 8 22 x² = 4 The opposite of squaring a number is taking its square root √ 4= ± 2.
Substitution Method: 1. Solve the following system of equations by substitution. Step 1 is already completed. Step 2:Substitute x+3 into 2 nd equation.
Step 1: Place x 2 term and constant into the box 2x 2 2 PROBLEM: 2x 2 + 5x + 2.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Simplifying 1 + 2a + b + 1 a + b a + b + 1 2a b + a + b
Sit-In Lab 1 Ob-CHESS-ion
Adding and Subtracting Decimals
Title: Magic Square Challenge
Puzzle A Puzzle B.
Adding and Subtracting Decimals
Solving 2-step equations
Objective: Today we will investigate the ‘magic’ in magic squares.
Lesson 35 Adding and Subtracting Decimals
Magic Squares   10   X.
Tower of Hanoi problem: Move the pile of rings from one peg to another
1.4 Solving Absolute-Value Equations
Adding and Subtracting Decimals
1.4 Solving Absolute-Value Equations
An example of how to represent a problem
Adding and Subtracting Decimals
© T Madas.
Solving Logarithmic Equations
Solving Systems of Equations by Elimination Part 2
Adding and Subtracting Decimals
Tower of Hanoi problem: Move the pile of rings from one peg to another
Lesson 37 Adding and Subtracting Decimals
Presentation transcript:

PROLOG MORE PROBLEMS

MAGIC PUZZLE 3 X 3 3 X 3 square Digits 1 to 9 All rows are equal to 15 All columns are equal to 15 Both diagonals are equal to 15

MAGIC PUZZLE 3 X 3 3 X 3 square X1 X2 X3 X4 X5 X6 X7 X8 X9

MAGIC PUZZLE 3 X 3 Basically only one solution (+symmetries) 2 7 6 2 7 6 9 5 1 4 3 8 Check it out: all totals are 15

MAGIC PUZZLE 3 X 3 All digits should be different All digits are between 1 and 9 Set of equations: X1 + X2 + X3 = 15 (1st row) X4 + X5 + X6 = 15 (2nd row) … X3 + X5 + X7 = 15 (opposite diagonal)

MAGIC PUZZLE 3 X 3 solve(X1,X2,X3,X4,X5,X6,X7,X8,X9) :- member(X1,[1,2,3,4,5,6,7,8,9]), .. alldifferent([X1,X2,X3,….,X6,X7,X8,X9]), X1 + X2 + X3 =:= 15, X3 + X5 + X7 =:= 15.

MAGIC PUZZLE 3 X 3 Would take about 7 minutes to generate the solution Intuitively The average number is 5 There are 3 numbers in each row, column, diagonal Average number (5) * # numbers/row .. (3) = 15  5 is probably in the middle (it is)  hard code 5 in the middle to speed up the code.

TOWERS OF HANOI 3 Towers: left, center, right N disks on left tower All disks have a different diameter A smaller disk must be on top of a bigger disk; it can be alone too We want to move the N disks to the center tower

TOWERS OF HANOI Starting position with 3 disks

TOWERS OF HANOI Solution (general case: N >= 2): To move N disks from A to B using C Move (N-1) disks from A to C using B (recursive call) Move 1 disk from A to B Move (N-1) disks from C to B using A (recursive call) Base Case (only 1 disk to move from A to B; no need for C here):

TOWERS OF HANOI Problem: Can we move N disks from tower A to tower B using tower C? Yes or No answer + printing out all the steps Predicate move takes 4 arguments: the number of disks, and 3 towers

TOWERS OF HANOI Base case: Move 1 disk from A to B move(1,A,B,_) :- write(‘Move top disk from ‘), write(A), write(‘ to ‘), write(B), nl.

TOWERS OF HANOI General case: Move N disks from A to B using C move(N,A,B,C) :- N > 1, M is N – 1, move(M,A,C,B), move(1,A,B,_), move(M,C,B,A).