recursion

Is there a more efficient way passing object parameters in recursion?

本秂侑毒 提交于 2020-01-05 04:29:10
问题 I would like to do recursion in Java, passing object parameters. Something like this: int recursion(Object object) { //do a little bit modification to the object int i1= recursion(modified_object_1); //do a little bit modification to the object int i2= recursion(modified_object_2); //do a little bit modification to the object int i3= recursion(modified_object_3); return max(i1, i2, i3); } Now, because objects are passed by reference, I have to clone the object parameters 3 times and pass the

Is is possible to move from (a,b) to (c,d)

。_饼干妹妹 提交于 2020-01-05 04:21:06
问题 The problem was to output whether it is possible to move from a given point (a,b) to target (c,d) We are restricted to positive co-ordinates only The following two moves are possible (a,b) -> (a+b,b) (a,b) -> (a,b+a) For instance, (1,1) to (5,4) is True You can do the following: Using 2nd move 3 times, (1,1) -> (1,2) -> (1,3) -> (1,4) Using 1st move 1 time (1,4) -> (5,4) I came up with the following recursive method def move(a,b,c,d): if a==c and b==d: return True elif a>c or b>d: return

Better way to write recursive random variables

杀马特。学长 韩版系。学妹 提交于 2020-01-05 04:20:14
问题 I know this is really bad, but it works and it was the only way with my current knowledge to complete the job. So I am looking for a "better" way in practice to write this. Basically it shows 3 slots of images and those 3 slots change images with the random images listed in SLOT_PATTERN . The images change using edit_message to edit the previous 3 slot images that were there, replacing them with random images from the given list. import discord, asyncio, time, random client = discord.Client()

Wrong answer to dynamic programming problem of finding minimum stair cost

Deadly 提交于 2020-01-05 04:09:15
问题 I am trying to solve the following problem on Leetcode: On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1. This is my solution so far. I believe I'm not correctly taking into account the fact that I can start at stair 0, or stair 1, and I'm not sure how to do

How do I make my squares generate behind each other rather than on top of eachother without using recursion?

天涯浪子 提交于 2020-01-05 03:59:07
问题 I've gotten some help in another one of my questions to get me this far but I'd like to know how to make my squares generate behind one another rather than on top of each other. The below code is what I've got so far. This is the code that places them behind each other recursively: import java.awt.image.*; import java.awt.Color; import java.io.*; import javax.imageio.*; import java.util.*; public class FractalDriver { static final int SIDE = 1000; // image is SIDE X SIDE static BufferedImage

PHP string to multi level array

孤人 提交于 2020-01-05 03:51:10
问题 How to convert this* string: $arrKeys = ['lev1', 'lev2', 'lev3']; $val = 'foo'; In to the following array: Array ( [lev1] => Array ( [lev2] => Array ( [lev3] => foo ) ) ) *Number of array keys may vary. Each array key except the last one represents Array. Thank you! 回答1: No recursion necessary: $arrKeys = array_reverse(['lev1', 'lev2', 'lev3']); $val = 'foo'; $result = $val; foreach ($arrKeys as $key) { $result = [$key => $result]; } print_r($result); // Array // ( // [lev1] => Array // ( //

Run excel macro code recursively on all files inside of a folder and subfolders

感情迁移 提交于 2020-01-05 03:35:10
问题 I have a folder where I have many sub-folders and inside of them more than 1000 Excel files. I want to run a specific macro (that changes a workbook) on all these files. Already saw the following answer. Sub ProcessFiles() Dim Filename, Pathname As String Dim wb As Workbook Pathname = ActiveWorkbook.Path & "\C:\...\EXCL\" Filename = Dir(Pathname & "*.xlsx") Do While Filename <> "" Set wb = Workbooks.Open(Pathname & Filename) DoWork wb wb.Close SaveChanges:=True Filename = Dir() Loop End Sub

How to convert recursive CTE to be usable in SQL Server 2000

妖精的绣舞 提交于 2020-01-04 15:58:29
问题 I have a recursive CTE-query like this: ;WITH cte AS ( SELECT e.entryID , e.bOpen , e.nextEntryID , e.entryID AS OriginalentryID FROM entries e WHERE e.bOpen = 1 AND e.nextEntryID IS NOT NULL UNION ALL SELECT e.entryID , e.bOpen , e.nextEntryID , c.OriginalentryID FROM cte c INNER JOIN entries e ON e.entryID = c.nextEntryID ) SELECT c.entryID , c.OriginalentryID FROM cte c WHERE bOpen = 0; Would there be any way to realise this without CTE (i.e. for SQL Server 2000)? Any hints/ideas are

SQL - recursion statement (trigger)

笑着哭i 提交于 2020-01-04 13:38:16
问题 I've got this problem with this excercice: Table Friend Friend1 Friend2 Table Relationship Friend1 Friend2 GradeOfFriendship So, i need to create a trigger system that make symmetric tuple after delete, insert update for example insert into Friend values('Luc' ,'Mark') my trigger system must insert into the table Friend the following value Mark Luc So i've symmetric tuple. But is not my real problem after insert, update, delete on table friend i must have another trigger that works only on

SQL - recursion statement (trigger)

谁都会走 提交于 2020-01-04 13:37:31
问题 I've got this problem with this excercice: Table Friend Friend1 Friend2 Table Relationship Friend1 Friend2 GradeOfFriendship So, i need to create a trigger system that make symmetric tuple after delete, insert update for example insert into Friend values('Luc' ,'Mark') my trigger system must insert into the table Friend the following value Mark Luc So i've symmetric tuple. But is not my real problem after insert, update, delete on table friend i must have another trigger that works only on