1. Write a recursive procedure called instanceCount that counts the number of instances of a number in a list
(instanceCount '(1 2 3 4 3 2 1) 3) => 2
2. Write a recursive procedure called excludeElement that receives a list and a number. It returns a new list with all instances of that number removed
(excludeElement '(1 2 3 4 3 2 1) 3) => (1 2 4 2 1)
1)
Write a recursive procedure called instanceCount that counts the number of instances of a number in a list
(instanceCount '(1 2 3 4 3 2 1) 3) => 2
lisp code:
(defun instanceCount (l n)
; declaring variable c with value 0
(setq c 0)
; for loop for item in list
(loop for i in l
; condition for checking equal
do(if(= i n)
; condition true the c value incremenet
(incf c 1)))
(write c)
)
(instanceCount '(1 2 3 4 3 2 1) '3)
output:
2
2). Write a recursive procedure called excludeElement that receives a list and a number. It returns a new list with all instances of that number removed
(excludeElement '(1 2 3 4 3 2 1) 3) => (1 2 4 2 1)
lisp code:
(defun excludeElement (l n)
; creating list
(setq mynewlist '())
; for llop for given list
(loop for x in l
; condition check if item not equal to given num then append to new
list
do(setq mynewlist (append mynewlist (if (/= x n) (list x))))
)
; printng new list
(write mynewlist)
)
(excludeElement '(1 2 3 4 3 2 1) '3)
ouput:
(1 2 4 2 1)
Note:
1. Write a recursive procedure called instanceCount that counts the number of instances of a number...
1) (10 pts) Write a recursive function that counts and returns the number of nodes in a binary tree with the root root, that store an even value. Please use the struct shown and function prototype shown below. (For example, if the tree rooted at root stored 2, 3, 4, 8, 13, 18 and 20, the function should return 5, since there are five even values [2,4,8,18,20] stored in the tree. typedef struct node { int data; struct node* left;...
Write a recursive method that counts the number of vowels in a string. It must return the number of vowels. Use appropriate parameters as needed. Hint: There's an ArrayList method called contains that might make checking whether a character is a vowel easier.
This is Python coding question, and topic is recursive. Can anyone help me figuring this out? (Only recursive function is allowed.) Thanks. Write a function called Fibonacci(n) that takes as a parameter an integer n and returns the nth Fibonacci number. The first two Fibonacci numbers are 1 and every subsequent one is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, .... Write a recursive function to count the number of uppercase letters in a...
Write a recursive method that counts the number of bowling pins given the number of pins in the back row: 1. public static int numPins (int num) numPins(0)-> 0 numPins(1) → 1 numPins(2)-> 3
Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops! CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...
Need help with this. Java please!
Write a recursive method that counts the number of bowling pins given the number of pins in the back row: 1. public static int numPins (int num) numPins(0)-> 0 numPins(1) → 1 numPins(2)-> 3
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
Write a new recursive function countup that expects a negative argument and counts “up” from that number. Output from running the function should look something like this: >>> countup(-3) -3 -2 -1 Blastoff! I need a script that runs and I can see it and learn why it is working with #comments. The subject is writing a countup script to blastoff in computer science.
Scheme number computer a. Write a recursive procedure (digits n) that computes the number of digits in the integer n using a recursive process. For example, (digits 42) should return 2 and (digits 13579) should return 5. You may make use of the built in floor predicate for truncating decimals to whole numbers. b. Rewrite your procedure from part (a) using an iterative process. Call the function (digits-iter n).
Use java code please not C++ or Python. Thank you.
Write a recursive algorithm that counts the number of nodes in a linked list. Analyze the runtime of your algorithm