nested-loops

I'm having trouble making a diamond shape with loops

穿精又带淫゛_ 提交于 2019-12-23 04:49:07
问题 You have an input of n and that represents half the rows that the diamond will have. I was able to make the first half of the diamond but I'm EXTREMELY frustrated with the second half. I just can't seem to get it. I'm not here to ask for specific code I need, but can you point me in the right direction and give me some tips/tricks on how to write this? Also, if I'm going about this program the wrong way, feel free to tell me and tell me on how I should approach the program. The diamonds at

Python Nested Loop unique pairs

浪尽此生 提交于 2019-12-23 03:59:50
问题 I'm trying to write a nested loop that prints out all possible "unique pairs" of numbers from a certain range. For example, if the range was from 1 to 3 the unique pairs would be: (1,2) (1,3) (2,3) If the range was from 1 to 4 the unique pairs would be: (1,2) (1,3) (1,4) (2,3) (2,4) (3,4) Here's how I did it for 1 to 3: for i in range(1,4): for j in range(2,4): if (i != j & j != (i-1)): print (i,j) which prints out (1, 2), (1, 3),(2, 3). But this is a hack because it doesn't work when I

Implement matrix config in Jenkins pipeline

自古美人都是妖i 提交于 2019-12-23 01:57:38
问题 I've recently moved to the Pipeline plugin in Jenkins. I've successfully used freestyle jobs before for my project, but now would like to test something new. My project builds for Windows and Linux, in release and in debug mode, and uses a parameter, called device , to configure some C preprocessor macros: globally #define d frame_width and frame_height differ, depending on device value. Here is my Jenkinsfile: def device_config(device) { def device_config = ""; switch(device) { case ~/^dev_

Break nested loops

别说谁变了你拦得住时间么 提交于 2019-12-22 04:25:27
问题 Can someone tell me how to break the main loop when I have nested loops? Example*: /*Main loop*/ for(int y = 0; y < 100; y+=10) { /*Sub loop*/ for (int x = 0; x < 100; x += 10) { if(x == 60) { //Break the main loop } } } *This code do nothing, it's just an example What should I put in the place of the "Break main loop" comment? In java there are labels which I can break (when i set a label to the main loop named "MainLoop" I can write "break MainLoop;" and it will be valid), but what can I do

How to check if an integer is linear combination of elements in an array?

删除回忆录丶 提交于 2019-12-22 01:12:23
问题 How to check if an integer can be expressed as linear combination of elements in a given array of length n? Currently I can code for the specific case when n=2, but I don't know how to code when n is unknown. This is the function when n=2 (when there are only two elements in the array): bool check(int array[], int n, int value){//n values in the array // for (int i=1; i<array[0]; i++){ for (int j=1; j<array[1]; j++){ if ((i*array[0]+j*array[1])%value==0){ printf("x=%d, y=%d, i=%d, j=%d\n",

How to print out an X using nested loops

好久不见. 提交于 2019-12-22 01:04:23
问题 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

complexity for nested loops

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 17:55:50
问题 I am trying to figure out the complexity of a for loop using Big O notation. I have done this before in my other classes, but this one is more rigorous than the others because it is on the actual algorithm. The code is as follows: for(i=n ; i>1 ; i/=2) //for any size n { for(j = 1; j < i; j++) { x+=a } } and for(i=1 ; i<=n;i++,x=1) //for any size n { for(j = 1; j <= i; j++) { for(k = 1; k <= j; x+=a,k*=a) { } } } I have arrived that the first loop is of O(n) complexity because it is going

Pythonic shortcut for doubly nested for loops?

半城伤御伤魂 提交于 2019-12-21 07:22:03
问题 Consider if I had a function that took a tuple argument (x,y), where x was in the range(X), and y in the range(Y), the normal way of doing it would be: for x in range(X): for y in range(Y): function(x,y) is there a way to do for xy in something_like_range(X,Y): function(xy) such that xy was a tuple (x,y)? 回答1: You can use product from itertools >>> from itertools import product >>> >>> for x,y in product(range(3), range(4)): ... print (x,y) ... (0, 0) (0, 1) (0, 2) (0, 3) (1, 0) (1, 1) (1, 2)

I need help writing a program that prints out two shapes on one line using nested loops

痴心易碎 提交于 2019-12-21 06:35:44
问题 Here is what the shapes should look like : Here is my code so far: public class Diamonds { public static void main(String[] args) { for (int i = 1; i < 10; i += 2) { for (int j = 0; j < 9 - i / 2; j++) { System.out.print(" "); } for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.print("\n"); } for (int i = 7; i > 0; i -= 2) { for (int j = 0; j < 9 - i / 2; j++) { System.out.print(" "); } for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.print("\n"); } } } I am

Upper-triangular loop idiom for Scala Lists

橙三吉。 提交于 2019-12-21 05:14:12
问题 From my background in imperative programming, I'm accustomed to doing for (i = 0; i < 1000000; i++) { for (j = i + 1; j < 1000000; j++) { doSomething(array[i], array[j]) } } to examine all unique pairs in a million element array. doSomething is some operation that yields trivial results on diagonal and symmetric or antisymmetric results off diagonal--- that's why I only want to work on the upper triangle. (There's a minor variant of this where the i == j case is interesting; that's easy to