recursion Questions
10
Solved
I'm trying to find whether a number is a power of 2 using recursion. However, I couldn't seem to figure out the correct solution. Here's what I've tried so far:
def is_power(n):
n = n/2
if n == ...
Puca asked 6/4, 2015 at 22:25
6
I'd like to write a function that deletes all empty folders, with the option to ignore certain file types (allowed file types are stored in the hashmap) and tell if it should look inside directorie...
1
Solved
7
Solved
I am currently optimizing a PHP application and found one function being called around 10-20k times, so I'd thought I'd start optimization there:
function keysToLower($obj)
{
if (!is_object($obj) ...
2
Solved
in SICP Section 1.2.1 The author giving such a code example below to show how to using iterative process to solve the factorial problem:
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-ite...
4
Solved
This regular expression matches palindromes:
^((.)(?1)\2|.?)$
Can't wrap my head around how it works.
When does the recursion end, and when regex breaks from the recursive subpattern and goes to &q...
Warlike asked 26/7, 2012 at 13:14
2
My problem is like this:
I have several lists need to be permuted, but the list numbers are unknowable. And every element numbers in every list are also unknowable. Sicne I would like to traverse ...
4
Solved
On the Bit Twiddling Hacks website the following algorithm is provided to round up an integer to the next power of two:
unsigned int v; // compute the next highest power of 2 of 32-bit v
v--;
v |=...
Duroc asked 23/1, 2014 at 2:39
10
Solved
I am trying to write a program that draws a sierpinski tree with python using turtle. Here is my idea:
import turtle
def draw_sierpinski(length,depth):
window = turtle.Screen()
t = turtle.Turtle...
Palaeontography asked 10/9, 2014 at 18:41
3
Solved
Need some help in creating function which can create folders recursively with giving path:
C:\TestFolder\Another\AndAnother
Delphi function MkDir returning IOerror = 3.
MkDir('C:\TestFolder\Ano...
19
Solved
Given a set of numbers: {1, 3, 2, 5, 4, 9}, find the number of subsets that sum to a particular value (say, 9 for this example).
This is similar to subset sum problem with the slight difference th...
2
Solved
I looking for a suitable algorithm that will return the maximum depth of a collection of objects within a hierarchy of collections. I have a root object which may or may not contain a collection of...
Tole asked 9/3, 2023 at 16:57
5
Solved
This is just curiosity on my part, but what is more efficient, recursion or a loop?
Given two functions (using common lisp):
(defun factorial_recursion (x)
(if (> x 0)
(* x (factorial_recurs...
Bilharziasis asked 21/2, 2012 at 22:33
2
Solved
So given the following:
def inorder(t):
if t:
inorder(t.left)
yield t.key
inorder(t.right)
x = [ n for n in inorder(r) ]
x only contains the root node, why?
Here's the full code; note that...
Busily asked 22/4, 2015 at 13:50
8
Solved
I am trying to convert the keys of a multi-dimensional array from camelCase or StudlyCase/PascalCase to snake_case, with the added complication that some keys have a leading exclamation mark that I...
Mortgagor asked 18/9, 2009 at 13:14
10
Solved
I'm trying to recall an algorithm on Fibonacci recursion. The following:
public int fibonacci(int n) {
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci...
9
Solved
I'm trying to write a very simple function to recursively search through a possibly nested (in the most extreme cases ten levels deep) Python dictionary and return the first value it finds from the...
Cosenza asked 19/2, 2013 at 16:29
3
Solved
I wrote the follwing function:
let str2lst str =
let rec f s acc =
match s with
| "" -> acc
| _ -> f (s.Substring 1) (s.[0]::acc)
f str []
How can I know if the F# compiler turned it ...
Mollee asked 30/4, 2009 at 12:44
5
Solved
Good night everyone. I'm having trouble with probably some simple recursive function. The problem is to recursively list all files in a given folder and its subfolders.
For the moment, I've m...
Bordelaise asked 1/5, 2018 at 18:32
5
I use GoogleColab to test data stuctures like chain-hashmap,probe-hashmap,AVL-tree,red-black-tree,splay-tree(written in Python),and I store very large dataset(key-value pairs) with these data...
Fortuity asked 20/2, 2018 at 6:56
1
I have a nested list called inputs:
library(htmltools)
library(shiny)
inputs = tagList(
selectInput('first', 'FIRST', letters),
checkboxInput('second', 'SECOND')
)
str(inputs, max.level = 1)
...
Tranquil asked 5/10, 2019 at 3:40
14
Solved
I have a dictionary like this:
{
"id": "abcde",
"key1": "blah",
"key2": "blah blah",
"nestedlist": [
{
"id": &q...
Heritor asked 21/3, 2012 at 15:26
8
Solved
For example:
isin([1,2,3], [1,0,1,2,3,0])
will yield true because 123 is inside of 101230
I wrote the following code:
isin([AH|AT],[AH|AT]).
isin([AH|AT],[BH|BT]):- AH = BH, isin(AT,BT), isin([AH...
8
Solved
I'm looking for something kind of like Object.keys but that works for potentially nested objects. It also shouldn't include keys that have object/array values (it should only include keys with imme...
Koan asked 1/11, 2017 at 20:12
10
I had an object like this (fields in snake_case)
const obj = {
vt_core_random: {
user_details: {
first_name: "xyz",
last_name: "abc",
groups: [
{
id: 1,
group_type: "EXT"
},
{
id: 2,
g...
Glove asked 16/1, 2020 at 12:23
© 2022 - 2024 — McMap. All rights reserved.