Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using haskell language Problem 4 [45 Points]. The following set of problems is about shuffling of cards, particularly something called the Faro shuffle, where the

image text in transcribedUsing haskell language

Problem 4 [45 Points]. The following set of problems is about shuffling of cards, particularly something called the Faro shuffle, where the stack is broken up into two, and then combined so that a card from one sub-stack is followed by one from the other, and so on. A perfect Faro shuffle breaks up the stack into two sub-stacks of exactly the same size, and then combines them in the manner described above. An out-shuffle results in the top and the bottom cards of the stack remaining the same after the shuffle; an in-shuffle results in these cards becoming the second and the second last cards of the shuffled stack (a) [10 Points]. Write a polymorphic function, shuffle, which takes two lists 11 and 12 representing decks of cards, and returns the result of a combining of the lists. Particularly, the returned list contains the first element of 11, followed by the first element of 12, followed by the second element of 11, and so on. If one of the lists ends before the other, the other list's remaining elements are simply added to the end (b) [7 Points]. Write a polymorphic function, split, which takes as parameters a list and an integer n, indicating the splitting point. It splits the contents of the provided list into two lists, the first with the first n elements of the list (in order), and the second with the remaining elements (again, in order). These two lists are then returned as a list of two lists (c) [8 Points]. Write two polymorphic functions outshuffle and inshuffle, which use shuffle and split functions described above (and possibly additional intermediary functions), and carry out perfect Faro shuffles of the out-shuffle and in-shuffle type. In other words, they take a single stack of an even number of cards, break them up and return the result of applying the required type of Faro shuffle exactly once (d) [10 Points]. Write a polymorphic function, nshuffle, which takes three parameters, a shuffle function (such as outshuffle or inshuffle), an integer indicating how many shuffles to carry out, and a list to shuffle, which is of even length. It then carries out the required number of shuffles on the list, and returns the result. (e) [10 Points]. Write a polymorphic function howManyShuffles, which takes three parameters: a shuffle function (such as outshuffle or inshuffle), and two lists of even size It repeatedly applies the provided shuffle function on the first of the two lists, until it becomes identical to the second list, and returns the count of the number of shuffles that were required As part of your testing of howManyShuffles, find out: a) How many out-shuffles are required to return a stack of 52 cards to its original ordering? b) How many in-shuffles are required to completely reverse a stack of 52 cards? Problem 4 [45 Points]. The following set of problems is about shuffling of cards, particularly something called the Faro shuffle, where the stack is broken up into two, and then combined so that a card from one sub-stack is followed by one from the other, and so on. A perfect Faro shuffle breaks up the stack into two sub-stacks of exactly the same size, and then combines them in the manner described above. An out-shuffle results in the top and the bottom cards of the stack remaining the same after the shuffle; an in-shuffle results in these cards becoming the second and the second last cards of the shuffled stack (a) [10 Points]. Write a polymorphic function, shuffle, which takes two lists 11 and 12 representing decks of cards, and returns the result of a combining of the lists. Particularly, the returned list contains the first element of 11, followed by the first element of 12, followed by the second element of 11, and so on. If one of the lists ends before the other, the other list's remaining elements are simply added to the end (b) [7 Points]. Write a polymorphic function, split, which takes as parameters a list and an integer n, indicating the splitting point. It splits the contents of the provided list into two lists, the first with the first n elements of the list (in order), and the second with the remaining elements (again, in order). These two lists are then returned as a list of two lists (c) [8 Points]. Write two polymorphic functions outshuffle and inshuffle, which use shuffle and split functions described above (and possibly additional intermediary functions), and carry out perfect Faro shuffles of the out-shuffle and in-shuffle type. In other words, they take a single stack of an even number of cards, break them up and return the result of applying the required type of Faro shuffle exactly once (d) [10 Points]. Write a polymorphic function, nshuffle, which takes three parameters, a shuffle function (such as outshuffle or inshuffle), an integer indicating how many shuffles to carry out, and a list to shuffle, which is of even length. It then carries out the required number of shuffles on the list, and returns the result. (e) [10 Points]. Write a polymorphic function howManyShuffles, which takes three parameters: a shuffle function (such as outshuffle or inshuffle), and two lists of even size It repeatedly applies the provided shuffle function on the first of the two lists, until it becomes identical to the second list, and returns the count of the number of shuffles that were required As part of your testing of howManyShuffles, find out: a) How many out-shuffles are required to return a stack of 52 cards to its original ordering? b) How many in-shuffles are required to completely reverse a stack of 52 cards

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

can you solve this for me ?

Answered: 1 week ago