Write a function in prolog pragramming languaged named, "ionah", that takes a single number as input and prints out the solution to the inverted disk problem for that many disks. This is the problem of moving a stack of k disks of increasing size from bottom to top, from the first peg to the third peg with another peg that may be used as well, subject to the condition that a smaller disk is never put on top of a larger one, and only one disk may be moved at a time. Here is a sample run:
?- ionah(3).
move disk from peg 1 to peg 3
move disk from peg 1 to peg 2
move disk from peg 3 to peg 2
move disk from peg 1 to peg 3
move disk from peg 2 to peg 1
move disk from peg 2 to peg 3
move disk from peg 1 to peg 3
Yes
?-
ionah(X):-mov(X,1,3,2).
mov(1,X,Y,_) :-
write('Move disk from peg '),
write(X),
write(' to peg '),
write(Y),
nl.
mov(N,X,Y,Z) :-
N>1,
M is N-1,
mov(M,X,Z,Y),
mov(1,X,Y,_),
mov(M,Z,Y,X).
The output is
Write a function in prolog pragramming languaged named, "ionah", that takes a single number as input...
write in c programming language . question 5.36 Fibonaco for its rets ing terms, a) Write a warruse function fibonacci(n) that calculatus 0, 1, 1, 2, 3, 5, 8, 13, 21,... (n) that calculates the n" Fib begins with the terms and 1 and has the property preceding terms. a) Write a cand unsigned long long int for i number. Use unsigned int for the function's paramete her that can be printed on your system. type. b) Determine the largest...
Write the recursive MIPS code (with abundant explanatory comments) for the Tower of Hanoi problem of transferring a stack of N disks (smaller sized disks stacked over the larger sized ones) from a source peg to a destination peg via a third (temporary rest peg) under the constraints: 1. Only one disk is moved at a time from one peg to another 2. At no time, a larger disk will sit on a smaller one.
Describe a recursive algorithm for solving the Towers of Hanoi puzzle for an arbitrary n (see Creativity Exercise C-5.16 for more details). C-5.16 In the Towers of Hanoi puzzle, we are given a platform with three pegs, a, b, and c, sticking out of it. On peg a is a stack of n disks, each larger than the next, so that the smallest is on the top and the largest is on the bottom. The puzzle is to move all...
Part A [50] in c++ A toy that many children play with is a base with three pegs and five disks of different diameters. The disks begin on one peg, with the largest disk on the bottom and the other four disks added on in order of size. The idea is to move the disks from the peg they are on to another peg by moving only one disk at a time and without ever putting a larger disk on...
Towers of Hanoi (15 points) Given: n disks, all of different sizes the size of the ith disk is į .3 pegs - A, B, C the number of pegs might change in a future version of the game Inally, all the disks are stacked on peg A Requirement: Never place a larger disk on top of a smaller disk (disk 5 is larger than disk 4, etc.) Objective: Move the disks from peg A to peg C Input: n,...
In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one).You have the following constraints: (A) Only one disk can be moved at a time. (B) A disk is slid off the top of one rod onto the next rod....
Please write a recursive Java program to solve the Tower of Hanoi game for n disks on pole A. Please read the textbook page 176 – 180 to fully understand this game or puzzle. The game consists of n disks and three poles: A (the source), B (the destination), and C (the spare). Initially, all the disks are on pole A. The game is to move all disks (one by one) from pole A to pole B using pole C...
Write a Python function named print_nums that takes a single parameter, a list of float values, and prints out the list on a single line.enclosed in brackets, each value with three places after the decimal point, the values separated by two spaces. You do not have to provide comments for this code. Example 1: print_nums([3/3, 4/3, 573, 6/3]) prints: [1.000 1.333 1.667 2.000] Example 2: print_nums([3]) prints: [3.000] Example 3: print_nums([]) prints: []
Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...
Java Program Write a method called reverseBottomHalf that accepts a Stack of integers as a parameter and reverses only the values in the bottom half of the Stack. For example, if a Stack containing the values [1, 2, 3, 4, 5] were passed in (with 1 at the bottom and 5 at the top), the Stack would be changed to [2, 1, 3, 4, 5] (with 2 at the bottom and 5 at the top) after this method was called...