# Tagged Questions

Recursion in computer science is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem.

1answer
47 views

### Recursive Implementation of Merge Sort C++

I am currently reading an algorithms book and I read on the insertion and merge sorts. I implemented the merge sort in C++, The first function MERGE is responsible for the merging of the two subarrays ...
2answers
64 views

### Evaluating a completely parenthesized arithmetic expression

I tried to solve the following problem in a programming challenge, but the verdict was time limit exceeded. Completely parenthesized expression Write a program that reads a completely ...
0answers
10 views

...
2answers
44 views

### Euclid's algorithm GCD finder and fraction simplifier

This program is a practise exercise in using instance methods, and also in recursion which I struggle to get my head around. I want to know how my technique for the recursion could be improved, and if ...
1answer
45 views

### Traveling Salesman Planet Edition

I completed this problem for an interview and my solution as rejected; of course no reasons were provided. I opted to use the nearest neighbour algo based on the timeframe allotted and having no ...
1answer
643 views

### Code smell when recursively returning a List

So this is part of my AVL tree implementation, namely the infix representation of the tree. Since I wanted to use a recursive method to stay close to the original algorithm and want to return a list, ...
0answers
19 views

### The Miller-Rabin Primality Test in Clojure

I am new to clojure and I wanted to test out my skills by taking an existing implementation written in Python and writing it in Clojure. Concerns My main concerns are where I use ...
2answers
24 views

### Finding Permutations in Haskell

I wrote a function to find all the possible permutations of a list in Haskell. I know it can definitely be optimized, but I'm not sure how. I'm pretty sure foldl or ...
2answers
800 views

### Minesweeper C++

This is my improvement of a minesweeper game I took from the internet, which I am quite proud of. Nevertheless I am willing to hear your opinions, suggestions, and comments. ...
2answers
116 views

### Recursive implementation of a zip function in F#

I'm learning F# from Tomas Petricek's "Real-World Functional Programming" book. As suggested at one point in the book, I started implementing a zip function using a ...
0answers
73 views

### CodeEval - Lucky Tickets challenge

This a solution to the CodeEval's challenge "Lucky Tickets". After a failed attempt with brute-force calculations (no surprise here), I have tried to implement an algorithm that I found on ...
1answer
67 views

### Recursive Breadth First Search Knights Tour

This program was written on Windows 7 using Visual Studio 2012 Professional. Some of the issues encountered may have been fixed or changed in a more recent version. This is a quote from my second ...
2answers
39 views

### Recursive Scala Case class Reduction

I have a case class that is recursive and looks like this: ...
1answer
58 views

### Count digits in a given number using recursion

Here is my code that finds the number of digits in a given integer (either positive or negative). The code works and results in expected output. ...
3answers
105 views

### Recursively moving every lowercase 'x' in a string to the end

Given a string, compute recursively a new string where all the lowercase 'x' chars have been moved to the end of the string. ...
1answer
81 views

### Knights Tour - Improved Refactored Recursive Breadth First Search for

The development and testing was performed on a Dell M6400 Laptop (Intel Core 2 Duo) running Centos 7, g++ compiler version 4.8.5, compiler switches -O3 -std=c++0x -D__cplusplus=201103L. (machine ...
1answer
133 views

### Animate and play sounds in Simon Says 'the Angular way'

I am a newbie coder and I'm trying to learn good coding habits. I'm making a Simon Says game challenge from Free Code Camp in Angular JS. Codepen I have an array that keeps random integers between ...
1answer
99 views

### Find the number of possible infinite cycles that Bessie the Cow can get stuck in

Bessie the cow is in Farmer John's field. The field is of size 0..1,000,000,000 for x and y. Farmer John knows that there are N/2 wormholes at certain coordinates, but he does not know which wormholes ...
3answers
96 views

### Recursive function that reverse the words in a string

I have been working on a problem that asks me to a write recursive function that can reverse the words in a string. For example if the string is "cat is running", then the result should be "running is ...
1answer
93 views

### Recursive flattening of Swift sequences - an overly complicated approach

I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
1answer
75 views

### Knight's tour code

Another one for some late night snack. - Knight's tour! Please provide your suggestions/flaws/optimization to this knight's tour backtracking code.. ...
1answer
117 views

### Number of unique sequences of 3 digits, given a length is equal to sum

This is the "Minion's bored game" problem from Google's "Foobar challenge": There you have it. Yet another pointless "bored" game created by the bored minions of Professor Boolean. The game ...
0answers
29 views

### Directory listing in Node.JS

This solution works, and I like having all the logic after the return. The main purpose of this function was for use with other functions to return a file list: ...
2answers
95 views

### google foo.bar max path algorithm puzzle optimization [closed]

I got a programming puzzle described as follows: Save Beta Rabbit Oh no! The mad Professor Boolean has trapped Beta Rabbit in an NxN grid of rooms. In the center of each room (except for ...
1answer
88 views

### Calculate the arclength

I am trying to estimate a good approximation for the arclength of the curve $y = \sqrt{1-x^2}$ for $x \in [0, 1]$. I did this using a Bezièr curve, and made it so that the area under the two ...
1answer
29 views

### Recursively walk directories with a callback function

This code works, but I want to refine it: ...
2answers
83 views

### Reverse a linked list recursively

This recursive calls reverseList on each node of the linked list. When returned from the function call, it changes the next link to the previous node. ...
1answer
95 views

### AI Tetris-like game

I was thinking to rewrite my Python code to C++ since it contains quite a lot of simple loops. I was stunned to find out that this critical part of code (the code below) is about 5 times slower than ...
1answer
54 views

### Storing hierarchical data into a data structure

With the following data in a table, ...
1answer
63 views

### Shell command line program

I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
2answers
57 views

### Finding all non-empty directories and their files on an SFTP server with Paramiko

The purpose of the following function is to find all non-empty directories, and the files in those non-empty directories. It recursively checks each directory on an SFTP server to see if it has any ...
1answer
133 views

### Searching a maze using DFS in C++

I have started learning recursion and search algorithms, especially DFS and BFS. In this program, I have tried to make an implementation of a maze-solving algorithm using DFS. The program is working ...
1answer
41 views

### Finding Sylvester sequence code

I've written this code to calculate the Sylvester sequence, which is defined as $$s_n = s_{n-1}(s_{n-1}-1)+1$$ where $s_0=2$. ...
1answer
34 views

### Get properties from all children in a recursive SQL structure

In our product, Company is a model that can have many Companies belonging to it; so some Companies are parents, some are children, and many are both. We have a ...
1answer
32 views

### Get all combination of a nested object with arbitrary levels

I have a JSON data which can be an object/array of recursively nested object or array. The value of an array can not be null, but an value in a object can be null. I would like to return all ...
1answer
40 views

### Get all combination of a nested object

I have JSON data which can be an object/array of recursively nested object or array. The value of an array can not be null, but a value in an object can be null. And I would like to return all ...
2answers
41 views

### Remove all occurrences of a digit from a number

I need to remove all occurrences of a digit from a number in a recursive function with this prototype: unsigned rem(unsigned num, unsigned dig); This is my ...
3answers
142 views

### Recursive methods of singly linked list

Can anyone review the methods? If there are better ways to write a certain method I would appreciate it if anyone could tell me. ...
2answers
129 views

### BF interpreter in Python that uses recursion to handle loops

I wrote a Brainfuck interpreter in Python and I'm wondering how to simplify it. I handle separately loop commands and the others. A recursive function deals with loops. ...
2answers
69 views

### Traversing javascript/json based on a dot-separated lookup string

I have an object of arbitrary depth, and a string (or array) containing the keys which have to be traversed to get to the value. As far as I know, there's no method to get to the value directly: <...
1answer
45 views

### Counting occurrences of “hi” in a string, except where followed by “x”

I already solved this one from CodingBat, but I'm unsatisfied with my solution and I feel I could have made it much shorter. Most of the other recursion tasks could be solved by a one line conditional ...
2answers
96 views

### Integer to English challenge

I have a challenge, which is to create a JavaScript function that turns a given number into the string representation. For example: console.log(inToEnglish(15)) ...
0answers
73 views

### Hierarchical Data to Graph

I am using vis.js to visualize some hierarchical data. I have created a recursive routine to add nodes and edges for each group and value in the dataset. I feel like something already exists for this ...
1answer
28 views

### Liquid navigation tree generator

This include was written for a Jekyll site I'm building. It generates nested HTML unordered lists to a given depth dynamically by parsing page urls. It works fine, but the code feels messy and it ...
2answers
255 views

### Java 8 Stream to produce all permutations of an array using recursion

I want to write a class that returns a Stream of permutations of an int[]. ...
4answers
117 views

### Copying file dependencies

I have written the following code, and it works great, but I'm not satisfied. I really love the book "Clean Code" by Uncle Bob and I try to apply all his principles when coding, but I'm having a tough ...
1answer
76 views

### Object-to-array flattening function

I have written a function that is designed to convert an object into an array of key/pair values ("flattening it") like so: Input ...
1answer
85 views

### Find all distinct subsets that sum to a given number

The function wants to achieve to find all distinct subsets that sum up to an given number. ...
1answer
40 views

### Find zeroes in a matrix

I am looking for the elements that are zeroes in a square matrix (of size n), as a list of pair. I don't really like the following code, some condition seems ...
0answers
51 views

### Recursion into git diff tree using nodegit

I'm using nodegit to develop the backend for a nodejs app that uses a mix of mongodb and git for persistence. The app has to version documents and be able to present diffs between versions, thus the ...