Turn this lisp code into ML code:
(defun mult (x)(cond ((null x) 5)
((consp x) (* (car x) (mult (cdr x))))))
(print (mult '(1 7 9)))
def mult(x):
if len(x)==0:
return int(5)
else:
return x[0]*mult(x[1:])
print(mult([1,7,9]))
Turn this lisp code into ML code: (defun mult (x)(cond ((null x) 5) ((consp x) (*...
7. Suppose that the equal 1ists function (page 49 of Sebesta) is called with the lists ((A (B)) (C) ) and ((A (B)) (C)) as the arguments. How many calls of equal lists will be performed altogether, including the original call and all recur- sive calls? The following is an example of a Lisp program: Lisp Example function The following code defines a Lisp predicate function that takes two lists as arguments and returns True ;if the two lists are...
Common LISP function Give a trace of the function when the input is 5 (defun guess (N) (if (or (zerop N) (= N 1)) 1 (+ (guess (- N 1)) (guess (- N 2))))) I have ran this code and with the following commands and i get this: > (trace) >(guess 5) 1. Trace: (GUESS '5) 1. Trace: (GUESS ==> 8 8 Is this correct or am i doing something wrong plz help.
Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func) (cond ((null? input-list) '()) ((func (car input-list)) (cons (car input-list) (filter (cdr input-list) func))) (else (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...
JAVA turn this psuedo code into java code. USING NO LOOPS! ALL LOOPS MUST BE TURNED INTO RECURSIVE CALLS. English: 1. Prompt for and read a number between 1 and 5. Repeat this step until the input is 1..5. 2. Repeat the following multiple times according to the number read in step 1. a. Read in a list of integers ending with a 0. The 0 marks the end of the input and is not considered part of the list...
Complete the mult() and printArr() functions
#include <iostream> using namespace std; void init(int arr]05], int x)t //initialization loop for row 1 and 2 for(int i = 0; i < 2; i++){ arr i][j] x; void mult(int arr JSD //multiply the elements of row 2 by row 1, and store result in row3 void printArr int arr ][5]) // a loop to print out all the elements of the array int main) int arr[3105] 31 int x 32 34 // initialize...
In Lisp 2. Code the function (replaceIn list possibleList repValue) which constructs a new list. It examines list for occurrences of any of the atoms from the possibleList. Those are replaced with repValue. This only examines the top-level items in list. Example: > (replaceIn '(P A T T E R) '(T R) 'S) (P A S S E S) 3. Code the function (insertAfter list atm insValue) which constructs a new list by inserting the specified insValue into the list...
2 of these blocks of code will produce an error if run. Find each statement with an error in it, describe the error and what behavior it will produce, and describe generally how you would fix it. print ("block 1" strl-"INST 126 is my first Python course" print (strl[-6:len Thu, Apr 11, 2019 9:38 PM it 6 characters of the string list1 = str1 . split() # split into words print (list 1 [len (list 1))) # get last word...
Python
Complete the player_turn() function that completes a single turn of the game Tic-Tac-Toe (also called Noughts and Crosses). The function takes 3 parameters: 1. The first parameter is called board. It is a list of length 3, where each entry is a string with 3 characters representing a row on a Tic-Tac-Toe board. Each character in a row represents a slot on the Tic-Tac-Toe board with the "#" character indicating an empty slot. An empty board looks like this:...
Question 16 What is the value of x after the following code is executed? X = 7 If x < 7 X = x + 1 X = x + 2 7 9 10 8
47. (2 points) What will the following code print? my-list-on"n) for n in range( 5) İf(n.nr%2--ol print(my_list) Answer Assume that the variable data refers to the list [5, 3, 7). Write the value of the following expressions for questions 48-49. 48. (1 points) datal-11 Answer: 49. (1 points) 0 in data Answer: 50. (4 points) Given my_dict my_dict l'a:3, x':7, r':5, write Python code to print all the key and value pairs of Answer: