recursion

How to prevent PowerShell -Recurse from renaming first file twice?

╄→гoц情女王★ 提交于 2020-01-06 03:57:05
问题 When using powershell to rename files with their directory name and file name, my code works, except in the first file in a directory, it gives it two copies of the directory name. So the file book1.xlsx in folder folder1 should become folder1book1.xlsx but it becomes folder1folder1book1.xlsx . The remaining files in folder1 are correctly named folder1book2.xlsx , folder1book3.xlsx , etc. I have a directory, with many sub-directories. In each sub-dir are files that need their sub-dir name

Patterns for asynchronous but sequential requests

时光总嘲笑我的痴心妄想 提交于 2020-01-06 03:33:07
问题 I have been writing a lot of NodeJS recently and that has forced me to attack some problems from a different perspective. I was wondering what patterns had developed for the problem of processing chunks of data sequentially (rather than in parallel) in an asynchronous request-environment, but I haven't been able to find anything directly relevant. So to summarize the problem: I have a list of data stored in an array format that I need to process. I have to send this data to a service

How to return that last index of a list Python [duplicate]

筅森魡賤 提交于 2020-01-06 03:30:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Finding first and last index of some value in a list in Python Hi I was wondering if someone could help me with Python. I am trying to create a code that returns the last index of the last occurrence of an item in a list in a recursive way. So in a list [1,2,3,4,5,2] the last it should return 4 . It only takes in 2 variables which are the list and the item that it is searching for. If it does not find any

Exact change in python via recursion

南楼画角 提交于 2020-01-06 00:52:48
问题 I'm asked to write a recursive function in python: def exact_change( target_amount, L ): where the input target_amount is a single non-negative integer value and the input L is a list of positive integer values. Then, exact_change should return either True or False: it should return True if it’s possible to create target_amount by adding up some-or-all of the values in L. It should return False if it’s not possible to create target_amount by adding up some-or-all of the values in L. For

Erlang Recursive end loop

人盡茶涼 提交于 2020-01-05 21:09:25
问题 I just started learning Erlang and since I found out there is no for loop I tried recreating one with recursion: display(Rooms, In) -> Room = array:get(In, Rooms) io:format("~w", [Room]), if In < 59 -> display(Rooms, In + 1); true -> true end. With this code i need to display the content (false or true) of each array in Rooms till the number 59 is reached. However this creates a weird code which displays all of Rooms contents about 60 times (?). When I drop the if statement and only put in

Number of recursive calls in Recursive function analysis

淺唱寂寞╮ 提交于 2020-01-05 16:32:08
问题 Reading algorithms by self using Robert Sedwick book in C++ A recursive function that divides a problem of size N into two independent (nonempty) parts that it solves recursively calls itself less than N times. If the parts are one of size k and one of size N-k, then the total number of recursive calls that we use is T(n) = T(k) + T(n-k) + 1, for N>=1 with T(1) = 0. The solution T(N) = N-1 is immediate by induction. If the sizes sum to a value less than N, the proof that the number of calls

sort() returns None

元气小坏坏 提交于 2020-01-05 15:38:14
问题 Code: import math import time import random class SortClass(object): def sort1(self, l): if len(l)==1: return l elif len(l)==2: if l[0]<l[1]: return l else: return l[::-1] else: pivot=math.floor(len(l)/2) a=l[pivot:] b=l[:pivot] a2=self.sort1(a) b2=self.sort1(b) if a2==None or b2==None: a2=[] b2=[] return (a2+b2).sort() return [] Sort=SortClass() x=[20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1] print(Sort.sort1(x)) The code outputs None even though it should return an empty list in two

sort() returns None

♀尐吖头ヾ 提交于 2020-01-05 15:37:11
问题 Code: import math import time import random class SortClass(object): def sort1(self, l): if len(l)==1: return l elif len(l)==2: if l[0]<l[1]: return l else: return l[::-1] else: pivot=math.floor(len(l)/2) a=l[pivot:] b=l[:pivot] a2=self.sort1(a) b2=self.sort1(b) if a2==None or b2==None: a2=[] b2=[] return (a2+b2).sort() return [] Sort=SortClass() x=[20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1] print(Sort.sort1(x)) The code outputs None even though it should return an empty list in two

clearer explanation of function level scope for recursion

自闭症网瘾萝莉.ら 提交于 2020-01-05 15:17:12
问题 This is an example from the book 'Matlab for Neuroscientists'. I don't understand the order in which, or why, g gets assigned a new value after each recursion. Nor do I understand why "factorial2" is included in the final line of code. here is a link to the text Basically, I am asking for someone to re-word the authors explanation (circled in red) of how the function works, as if they were explaining the concept and processes to a 5-year old. I'm brand new to programming. I thought I

Calculator in python

女生的网名这么多〃 提交于 2020-01-05 13:52:49
问题 I am trying to make calculator that can solve expressions with basic 4 operators, like 1+2*3-4/5, however it does not work and I do not know what is wrong. Please check my code. When I run it, I am getting infinte number of errors in 8. line return ret(parts[0]) * ret(parts[2]) Here is code def ret(s): s = str(s) if s.isdigit(): return float(s) for c in ('*','/','+','-'): parts = s.partition(c) if c == '*': return ret(parts[0]) * ret(parts[2]) elif c == '/': return ret(parts[0]) / ret(parts[2