All Questions
30 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 ...
-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: [
{
...
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 ...
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 ...
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 ...
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,...
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 ...
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))))
...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...