recursion

Scheme function that returns the odd-numbered elements from a list in reverse

人盡茶涼 提交于 2019-12-23 03:21:28
问题 I have to create a recursive Scheme function for my programming class that will take all the odd-numbered elements of a list, and then return them in reversed order. I have a function for reversing a list, and another function for getting the odd-numbered elements, but can't figure out how to combine the two into a new function, as they both are recursive. It has to be one function that doesn't call any functions other than itself. It can not call odd or reverse , and it has to have the same

C# - Finding the Boundaries of an Image (not the size)

独自空忆成欢 提交于 2019-12-23 03:19:10
问题 I'm developing an application to split an image grid equally and center the images (based on their similarity). So far, I could manage to fix a grid of images with small sizes, but whenever I try a larger "sprite" size (100x100, for instance), I get Stack Overflow error. Yes I'm using recursion, but whenever a pixel is checked, I set a boolean to deactivate it, copy it to a list and go on checking the others (in all directions), until the list is filled up with an image from the grid. I'm not

How to list switched svn directories recursively in a working copy?

我只是一个虾纸丫 提交于 2019-12-23 03:12:12
问题 I have checked out a working copy from a repository and switched some directories to a different URL but on the same repo (same host and svn server). How could I list these switched directories? We use many switching for internal purposes and it would help to easily list all these in a working copy, until this quick-and-dirty usage of switch is eliminated. 回答1: (1) The answer provided by @ks1322 is concise and it works fine except for one minor tweak: one should use "^URL" instead of just

Towers of Hanoi question

人盡茶涼 提交于 2019-12-23 03:05:06
问题 I read through a few of the discussions about the Towers of Hanoi problem. I understand the recursive solution using the following code: void Hanoi3(int nDisks, char source, char intermed, char dest) { if(nDisks == 1){ cout << "Move the plate from " << source << " to " << dest << endl; } else{ Hanoi3(nDisks - 1, source, dest, intermed); cout << "Move the plate from " << source << " to " << dest << endl; Hanoi3(nDisks - 1, dest, intermed, source); } } What I actually need to do is output some

Recursion - Java

我的未来我决定 提交于 2019-12-23 02:55:11
问题 I am working on a program where I have to use recursion to calculate the sum of 1/3 + 2/5 + 3/7 + 4/9 + ... + i / (2i + 1). However, I am not sure how to make my program show the term that must be added in order to reach the number enter by the user. For example. If I enter 12, I want to know how many terms of the series [1/3 + 2/5 + 3/7 + 4/9 + ... + i / (2i + 1)] were added to get approximately to the number 12. What I don't want to get is the sum of inputting 12 which in this case is 5

how to print this horizontally?

空扰寡人 提交于 2019-12-23 02:49:05
问题 Hey guys if you run this code with the given input you will get a vertical ruler i'm trying to get a horizontal ruler using the given recursive functions any idea how to get there or hints ??? public class Ruler { // draw a tick with no label public static void drawOneTick(int tickLength) { drawOneTick(tickLength, -1); } // draw one tick public static void drawOneTick(int tickLength, int tickLabel) { for (int i = 0; i < tickLength; i++) System.out.print("-"); if (tickLabel >= 0) System.out

how to print this horizontally?

主宰稳场 提交于 2019-12-23 02:49:04
问题 Hey guys if you run this code with the given input you will get a vertical ruler i'm trying to get a horizontal ruler using the given recursive functions any idea how to get there or hints ??? public class Ruler { // draw a tick with no label public static void drawOneTick(int tickLength) { drawOneTick(tickLength, -1); } // draw one tick public static void drawOneTick(int tickLength, int tickLabel) { for (int i = 0; i < tickLength; i++) System.out.print("-"); if (tickLabel >= 0) System.out

Permutation of jagged array

狂风中的少年 提交于 2019-12-23 02:47:07
问题 I'm trying to create a permutation of a multidimensional array in classic asp (vbscript) and I'm seriously stuck. I've tried several functions of my own and also tried copying several php versions over, but I often end up with something that either goes into a buffer overflow / infinite recursion or I get results that are more like a combination than a permutation, if I understand the differences correctly. Lets say it's for a shirt. The shirt can have colors, sizes, and styles. (The actual

How do I convert this nested iteration to a recursive solution?

隐身守侯 提交于 2019-12-23 02:39:22
问题 I have this code I wrote that calculates the sum of neighboring elements in a matrix and stores them into another matrix called sum_mat . I need the same result of this code but in a recursive solution and I don't know how to convert nested loops into recursion. void calculate_result(int n,int mat[100][100]) { //calculates an (n-1)x(n-1) matrix in which each element the sum of 4 // neighboring elements in the original matrix. int sum_mat[100][100]; for(int i=1;i<=n-1;i++) { for(int j=1;j<=n-1

Method to Display a Splay Tree

坚强是说给别人听的谎言 提交于 2019-12-23 02:38:21
问题 I have built a splay tree and I am trying to print it out reverse in order so that when you turn your head to the left you can see the tree in a normal manner. I have written the following code and it outputs the tree somewhat correctly but it adds extra spaces in on the rightmost node and it doesn't add spaces for all of the child nodes that should be placed below the root node: public void printReverseInOrder() { if (root != null) { reverseInOrder(root, 0); } else { System.out.println(); }