if given a 15 digit number whats the best way to find the next palindrome?
in c++ what will be the fastest logic to find next palindrome of a given 15 digit number? for example what will be the next palindrome of: 134567329807541 ? ...
in c++ what will be the fastest logic to find next palindrome of a given 15 digit number? for example what will be the next palindrome of: 134567329807541 ? ...
Hi, I have problem reading/println after the first two FOR loop in this method. This is strange. How can I solve this problem? private int spacing() { int n = numberOfTriangles(); ArrayList<Double> list_Xs1 = new ArrayList<Double>(); ArrayList<Double> list_Ys1 = new ArrayList<Double>(); for(Polygon p:triangles){ double cX =...
Suppose I have this table: ID | description ------------------- 5 | The bird flew over the tree. 2 | The birds, flew over the tree These two rows have "similar" content. How would I remove #2? What algorithm should I use for "similar" text? How would I do this with Python? Thanks! ...
I'm looking for a efficient searching algorithm to get the longest shortest repeated pattern in a collection (~2k of integers), where my collection is made of this repeated pattern only (there is no noise between repeated patterns), but the last occurence of pattern may be incomplete. Examples: I've got: [2,4,1, 2,4,1, 2,4,1, 2,4,1, 2,4...
import java.util.Scanner; public class Fraction { private int numerator; private int denominator; private int product; private int sum; public Fraction(int num, int denom) { this.numerator=num; this.denominator=denom; if (this.denominator == 0){ System.out.println("can not divide by zero"); }// end if }// end fraction ...
Hi, Let f transform one value to another, then I'm writing a function that repeats the transformation n times. I have come up with two different ways: One is the obvious way that literally applies the function n times, so repeat(f, 4) means x → f(f(f(f(x)))) The other way is inspired from the fast method for powering, which means div...
Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit indus...
If you have 5 distinct numbers, how many comparisons at most do you need to sort this using merge sort? ...
I m very curious, why stability is or is not important in sorting algorithms? Any ideas? ...
what is plane sweep algorithm to compute all intersection points between the circles? ...
I want to know the idea of algorithm for the coin change problem where each denomination has infinte number of coins. Means how to apply DP (like the standard coin change problem) For e.g in set 1,10,15, change for 35 gives--2 coins of 10 and one coin of 15 Also give me an idea of brute forcing algorithm for this. I know to iterate ove...
Hi, I've been working on a Sudoku Solver, my current solver uses the backtracking algorithm but it still takes too long. I'm hoping to get it down to less than a second for most cases. As such, I've decided to rewrite it with the dancing links algorithm, understanding it is one of the better bruteforce methods that works well especiall...
Hi, I'm hoping to optimize my backtracking algorithm for my Sudoku Solver. What it does now: The recursive solver function takes a sudoku puzzle with various given values. I will scour through all the empty slots in the puzzle, looking for the slot that has the least possibilities, get the list of values. From the list of values, ...
Say I have a square from (0,0) to (z,z). Given a triangle within this square which has integer coordinates for all its vertices. Find out the number of triangles within this square which are congruent to this triangle and have integer coordinates. My algorithm is as follows-- 1) Find out the minimum bounding rectangle(MBR) for th...
Hi, There is a question in TAOCP vol 1, in "Notes on Exercises" section, which goes something like: "Prove that 13^3 = 2197. Generalize your answer. (This is a horrible kind of problem that the author has tried to avoid)." Questions: How would you actually go about proving this ? (Direct multiplication is one way, another way could ...
The world consists of many (1k-10k) rectangles of similar sizes, and I need to be able to quickly determine potential overlaps when trying to add a new rectangle. Rectangles will be added and removed dynamically. Are R-Trees appropriate here? If so, are there any good libraries I should consider? (I'm open to suggestions in any language)...
I would like to track a color in a set of images. For this reason I use the algorithm of constant thresholding mentioned in Introduction to Autonomous Mobile Robots. This method simply marks all those pixels that are among a minimum and a maximum threshold of red, green, blue (or hue, saturation, value in my case). My problem is that ...
is there a way we can detect a person's body in the image and cut the only body part of the image. ...
I have a bipartite graph. I am looking for a maximum (1,n) "matching", which means that each vertex from partitation A has n associated vertices from partition B. The following figure shows a maximum (1,3) matching in a graph. Edges selected for the matching are red and unselected edges are black. This differs from the standard bipa...
I have a dynamic number of equally proportioned and sized rectangular objects that I want to optimally display on the screen. I can resize the objects but need to maintain proportion. I know what the screen dimensions are. How can I calculate the optimal number of rows and columns that I will need to divide the screen in to and what si...