recursion

how to make HTML from a list in scheme, racket

北城以北 提交于 2021-02-10 06:48:33
问题 This is a very long question ... I am new and joined, so please don't attack me. Apologies for my bad communications in English. I have some defintions: An HTML(H) is one of Str Tag A Tag is (cons Sym (listof H)) I want to use mutual recursion,make the HTML into real HTML code. For example, (list 'html (list 'head (list 'title "Hi")) (list 'body (list 'h1 "Welcome") "Text")) Turns into: "<html><head><title>Hi</title></head><body><h1>Welcome</h1>Text</body></html>" This should work for any

Find and print num of solutions to x1+x2+x3=num

怎甘沉沦 提交于 2021-02-10 04:49:07
问题 I need to write a recusive function that recive an integer num and returns the number of solutions to the equation : x1 + x2 + x3 = num , where x1,x2,x3 are numbers between 1-10, the method should print all solutions. For example if num=3 then the method will print 1+1+1 and will return 1 . if num=5 the method will return 6 and will print: 1 + 1 + 3 1 + 2 + 2 1 + 3 + 1 2 + 1 + 2 2 + 2 + 1 3 + 1 + 1 if num<3 or num>30 the method will return 0 . The method should be recursive without using

Find and print num of solutions to x1+x2+x3=num

China☆狼群 提交于 2021-02-10 04:48:41
问题 I need to write a recusive function that recive an integer num and returns the number of solutions to the equation : x1 + x2 + x3 = num , where x1,x2,x3 are numbers between 1-10, the method should print all solutions. For example if num=3 then the method will print 1+1+1 and will return 1 . if num=5 the method will return 6 and will print: 1 + 1 + 3 1 + 2 + 2 1 + 3 + 1 2 + 1 + 2 2 + 2 + 1 3 + 1 + 1 if num<3 or num>30 the method will return 0 . The method should be recursive without using

Find and print num of solutions to x1+x2+x3=num

怎甘沉沦 提交于 2021-02-10 04:48:09
问题 I need to write a recusive function that recive an integer num and returns the number of solutions to the equation : x1 + x2 + x3 = num , where x1,x2,x3 are numbers between 1-10, the method should print all solutions. For example if num=3 then the method will print 1+1+1 and will return 1 . if num=5 the method will return 6 and will print: 1 + 1 + 3 1 + 2 + 2 1 + 3 + 1 2 + 1 + 2 2 + 2 + 1 3 + 1 + 1 if num<3 or num>30 the method will return 0 . The method should be recursive without using

How to prevent a recursive function from re-initializing an accumulating variable?

心已入冬 提交于 2021-02-09 08:51:25
问题 This function is written in JavaScript but I think that the concept can be implemented with some other programming languages. function uniteUnique(arr) { let seenBefore = []; //the accumulating array for (let item of arguments) { if (typeof (item) == "object") { uniteUnique(...item); } else if (!seenBefore.includes(item)) { seenBefore.push(item); } } return seenBefore; } In short, the function iterates over arrays it receives as arguments, which may or may not contain other arrays themselves.

How to prevent a recursive function from re-initializing an accumulating variable?

╄→尐↘猪︶ㄣ 提交于 2021-02-09 08:50:38
问题 This function is written in JavaScript but I think that the concept can be implemented with some other programming languages. function uniteUnique(arr) { let seenBefore = []; //the accumulating array for (let item of arguments) { if (typeof (item) == "object") { uniteUnique(...item); } else if (!seenBefore.includes(item)) { seenBefore.push(item); } } return seenBefore; } In short, the function iterates over arrays it receives as arguments, which may or may not contain other arrays themselves.

pyinstaller Recursion error: maximum recursion depth exceeded

蹲街弑〆低调 提交于 2021-02-08 15:01:29
问题 I am trying to convert a .py to .exe using pyinstaller. When I type pyinstaller my_code.py everything seems to be working and after a couple of minutes the process stops and I get the recursion error. I have tried to create a my_code.spec file in the same folder, edit it and change the number of recursions but when I run pyinstaller apparently a new .spec is created since I can't find the sys.setrecursionlimit() command that I had previously added to the my_code.spec file. I am running all

Square of Numbers in Nested List Python 3

别说谁变了你拦得住时间么 提交于 2021-02-08 13:49:33
问题 The problem I have to solve is one that takes a nested list as an input, and returns the same nested list, except each element is the square of the element that previously existed in that spot. This is my code >>> def treemap(lst): ... for element in lst: ... if element == type(list): ... return treemap(element) ... else: ... element=element**2 ... return lst >>> lst = [1, 2, 3, [4, [5, 6], 7]] >>> print(treemap(lst)) Now I am getting an error that is saying 'int' object is not iterable. I'm

Does @tailrec affect compiler optimizations?

时光总嘲笑我的痴心妄想 提交于 2021-02-08 11:13:02
问题 I looked at this question trying to better understand @tailrec annotation in scala. What I'm not sure is whether the annotation also hints the compiler to do some optimizations or it's only used for warnings when you mark a method that is not a tail-recursion? More specifically - is this annotation might affect performance in any way? For example, if I don't put this annotation, the compiler will compile a tail-recursive function as non-tail recursive? 回答1: As per the scaladoc: A method

Append linked list with recursion

萝らか妹 提交于 2021-02-08 10:40:45
问题 I want an insert function that calls a private recursive insert function that adds the next number to the end of a linked list. I am having trouble on which parameters I should use and what should be in the recursive insert function. I am thinking that the recursive insert function needs a Node pointer to step through recursively. class LinkedList{ private: struct Node{ int data; //stores data in nodes Node* next; ~Node(){delete next;} }; public: LinkedList(){ first = NULL;} ~LinkedList()