A theatre booking system uses a logical relation to describe all combinations of values satisfying its stated conditions. Its relation booking(a,c)\operatorname{booking}(a,c)booking(a,c) holds when aaa is the number of adult tickets, ccc is the number of child tickets, and all of these conditions hold:
The logic engine can query this relation with both ticket counts unknown. Count each distinct ordered pair (a,c)(a,c)(a,c) once; search order is irrelevant.
Find the number of valid ordered pairs and the largest adult-ticket count among those pairs. Then add the further constraint that exactly 12 tickets were purchased, and find the adult-ticket count for the resulting booking. Give all three answers as whole-number counts, to zero decimal places.
Unlock full course notes by signing up
Tracing a loop and a pipeline side by side
A shop applies a 2-dollar discount to every item priced above 5 dollars and totals the discounted prices. Two versions of the code, one procedural and one functional, process the same list of prices.
Complete the table with whole numbers. Values of total are in dollars.
State and side effects in a counter class
Consider this Python code, which defines a class and then makes three method calls on two objects.
Which of the following statements are true? Select all that apply.
Reusing pure results without changing the total
A shop calculates an order quote using a pure function: it returns the same result for the same input and produces no observable side effects. For a positive integer quantity qqq, its quote in dollars is
The application adds the quotes for three separate orders by evaluating
Counting Prolog answers for a recursive rule
A Prolog program records which course is a direct prerequisite of another and defines a recursive rule for indirect prerequisites.
The query ?- leads_to(cs101, C). is entered, and the user keeps asking for more answers until Prolog reports there are no more. Prolog uses its standard search: clauses top to bottom, goals left to right, with backtracking. How many answers for C does Prolog report in total, counting any repeated value each time it appears? Give your answer as a whole number.