Getting Infinite Loop Babylonian Algorithm R

I am trying to do the Babylonian Algorithm in R and can't quite figure out where I'm wrong. Basically, I'm trying to calculate the square root of x using the Babylonian algorithm. It consists of guessing the root of x, - (let's call this r). Let's sa...
more »

2017-10-08 23:10 (0) Answers

Find words and put spaces after them

Once I was asked a question in an interview and I am still not clear how to solve it. Or couldn't even get close to it. Q. Given is a of series of characters eg."thisisachallengingquestion", Write a program to put space after every word except the ...
more »

2017-10-02 23:10 (2) Answers

memoization not working as expected

I am new to algorithms and so I was experimenting with several possibilities of algorithms, specially memoisation I have a simple Fibonacci series recursive function using memoisation class Memoize: def __init__(self, f): self.f = f ...
more »

2017-10-02 07:10 (1) Answers

Graph library for virtual (dynamic) graph search

As a part of a larger algorithm, I need to run graph search algorithm (A* family) on a graph that is created dynamically during the search. I cannot instantiate the whole graph because it is exponentially large though not infinite, and most nodes wo...
more »

2017-09-28 16:09 (0) Answers

search a line in preprocessed big text file

I have a data file which contains 100,000+ lines, each line just contains two fields, key and value split by comma, and all the keys are unique. I want to query value by key from this file. Loading it to a map is out of question as that consumes too ...
more »

2017-09-26 13:09 (3) Answers

N-length sequences of pairs following conditions

I have the following 2d-array of fruits: fruits = [["apple", "lemon"],["apple", "cucumber"],["carrot", "lemon"],["carrot", "cucumber"],["peach", "cucumber"],["lemon", "melon"],["grape", "cucumber"],["lime", "lemon"],["lime", "cucumber"],["apricot", ...
more »

2017-09-25 23:09 (4) Answers

Year to Century Function

Problem: Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc. My Code: def centuryFromYear(year): century = ye...
more »

2017-09-22 06:09 (2) Answers

Precalculate Result of A*

Currently learning about the A* search algorithm and using it to find the quickest solution to the N-Puzzle. For some random seed of the initial starting state, the puzzle may be unsolvable which would result in extremely long wait times until the al...
more »

2017-09-21 20:09 (2) Answers

Optimization of profit in Ruby

I'm using Ruby, but for the purposes of this problem it doesn't really matter. Let's say I have two different kinds of resources, the quantities of which are denoted by a and b. I can allocate d new resources, and since a and b are of equal cost an...
more »

2017-09-21 01:09 (2) Answers