iteration

Recursive to Iterative Pascal's Triangle

陌路散爱 提交于 2020-01-11 13:39:10
问题 I wonder how to convert a recursive function/class to an iterative one. I have made a recursive Pascal's triangle, and now need to compare it to an iterative. public class RecursivePascal extends ErrorPascal implements Pascal { private int n; RecursivePascal(int n) throws Exception { super(n); this.n = n; } public void printPascal() { printPascal(n, false); } public void printPascal(boolean upsideDown) { printPascal(n, upsideDown); } private void printPascal(int n, boolean upsideDown) { if (n

How to do a loop to re-calculate the formula in R?

我的梦境 提交于 2020-01-11 13:04:54
问题 My question is how to use loop(while) to get the final "Tb" and "Theta_T"? Tmax = c(35.0,30.0,28.0,25.0,25.5,26.0) Tmin = c(15.4,15.8,13.2,9.8,9.5,9.4) X = c(0.233,0.233,0.220,0.065,0.138,0.083) D = c(12,25,46,41,45,62) Ts = 40 To = 30 Tbo = 0 ## calculate Theta_g by Tbo ## if (Tbo<Tmin){ Theta_g = (Tmax+Tmin)/2 } else if (Tbo<Tmax & Tbo>Tmin){ Theta_g = (Tmax+Tmin)/2+(Tbo-Tmin)^2/2*(Tmax-Tmin) } else Theta_g = Tbo ##calculate Theta_a by Tbo ## if (To>Tmin & Tmax<Ts){ Theta_a=(Ts-Tbo)*(Tmax

PHP - Iterate through folders and display HTML contents

*爱你&永不变心* 提交于 2020-01-11 07:14:07
问题 I'm currently trying to develop a method to get a overview of all my different web templates I've created and (legally) downloaded over the years. I thought about displaying them like WordPress is previewing its templates with a small preview window, displaying the concrete file with styles and everything. How do I divide them into rows and columns and create Ajax modal window open on preview and pagination and so on? I believe I can manage, but it is the concept itself about iterating over

How do you iterate through current class properties (not inherited from a parent or abstract class)?

自作多情 提交于 2020-01-10 04:12:44
问题 I know that PHP5 will let you iterate through a class's properties. However, if the class extends another class, then it will include all of those properties declared in the parent class as well. That's fine and all, no complaints. However, I always understood SELF as a pointer to the current class, while $this also points to the current object (including stuff inherited from a parent) Is there any way I can iterate ONLY through the current class's properties. Reason why I'm asking this.... I

Converting for loops to while loops in python

元气小坏坏 提交于 2020-01-09 11:23:09
问题 I am struggling to find an efficient way to convert these for loops to a working set of while loops. Any Suggestions? I am using 2.7 def printTTriangle(height): for row in range(1,height+1): # print row T's for col in range(1,row+1): print 'T', print Thank you all for your help! 回答1: It's like this: def printTTriangle(height): row = 1 while row < height+1: col = 1 while col < row+1: print 'T', col += 1 print row += 1 Here's how I did it. For example, let's convert this line: for row in range

Recursion to Iteration- refactoring

若如初见. 提交于 2020-01-07 03:50:30
问题 I wrote this code but now I want to refactor it in order not to use recursion. But I can't wrap my head around it? Any ideas guys? public List<ServiceDTO> findCustomerServices(String customerId) { List<Service> serviceTree = contractService.findCustomerServices(customerId); List<ServiceDTO> serviceDTOs = new ArrayList<ServiceDTO>(); cloneTree(serviceTree, serviceDTOs); return serviceDTOs; } private void cloneTree(List<Service> services, List<ServiceDTO> clonedServices) { for (Service service

How to iterate over functions?

南笙酒味 提交于 2020-01-06 21:23:48
问题 I would like to apply loop over a function. I have the following "mother" code: v = 1; fun = @root; x0 = [0,0] options = optimset('MaxFunEvals',100000,'MaxIter', 10000 ); x = fsolve(fun,x0, options) In addition, I have the following function in a separate file: function D = root(x) v = 1; D(1) = x(1) + x(2) + v - 2; D(2) = x(1) - x(2) + v - 1.8; end Now, I would like to find roots when v = sort(rand(1,1000)) . In other words, I would like to iterate over function for each values of v . 回答1:

C# .Net Freeze while iterating through large number of files

試著忘記壹切 提交于 2020-01-06 16:19:42
问题 I have a problem that I wrote an application that would iterate through files and add +1 to the integer each file, until it reaches a specific file name. The problem is probably because .Net does not access the native file system directly, it fills up collections, but in my case it would take years, believe me, I have 260 000 files in the target folder. The iteration does not even reach the second file. The thread just totally freezes, no errors, no exceptions. So is there any way to get a

php array iteration visually parent > child

对着背影说爱祢 提交于 2020-01-06 08:32:17
问题 managed to create array tree with childs. Looks like this. Want to try printing it out with same levels. <ul> <li>cat1</li> <ul><li>sub-cat</li> <ul><li>subsub-cat</li> <ul><li>subsubsub-cat</li> <ul><li>subsubsubsub-cat</li></ul> <li>subcub-cat2</li> <ul></ul></ul></ul></ul> <li>cat2</li> </ul> Need to use iterative angle. At least point me to to the right direction. It doesn't have to be with UL LI, can be with -- -- or some sort similar, just need to print it out using iterative methods.

Iterating after pairs in string in Python

て烟熏妆下的殇ゞ 提交于 2020-01-06 07:55:59
问题 Here is the combination / permutator generator function that uses any number of lists with values and any length of template strings. The generator creates corresponding lists with combinations / permutations of values matching the template string. The answer was given by a colleague here: https://stackoverflow.com/a/48121777/8820330 from itertools import permutations, combinations, product def groups(sources, template, mode='P'): func = permutations if mode == 'P' else combinations keys =