recursion

Stored procedure with recursive call using mysql

霸气de小男生 提交于 2019-12-23 11:48:11
问题 enter image description hereget legside from binary I have tried using stored procedure with recursive call. i need to display relevant name based on emp_name based on leg1 but it showing error like #1414 - OUT or INOUT argument 2 for routine sample.getVolume is not a variable or NEW pseudo-variable in BEFORE trigger Here is my code, DELIMITER $$ CREATE PROCEDURE getVolume( IN param_name VARCHAR(255), OUT result VARCHAR(255 )) BEGIN SELECT val INTO result FROM employee WHERE emp_name = param

Recursive replace with Java regular expression?

主宰稳场 提交于 2019-12-23 10:56:21
问题 I can replace ABC(10,5) with (10)%(5) using: replaceAll("ABC\\(([^,]*)\\,([^,]*)\\)", "($1)%($2)") but I'm unable to figure out how to do it for ABC(ABC(20,2),5) or ABC(ABC(30,2),3+2) . If I'm able to convert to ((20)%(2))%5 how can I convert back to ABC(ABC(20,2),5) ? Thanks, j 回答1: I am going to answer about the first question. I was not able to do the task in a single replaceAll . I don't think it is even achievable. However if I use loop then this should do the work for you: String

Finding Power Using Recursion

感情迁移 提交于 2019-12-23 10:55:04
问题 In Python 3 def power(base,exponent): if exponent == 1: return base return base * power(base, exponent - 1) I haven't considered corner cases ( exponent <= 0) Why don't we use the above-written code in-place of code computed using Divide and Conquer Technique, this code looks more simple and easy to understand? Is this code less efficient by any means? 回答1: These are the steps taken for calculating 2^8 with your code: power(2,8)= 2*power(2,7)= 2*2*power(2,6)= 2*2*2*power(2,5)= 2*2*2*2*power(2

Reaching end of list in prolog

会有一股神秘感。 提交于 2019-12-23 10:53:25
问题 I've been given the question: Define a predicate ordered/1, which checks if a list of integers is correctly in ascending order. For example, the goal ordered([1,3,7,11]) should succeed, as should the goal ordered([1,3,3,7]) , whereas the goal ordered([1,7,3,9]) should fail. So far I have this: ordered([]). ordered([N, M|Ns]):- append(M, Ns, Tail), ordered(Tail), N =< M. But it fails on every list. I have deduced that the reason it fails is because it reaches the end number in the list then

Python Recursion and list

一曲冷凌霜 提交于 2019-12-23 10:52:27
问题 I am learning about recursion in python and I have this code: def search(l,key): """ locates key in list l. if present, returns location as an index; else returns False. PRE: l is a list. POST: l is unchanged; returns i such that l[i] == key; False otherwise. """ if l: # checks if list exists if l[0] == key: # base case - first index is key return True s = search(l[1:], key) # recursion if s is not False: return s return False # returns false if key not found Can someone explain to me what

Why does function containing Console.ReadLine() not complete?

跟風遠走 提交于 2019-12-23 10:25:51
问题 I am using Visual Studio 2012, and the function that calls Console.ReadLine() will not execute let inSeq = readlines () in this simple program open System open System.Collections.Generic open System.Text open System.IO #nowarn "40" let rec readlines () = seq { let line = Console.ReadLine() if not (line.Equals("")) then yield line yield! readlines () } [<EntryPoint>] let main argv = let inSeq = readlines () 0 I've been experimenting and researching this, and cannot see what is probably a very

How to detect completion of recursive asynchronous calls in javascript

只愿长相守 提交于 2019-12-23 10:17:06
问题 I am using following code to fetch hierarchical data from Web SQL Database: ... function getResult(query, data, callback){ db.transaction(function(tx) { tx.executeSql(query, data, function(tx, result) { callback(result); }); }); } function findChildren(id){ getResult("SELECT * FROM my_table WHERE parent_id=?", [id], function(result){ for (var i = 0, item = null; i < result.rows.length; i++) { item = result.rows.item(i); data.push(item); findChildren(item.id); } }); } var data = Array();

F# Split Function

两盒软妹~` 提交于 2019-12-23 10:14:24
问题 I'm building a merge sort function and my split method is giving me a value restriction error. I'm using 2 accumulating parameters, the 2 lists resulting from the split, that I package into a tuple in the end for the return. However I'm getting a value restriction error and I can't figure out what the problem is. Does anyone have any ideas? let split lst = let a = [] let b = [] let ctr = 0 let rec helper (lst,l1,l2,ctr) = match lst with | [] -> [] | x::xs -> if ctr%2 = 0 then helper(xs, x::l1

zip main folder with sub folder inside

喜夏-厌秋 提交于 2019-12-23 10:11:25
问题 I have a folder with some files and sub folder inside. How im going to read the directory and zip the main folder? Ex: maindirectory --- file 1 --- file 2 --- subdirectory 1 ------ file 3 ------ file 4 --- subdirectory 2 ------ file 5 ------ file 6 I'm using this script: function Zip($source, $destination, $include_dir = false) { if (!extension_loaded('zip') || !file_exists($source)) { return false; } if (file_exists($destination)) { unlink ($destination); } $zip = new ZipArchive(); if (!$zip

Why is this recursion slow?

孤人 提交于 2019-12-23 10:08:48
问题 I'm trying to solve the problem: How many ways are there to get $50 using only 1c, 5c, 10c, 25c, or 50c coins? Here's my code: main = print $ coinCombinations [1,5,10,25,50] !! 5000 coinCombinations coins = foldr recurse (1 : repeat 0) coins where recurse a xs = take a xs ++ zipWith (+) (drop a xs) (recurse a xs) It turns out that my recurse function is slow, maybe quadratic time or worse. But I don't understand why, since it looks similar to the fibonacci list fibs = 0 : 1 : zipWith (+) fibs