nested-loops

How to use nested FOR loops in batch files

徘徊边缘 提交于 2019-12-06 10:49:48
I have some code in which I want to use a FOR loop to handle a set of files. As part of handling a file there's a FOR /F loop that reads it and appends data to an other file based on the file name. In order to be able to set the output file name I have delayed variable expansion set on. This is what the code should look like as I originally intended it to be: setlocal enabledelayedexpansion for %%f in (DataFolder\*.Ext) do ( set POI=%%~f set POI=!JbPOI:DataFolder\=! set POI=!JbPOI:.Ext=! for /f "tokens=1,2,3 delims=," %%a in ("%%~f") do ( set CX=%%a set CY=%%b set FN=%%c echo !FN!,9,!CX!,!CY!

F# functional style approach much slower

折月煮酒 提交于 2019-12-06 10:25:15
Trying to learn F#, by solving some programming puzzles. I don't want to add too many details about the problem as I don't want to spoil the fun for others. Basically, the issue is to find all 4-uples { (i,j,k,l) | i ^ j ^ k ^ l != 0 } with no repetition (eg., (1,1,1,2) and (1,1,2,1) are the same and should be counted just once). I have found a O(n^3) approach which works, please see countImperative(a,b,c,d) below. But I also tried to refactor the code as to get rid of the nested for loops. However, I could not do so without a significant performance penalty. It was my impression that F#'s

C++ nested iterators

安稳与你 提交于 2019-12-06 09:40:16
Is it OK to have a nested iterator like the following? for (vector<type>::iterator i = list.begin(); i != list.end(); ++i) { for (vector<type>::iterator j = i; j != list.end(); ++j) { ... } } Note that j starts at i , and not list.begin() . Since the iterator is random access, can I guarantee that both i and j will have the same order? is there a better way of doing this? Rafał Rawicki Your code is correct. Both iterators will have the same order and incrementing j doesn't affect i as long as you don't make any operation that invalidates iterators (for example erasing from or pushing to vector

variable number of dependent nested loops

只愿长相守 提交于 2019-12-05 18:37:57
Given two integers n and d , I would like to construct a list of all nonnegative tuples of length d that sum up to n , including all permutations. This is similar to the integer partitioning problem , but the solution is much simpler. For example for d==3 : [ [n-i-j, j, i] for i in range(n+1) for j in range(n-i+1) ] This can be extended to more dimensions quite easily, e.g., d==5 : [ [n-i-j-k-l, l, k, j, i] for i in range(n+1) for j in range(n-i+1) for k in range(n-i-j+1) for l in range(n-i-j-l+1) ] I would now like to make d , i.e., the number of nested loops, a variable, but I'm not sure how

Terraform 0.12 nested for loops

青春壹個敷衍的年華 提交于 2019-12-05 17:07:32
I am trying to implement nested for loops using Terraform 0.12's new features in order to loop through AWS IAM users, each of which can have one or more policies attached. The variable used to represent this list is of type map(list(string)) and looks something like this: { "user 1" = [ "policy1", "policy2" ], "user 2" = [ "policy1" ] } Getting the list of users to create is easy enough via keys() , but since there is currently no mechanism for nesting looped resource creation in Terraform, the policy attachments have to happen as a singular loop independent of each user. So, I am attempting

Lisp macro (or function) for nested loops

二次信任 提交于 2019-12-05 04:28:27
Is it possible to write a Common Lisp macro that takes a list of dimensions and variables, a body (of iteration), and creates the code consisting of as many nested loops as specified by the list? That is, something like: (nested-loops '(2 5 3) '(i j k) whatever_loop_body) should be expanded to (loop for i from 0 below 2 do (loop for j from 0 below 5 do (loop for k from 0 below 3 do whatever_loop_body))) Follow up As huaiyuan correctly pointed out, I have to know the parameters to pass to macro at compile time. If you actually need a function as I do, look below. If you are ok with a macro, go

Better equivalent of this crazy nested python for loop

天涯浪子 提交于 2019-12-05 04:02:35
for a in map: for b in map[a]: for c in map[b]: for d in map[c]: for e in map[d]: print a+b+c+d+e The above code is used to create all paths of certain length in a graph. map[a] represents the points you can reach from point a. How can I change it to simulate having an arbitrary number of loops? This is like a cartesian product (itertools.product) where at each iteration your choice for the next element is limited to those in map[current_point]. map = { 'a': ['b', 'c'], 'b': ['c', 'd'], 'c': ['d', 'a'], 'd': [] } def print_paths(map, start, length, prefix = ''): if length == 0: print prefix

Multi-dimensional nested OpenMP loop

六眼飞鱼酱① 提交于 2019-12-05 01:20:21
What is the proper way to parallelize a multi-dimensional embarrassingly parallel loop in OpenMP? The number of dimensions is known at compile-time, but which dimensions will be large is not. Any of them may be one, two, or a million. Surely I don't want N omp parallel 's for an N-dimensional loop... Thoughts: The problem is conceptually simple. Only the outermost 'large' loop needs to be parallelized, but the loop dimensions are unknown at compile-time and may change. Will dynamically setting omp_set_num_threads(1) and #pragma omp for schedule(static, huge_number) make certain loop

Artists Group_by nested attribute Order_date

社会主义新天地 提交于 2019-12-04 22:52:21
I have created a functioning e-commerce platform where Members can buy songs. Everything works fine, But I would like to group all of my Orders in my Index Page by Month. Currently I am able to group each Album with its corresponding Artist, and each Ordered Song to its corresponding Album. But now I would like to group Orders by Month. How Can I Group Artists by the order_date in my Orders Table, So that everything is organized by Month? Ex. of what I've like to do Month 1 Orders Artist1 Album1 ###List of Albums Corresponding to an Artist --Song1 (10 0rders) --Song3 (5 Orders) Album2 --Song5

How to print out an X using nested loops

扶醉桌前 提交于 2019-12-04 22:37:49
I have searched through to find a simple solution to this problem. I have a method called printCross(int size,char display) It accepts a size and prints an X with the char variable it receives of height and width of size. The calling method printShape(int maxSize, char display) accepts the maximum size of the shape and goes in a loop, sending multiples of 2 to the printCross method until it gets to the maximum. Here is my code but it is not giving me the desired outcome. public static void drawShape(char display, int maxSize) { int currentSize = 2; //start at 2 and increase in multiples of 2