Skip to main content

All Questions

0 votes
3 answers
88 views

difficulty to understand the code, and maybe the concept itself (recursion problem)

this code below is from Grokking Algorithms book that is an exercise for the functional programming/recursion and an application for the D&C concept. the function finds the maximum number in a ...
Ahmed Salah's user avatar
-3 votes
3 answers
670 views

find in deep nested array (tree) recursivley

I want to find a value in the following nested array without using loops: let children = [ { name: 'grand 1', children: [ { name: 'parent 1.1', children: [ { ...
Thore's user avatar
  • 33
0 votes
2 answers
80 views

Make Recursive Function Functional in Javascript

I am implementing a recursive encryption for Javascript objects but the solution I came up with is non-functional. This has caused some weird errors as it manipulates the object directly. Is there any ...
Paolo Tormon's user avatar
0 votes
2 answers
979 views

thread 'main' panicked at 'attempt to add with overflow', test.rs:15:12

I have been learning rust while practicing recursion. So this is just a simple recursive problem and the type is an signed8 and should be working. But I get this error which I am not able to ...
Pr00grammer's user avatar
7 votes
2 answers
218 views

Memoize multi-dimensional recursive solutions in haskell

I was solving a recursive problem in haskell, although I could get the solution I would like to cache outputs of sub problems since has over lapping sub-problem property. The question is, given a grid ...
Adeeb HS's user avatar
  • 169
3 votes
1 answer
255 views

Is it possible to reduce a fraction to the lowest form in a single recursive pass, using no auxiliary functions other than is_zero, succ and pred?

Is it possible to reduce a fraction to the lowest form, in a single recursive pass, using no auxiliary function other than is_zero, succ and pred? As an example, if we wanted to implement gcd that way,...
MaiaVictor's user avatar
  • 53.1k
3 votes
2 answers
627 views

Ocaml - writing a function who's number of arguments is determined at runtime

I want to write a function f, that takes n arguments, where n is determined at runtime, and might vary at every call to the function, for example let's say our function f takes an integer n which is ...
hra1234's user avatar
  • 409
0 votes
1 answer
109 views

Generating permutations in Lisp withous map functions

I want to generate in Lisp the list of all permutations of a set. This is what I tried: (defun ins(e n l) (cond ((equal n 1) (cons e l)) (T (cons (car l) (ins e (1- n) (cdr l)))) ...
hackermanwasd's user avatar
2 votes
2 answers
207 views

Functional/Stream programming for the graph problem "Reconstruct Itinerary"

I am trying to solve the reconstruct itinerary problem (https://leetcode.com/problems/reconstruct-itinerary/) in Scala using functional approach. Java solution works but Scala doesn't. One reason I ...
Dhaval Kolapkar's user avatar
1 vote
2 answers
103 views

Confusing call sequence in scala recursion

I am trying to trace recursion processing in scala. The following is the code sample: def factorial(n: Int): Int = if (n <= 1) 1 else { println("Computing factorial of " + n + " - I first ...
Loom's user avatar
  • 10k
0 votes
0 answers
50 views

Why my algorithm is using not a linear memory space?

I'm currently writing this roll equality checking algorithm just for fun, the main goal is to do it declaratively and in functional style. Somehow my algorithm uses non-linear memory-space. In fact, ...
Danil Mednikov's user avatar
3 votes
5 answers
3k views

How to transpose an m*n matrix using recursion?

I'm trying to transpose a matrix using recursion. Now, I know that under normal circumstances this isn't a good idea and a nested loop/nested map, or a similar approach is superior, but I need to ...
user1984's user avatar
  • 6,888
0 votes
3 answers
324 views

Print series of number every 50

I need to paginate through an API and I am creating the URLs. The URL looks like this: /search/officers?q=XXXXX&items_per_page=50&start_index={} The maximum items per page allowed in the ...
Tytire Recubans's user avatar
1 vote
1 answer
1k views

Set a weight to each item in a list [closed]

I have got a comma-separated list of fruits, and they are listed in order from most-relevant to least-relevant. e.g: "fruits":"apple, orange, lemon, apple, strawberry, pineapple, banana" I need to ...
D.B's user avatar
  • 4,329
2 votes
3 answers
442 views

How to handle multiple variables in a Clojure algorithm implementation?

I'm new to Clojure and trying to learn by implementing some algorithms in it. The algorithm I'm writing is for calculating the node betweenness centrality metric for a graph data structure. The ...
sfactor's user avatar
  • 13.1k

15 30 50 per page