Question

Having trouble with writing a function in racket that would be able to use substitution like...

Having trouble with writing a function in racket that would be able to use substitution like so:

Input: two atoms and a list that might itself contain lists as elements. Substitute will replace every occurrence of the first atom with the second in the list.
Example:
(substitute ‘yim ‘yam ‘(a b yim (c d yim e) (f (g h (i yim)) j))
Should return
(a b yam (c d yam e) (f (g h (i yam)) j))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You have to consider a linked list kind of approach. We have to create a node that has two arrays. The first array is the array of nodes. The second array is the array of atoms/elements (here strings).

class Node{
public:
vector<Node*> arr;
vector<string> atoms;
};


//Here src is yim and dest is yam

void solve(Node * head, string src, string dest){
for(int i=0;i<head->arr.size();i++){
solve(arr[i], src, dest);
}
for(int i=0;i<head->atoms.size();i++){
if(atoms[i] == a){
atoms[i] = b;
}
}
}

Add a comment
Know the answer?
Add Answer to:
Having trouble with writing a function in racket that would be able to use substitution like...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I would like some help with number 2. I'm having trouble with working out the problems. If you ch...

    I would like some help with number 2. I'm having trouble with working out the problems. If you chould show your work step by step I could try to understand it. Thank you so much for your help. Molar Conversions Problem Sets i. For each of the following find the number of moies contained in each sample -12 A) 45.3 grams of Sodium Nitide%F)356 x 1012 Forraula Units of Cesium Chloride 5, B) 1.02 x 1034 atoms of Mercury :...

  • Please Provide me all Necessary Screenshot with copy able code. Thanks Write a scheme function named...

    Please Provide me all Necessary Screenshot with copy able code. Thanks Write a scheme function named up-to-first-number that takes a list as its input and returns a list containing all the elements up to the first numeric element in the input list. You can use the number? predicate function to determine whether an element is a number or not. Sample runs: (up-to-first-number '(a b c d 1 2 3 )) returns (a b c d) (up-to-first-number '(d e f 7))...

  • having trouble with the following swift 5 problem. It is just printing the number 4 twice...

    having trouble with the following swift 5 problem. It is just printing the number 4 twice and it seems to be ignoring camelCasePhraseTwo, please help if you can: /* Problem 4 Write a function that takes in a camel-case string and returns an integer representing the number of words in the string Notes: - Assume all input will contain only letters, and the string will be a valid camel-cased phrase - Do not loop through the array manually. */ func...

  • Define a function called max_association(), which recieves 2 lists, lst1, which is a list of strings,...

    Define a function called max_association(), which recieves 2 lists, lst1, which is a list of strings, and lst2, which is a list of integers. The function must return a list of strings associated to the highest integers in lst1. Assume both lists have the same length As an example, the following code fragment: L1 = ['a','b','c','d','e','f','g','h','i','j'] L2 = [1,2,3,1,3,2,3,1,2,1] result = max_association(L1,L2) print(result) should produce the output: ['c', 'e', 'g']

  • In Lisp 2. Code the function (replaceIn list possibleList repValue) which constructs a new list. It...

    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...

  • I am having trouble with this question. It would be appreciated if someone could work this out, explaining all the s...

    I am having trouble with this question. It would be appreciated if someone could work this out, explaining all the steps along the way. 79. A wheel of mass M has radius R. It is standing vertically on the floor, and we want to exert a horizontal force F its axle so that it will climb a step against which it rests (Fig. 8-55). The step has height h, where h R. What minimum force F is needed? 82 times...

  • Can I please have answers to all the parts. H. 5 4 HH N H HH...

    Can I please have answers to all the parts. H. 5 4 HH N H HH 2 H Н. С C C 1 Η 6 HH HH For parts A-G, provide a numerical answer in the blank (ex. 7). For parts H-J, answer with YES or NO (capitalized letters only). Note: Lone pairs electrons have been omitted. All formal charges are equal to zero. a) Total number of o-bonds in this molecule? 29 b) Total number of ri-bonds in this...

  • For the following question(s) MATCH each definition to a term from the list below. Place the...

    For the following question(s) MATCH each definition to a term from the list below. Place the letter of the term in the blank to the left of the definition. a. racemates b. chirality center c. chirality d. diastereomers e. enantiomers f. meso compounds g. optically active h. prochirality center i. optically inactive j. achiral ____ describes organic molecules which rotate plane-polarized light. ___ is the property of "handedness": the property of an object that causes it to be nonsuperimposable on...

  • Hello, Would you please be able to answer this question number 1 please, I am having...

    Hello, Would you please be able to answer this question number 1 please, I am having a hard time understanding what is going on. Can you please write it out in detail how you get the answers you did, that way I can understand the thought process to answering a question like this. Thank you 1) (27 points) Give the structures of compounds A through I in the following series of reactions CH3 Brą, light CI Brą, AIBr; B AICI,...

  • I am having trouble applying equations. An electromagnatic wave is traveling in vacuum with frequency 7.1...

    I am having trouble applying equations. An electromagnatic wave is traveling in vacuum with frequency 7.1 x 1014 Hz. The wave has average total energy density of 4.7 x 106 J/m3 (a) What is the speed of this wave? m/sHelp Enter (b) What is the wavelength of this wave? 1-I (c) What is the maximum electric field of this wave? Emax = (d) What is the rms magnetic field of this wave? m Help Enter V/m Help Enter T Help...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT