Any idea how to detect a source code (Java, C#, SQL and so on) in a text file with Java without looking at the file extension or using an extraordinary long, ... |
I just saw Ikea's "Automated Online Assistant" and it looks pretty smart (for example I asked when one branch is open and it redirected me to correct page).
Does it uses just ... |
I am currently working through a book on algorithm design and came across a question whereby you must implement a greedy algorithm with dynamic programming to solve the coin change problem.
I ... |
I tried the sample demo at Codility website, and posted my soultion but I've a simple mistake but couldn't determine it.
The problem is described here (The problem is only described please ... |
For a blank n * n matrix, even n, we want to assign zeros and ones to this matrix so
that each row and each column contains exactly n/2 zeros and n/2 ... |
I am working on a distributed systems and I have to implement consensus algorithm ( pref. Paxos ). I was looking for any API which I can use to have ... |
package edu.uci.ics.jung.algorithms.cluster;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
...
|
|
I've noticed that in some devices without true optical focus control, (Blackberries, Android phones, etc), there's a built-in digital auto-focus mechanism.
I suppouse that this mechanism is fully implemented in software, applying ... |
Hello my question today is to breakdown and figure out how to actually code the LOWER TANGENT part of the algorithm Ive managed to complete steps (1) and (2) but I ... |
So I spent a week on this, and asked my peers, but we couldn't get it right. I turned it in as is, just to be ...
|
Spec
Counting in Lojban, an artificial language developed over the last forty years, is easier than in most languages. The numbers from zero to nine are:
...
|
Firstly i would like to say i dont want answers, just advice on how to go about achieving them, my main issue is how to implement both into java and compare ... |
For this task I'm supposed to create a "wannabe" network that is supposed to be a graph. The first file you read contains a textfile with vertices from/to and some other ... |
What is the best algorithm for bullet chart/graph visualization?
Bullet Chart
|
I'm trying to, using stacks, find a solution for placing k queens on an n X n chessboard, where k is < n, such that each cell is attacked. I'm thinking ... |
I have a bunch of Joda time Interval objects ( http://joda-time.sourceforge.net/api-release/org/joda/time/Interval.html ) stored in a List. All of these Intervals have valid start and end instants. These Intervals can ... |
Am really stuck and need some help from you guys.
Am implementing the NXN puzzel in 2-Dimensional array (using Java).
My questions are:
1)
How do i calculate the Manhattan distance in 2-Dimensional ... |
I am solving an NxN puzzle in java 2D array. I can move to the empty tile in say four directions : LEFT, RIGHT, DOWN or UP. My question is ... |
Am implementing the A* algorithm based on this tutorials:
create the open list of nodes, initially containing only our starting node
create the closed list of nodes, initially ...
|
I am implementing the AStar algorithm with Manhattan heuristic but I haven't been able to get it working.
I get infinite loop. The problem is in the search method. ... |
Mainly the implementation for Douglas-Peucker algorithm.
|
I want to develop a Java applet for the Addition Reference Bit Algorithm which is LRU page replacement algorithm. If anyone has already developed such a thing, it will be of ... |
Hi all, I want to implement a 2D corrdinate system in Java so that i can get the corrdination for each point i chosse. i have seen alot of applet that ... |
|
|
Hi, I need to read some text files, containing Left-To-Right text(Hebrew and Arabic, yet the two languages never appear in the same file). Unfortunately, the files were written by some ancient homemade DOS program, some 20 years ago. It used the following algorithm: Char encoding : IBM CP 824 (Arabic) , IBM CP 826 (Hebrew). Ordering: 'Visual BIDI Ordering' , i.e. ... |
Hi guys, I am coding a certain Swing application. This application is capable of saving data as files, which is a very common feature. However, I have a little problem here. After generating the saved file, I need to be able to open this file in a J2ME application. As a result, I will like to have this saved file consume ... |
je veux implmenter une application client-serveur et je veux utiliser l'algorithme EAP-MD5 pour l'authentification. j'ai trouv la documentation suivante: The EAP-MD5 algorithm consists of the following basic steps : 1. The client sends the username to the server in clear text. 2. The server validates the username and sends the client a clear text message(called the challenge). 3. The client uses ... |
Hello everyone. I am writing a program that uses the Java Robot class to basically do all of the keystrokes that a human would do in order to complete a certain process. The Robot performs these keystrokes on another windows program. My goal is to basically find a certain folder from a very large list. I search for this folder by ... |
A genetic algorithm is trivial in any programming language and so it easy to implement in Java. It is capable of finding global maxima much much quicker than other methods such as simulated annealing, as you can only jump between neighbouring solutions using a SA algorithm rather than around the entire search space with a GA (made possible through crossover). Consequently, ... |
Hi, I have a problem at hand and i kinda need some help. I have an array with some values inside and basically i need to check if the array (index value+1) == the actual value in that index and if so, i need to increase a counter. int a[] = {-1, 0, 2, 4, 5, 6, 7} and the result ... |
hi everybody, i am wondering: 1) does anybody here use any of the algorithms they were taught in their cs classes during their everyday java coding gigs? 2) what algorithms that you learned in your cs studies have you used recently? 3) if you haven't used any cs studies algorithms in your real-world jobs, why not? 4) if you do use ... |
I would suggest creating a hashtable with the initial string as the key and the string you wish to convert to as the value. For example, if a converts to t, Hashtable table = new Hashtable(); table.put("a", "t"); You can then take each letter from the word and us it to extract the value you wish to convert to. For example, ... |
I am having a resource scheduling problem now. I have 5 trucks and coming new job orders, and I need to make a autorunning program that can automatically check the status of truck and assign coming new jobs to it. the problem is that not only I need to balance the service time of each truck, but also I have to ... |
hi fellows..... i am trying to write a program to solve class scheduling program....the problem is based on implementing the walksat algorithm or hill climbing algorithm.....i have looked at these algorithms but unfortunalely i was not be able to understand them and how to code them.......i was thinking that i can get some tips and ideas that will help me in ... |
I am comparing two html files, using Levenshtein Algorithm. I am reading these two files in arraylist and giving as input to Levenshteing Algorithm. This algorithm uses Edit matrix for comparision with size m*n ( arrayList1.size() * arrayList2.size() ). It is working good and efficient for small files, but for large file it throws out of memory exception. To overcome this ... |
Sarah, Welcome to Java Ranch! I hope we can help you. In fact, I've tried to post an explanation several times, but I crashed the computer the first time and the second time I closed my browser on accident. I think there are plenty of resources on the Web that can explain it better than I can. Perhaps it will help ... |
hi, i was going through java exercise and i did not understand this exercise. if you know anything, please post your comment here. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). What is the maximum ... |
A friendly place for programming greenhorns! Register / Login Java Forums Java Java in General Algorithm Help Post by: John Brookes, Greenhorn on Apr 23, 2006 09:35:00 Righty-ho chaps, here's the situation: I'm creating a program that simulates traffic flow. I'm currently implementing speed limit zones. A "Limit" object (below) contains the value for the speed and a value ... |
|
I am trying to implement a minimax algorithm based on this pseudo code below. Could anyone tell me if this pseudo code is correct, because I'm haivng a hell of a time getting it to work. Some things I don't get are: 1. In the MinMove function why do they use move > best_move (identical to max move). Shouldn't the min ... |
Hi, I need to generate a digest value for securing my message. I am using the follwing piece of code to generate the digest value using the MessageDigest class. import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.Security; public class message { static String a = "SHA-1"; static String b = "SHA-256"; public static void main (String arg[]){ try { MessageDigest digest = MessageDigest.getInstance(a); ... |
Hi all, I am trying to develop a mechanism to know which machine can handle a user job (by providing his Requirements) for now I wrote this method but it is a Round robin, I am trying to modify it to a best-fit algorithm can anybody give me tips about how should I begin? public static String canDo(Resources userReq,Hashtable hash){ //getResourceInfo() ... |
what Ernest is saying is that you can use the bits in an integer (or long) as "flags" for whether or not to include an element. say you have 3 elements. 2 ^ 3 = 8. so, you need to count from 0 - 7 (giving you the 8 powerset elements). as you count, you look at which bits in your ... |
hi every1, im currently trying to do a very basic implementation of prims algorithm. At present i have an array of nodes (places) and edges (distances between the places) all within the form of an adjacency matrix. Iv now started Prims algorithm and i am trying to call the first node with the follwoing lines of code, altho it compiles and ... |
Dear Readers, I am using a program that allows the user to input two colors, one a Foreground color and the other a Background color. The program outputs whether the two colors have sufficient "color difference" and sufficient "brightness difference". If both conditions are fulfilled then these colors can be used as Foreground and Background colors. I analyzed the outputs for ... |
Alright, I've been having some trouble with this. Basically, I need to read in 2 integers (for example, 10 and 15), then multiply them like so: a * a + 1 * ... b. So, for our example, we would need to multiply 10 x 11 x 12 x 13 x 14 x 15 and output the answer. Here's what I ... |
Given that no-one else has replied, I suspect they all thought "WTF?", like I did. I think you're assuming that these "polynomial algorithms" are something well-known. But it doesn't look like anything I've ever seen and I did a fair amount of numerical computing. Please give some more background, then maybe we can help. (Yes, I do know what a "polynomial" ... |
|
Originally posted by ramanuja varun: Does the garbage collector use any algorithm? If yes please do mention that. Wow. Yes. It uses tons of algorithms.... Overall, the Sun GC breaks the heap into two generations. Young, which is generally for newer short lived objects. And Tenure, which objects gets promoted to after this lived for awhile. For the young ... |
Hello again, I've been revamping my Data Structures skills for a more modern JDK 1.5 (back in '96, when I was in college, I used GNU C in my Data Structures course). Reached a particular problem... Here's the TestCase: import junit.framework.TestCase; public class SortUtilTest extends TestCase { public void testInsertionSort() throws Exception { Integer[] is = { 5, 4, 1, 3, ... |
In the following string: f b, b c, a c, e b, d a, g a two letters are tuples with each tuple separated by commas. The first letter in each tuple is a node and the second letter is the parent of the node. Please write a function that takes the string as input, and outputs a representation of the ... |
Hi Satnam, Last time when I was visitng Manning's website I found that there are two similar titles scheduled to be published in 2008: one is your book and the other one is "Algorithms of the Intelligent Web". At first sight, these two titles seem to be very similar. What do you think? Will these two books cover the same stuff ... |
I reading the Wikipedia entry for the Boyer-Moore Algorithm for searching through strings, and I was wondering if someone can explain to me (in simple words with perhaps a simple example) of how the "good suffix shift" table is computed. I understand how the "bad character shift" table is calculated, but I can't seem to understand how the "good suffix shift" ... |
Welcome to JavaRanch. If I understand it correctly, then the keys of the Map are strings, and the values are the frequencies in which they occur? In that case, you can use a SortedMap instead of a HashMap. It keeps the elements in the natural order of their keys if you obtain an iterator from it. |
This is a standard algorithm for programming regardless of the language, C, C++, Pascal, Java, etc. As far as I know, there is no method in the java API called bubble sort. Check your local library for a book on algorithms to get the general concept. A good one is Data Structures & Algorighms in Java by Mitchell Waite. |
|
This question has always bothered me in a book I read a while ago and I can't find a proper solution. It's a program to convert a given number(integer) to roman numerals, for some reason I think I'm not doing this the most efficient way. Whenever code is repeated like this, there has to be something I missed. Loops aren't even ... |
Hallo, I'd like to have some information on "2,3,4 Tree" algoithm and it's realization using Java. I tried to use Google but it was helpless or my request was not good enough. So i have nothing on this at the moment. I would be really appreciated if you posted some links about this algorithm. |
For some reason this program spits out a bunch of errors in the DOS window, but none in my ide. Any noticeable problems with my code? import javax.swing.*; import BreezySwing.*; public class PIGuiNewton extends GBFrame{ private JLabel itLabel; private JLabel numLabel; private IntegerField itField; private IntegerField numField; private JButton itEnter; private int iterations, i, num; private double guess; public PIGuiNewton() { ... |
Hi everybody! I can't seem to figure out how to make an array of circles move! The problem requires me to animate a number of circles input by the user clockwise around a square of side 400 pixels with a 20 Milliseconds delay. At each move the circles must be capable of changing direction with probability input by the user at ... |
Given these 2 definitions of algorithm, your request may need to be a bit more specific. Gary. WordNet Dictionary Definition: [n] a precise rule (or set of rules) specifying how to solve some problem Computing Dictionary Definition: A detailed sequence of actions to perform to accomplish some task. Named after an Iranian mathematician, Al-Khawarizmi. Technically, an algorithm must reach a result ... |
Hi Rico, Welcome to JavaRanch! We don't like to hand out solutions to homework problems here. We do, however, like to help people figure them out for themselves. If you give it a try, and then show us what you've got, we'd be happy to critique it; if you get stuck, we'll be happy to give you a hint. If you ... |
in other words a computer program is a specific implementation of an algorithm or set of algorithms designed to be used in conjunction with computer hardware (and possibly other programs) to solve a problem whereas an algorithm does not define the way it is to be implemented (though specific algorithms might by their nature suggest specific implementations). |
hello, im in the middle of making a program and have hit a strange problem which im sure you can me fix! :-) -i have a grid of squares and a jbutton. -when the button is pressed, a random number is made that decides the next step. - step A - adjacent squares change color, direction down, or right. - step ... |
Thanks for your reply. The Listener part is not the problem. I have done all that. Please take a look at what I have been trying to crack since Tuesday. I must say that this is neither a class assignment nor a project at work. I passed the scjp last December and the only way I can know my craft is ... |
Does anyone know the algorithm for drawing polygonal lines (ie: from (x1,y1) to (x2,y2) for any value of the x/y variables)? I can't use the Java libraries to do it because, to be honest, I'm doing it in C and I haven't got enough program memory to store the maths libraries. I haven't been able to find any algortihms on the ... |
hi, This is just a simple program that finds the adjcanet squares ofa selected square. As the range increases, so will the number of LOC, using my current method. anyone any ideas how to implement this in a nested loop? int x = currentUnit.unitCol; int y = currentUnit.unitRow; try { layerOneRef[x][y + 1].movePhase = true; } catch (ArrayIndexOutOfBoundsException e) {} try ... |
OK, starting to actually put my project together and have been trying to figure out how I am going to accomplish the following: I have a tournament with 4 different divisions. Each of these divisions is made up of a varying number of teams (from 3 to 7 teams per division). Each team needs to race the other in a "Round ... |
1) How to find 5 most frequent apprearance workds in a words array? what if the size of the array is so big that we only need ot find approximate 5 top popular words? 2) Assume speed is more important than storage. How do you count the number of bits that will set in 32 bit integer? Please help. Thanks! |
|
I don't think there is a solution. A really small triangle, and a really large triangle, may have the same center. So almost any point can be in the triangle or not, depending on the size of the triangle. You don't know the size, only the center, so you can't tell if the point is in the triangle. Henry |
|
Hi there! I'm witing because i've been working on a project, in this project The user has to give the initial city an the final. I've read about the Floyd's Algorithm. In my project i just have to use the final step of Floyd's Algorithm that is to check the final adjacency matrix, given by me. /* * Shortest Path Between ... |
Dear Readers, I am using a program that allows the user to input two colors, one a Foreground color and the other a Background color. The program outputs whether the two colors have sufficient "color difference" and sufficient "brightness difference". If both conditions are fulfilled then these colors can be used as Foreground and Background colors. I analyzed the outputs for ... |
|
This looks an awful lot like a homework problem. or at the very least, a theoretical exercise you have given yourself. So, it would be pointless at best, and cheating at worst for someone to give you the solution. So, what have you tried? where are you stuck? what do you think will or won't work, and why? |
How to implement an algorithm that averages an array of N doubles, and is relatively free from bug? It should take care of overflows, and be reasonably fast. Simply accumulating and then divide is susceptible to overflow while dividing all values by N prior to summing them takes 2x the required operations to calculate. [ October 22, 2007: Message edited by: ... |
Just for clarification, I'm only asking out of academic curiosity. After I discovered the XOR swap algorithm I demonstrated my cleverness to my co-workers around the water cooler when the question of floats came up. The idea of converting the floats to integers doing the XOR swap and the converting back came up, but didn't seem like a good solution (figuring ... |
You may prefer to use the System method which gets time in nanoseconds, called something like nanoTime() (look in the API for the correct spelling).long startTime = System.nanoTimeOrSimilar(); . . . carry out algorithm, or do nothing at all. . . . long runTime = System.nanoTimeOrSimilar() - startTime; System.out.printf("My algorithm took %d.%03d microseconds.%n", runTime / 1000, runTime % 1000);Also note how ... |
Matlab (like Mathematica) is a standalone program for solving math-related problems. It includes a complete programming language to do that. There's probably a Java API for it, too. It's not cheap, though. It would be easier to help you if you were more specific about what kinds or algorithms you'd like to implement - differentiation, integration, differential equations, ... ? You ... |
Dear all, I want to implement KMP alorothem in Java. but i can not understand how it works. though i went through google, still the situation is same. can anybody help me in this matter. my basic problem is how to create the shifting table (in most web sites, next[]). Or can somebody direct me to a simple tutorial on KMP ... |
Write a java program using following details. You are free to make all necessary assumptions. All the assumptions made should be documented. There are four scientists who need to be ordered according to their smartness (smartest to least smart). There is a text file "smart.txt" in the following format: Satish Arun Ramesh Suresh Ramesh Satish Suresh Satish Each line has a ... |
step1. mid_index = (total_length - 1)/2 (for odd) or (total_length/2)-1 for even step2. max_index = total_length - 1 (to pick up letters from end) step2. loop_index = 0 step3. pick letter at loop_index, pick letter at max_index - loop_index step4. compare them, if not equal, print "not palindrome" and exit. step5. loop_index = loop_index + 1 step6. if loop_index > mid_index ... |
|
Howdy. I'm working on writing an anagram generator that can take a String, shuffle it around & compare the permutations of all the chars against entries in a known word list. I have a good start - I can perform a search against char permutations of the entire String, but I'm stuck as to how I should write the part that ... |
|
Hi, I have here a simple program to find the GCD - Greatest Common Divisor of 2 numbers using Euclidean algorithm. I guess that's the fastest way to compute GCD. Here is the code: public static void main(String[] args) throws IOException{ BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int diff=0; System.out.println("Enter num1: "); int x = Integer.parseInt(read.readLine()); System.out.println("Enter num2: "); int y ... |
|
I am new to java programing and algorithms I was going through the the java tutorial and was quite proud of myself as I was surviving chapt. 3 then I came across this demo and began to lose my footing Can you please help me by explaining these few lines of code in the ContinueWithLabelDemo? correct me if i am wrong ... |
the cuboid is specified by two vertex which are Point3D objects meaning that they are parallel to the axises. My approach is to first determine if the two cuboids have common space by compare the distance between two mid-point of the two cuboids with half of their length on the X,Y and Z axis respectively. If they do have common space, ... |
|
|
i don't know if this is the right forum.I wish to implement the token ring algorithm for mobile hosts.I have information as below for the algorithm. A fundamental algorithm in distributed systems consists of circulating a token amongst participants in a logical ring. Each participant executes as follows: wait receipt of token from its predecessor in the ring; enter ... |
import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet; public class MainClass { static void fill(Set s) { s.addAll(Arrays.asList("one two three four five six seven".split(" "))); } public static void test(Set s) { System.out.println(s.getClass().getName().replaceAll("\\w+\\.", "")); fill(s); fill(s); fill(s); System.out.println(s); // No duplicates! s.addAll(s); s.add("one"); s.add("one"); s.add("one"); System.out.println(s); System.out.println("s.contains(\"one\"): " + s.contains("one")); } public static void main(String[] args) { test(new HashSet()); ... |
Hi folks , I have been trying to implement this algorithm and have been stuck up on with a error i.e Array index out of bounds exception. The Algorithm traverses a 2D NxN array, making every element the average of its 4 surrounding neighbors (left, right, top, down). The NxN array has initially all zeros and is surrounded by a margin ... |
Okay, so I'm sure I'm not thinking of something simple here, but here goes... The assignment was to take some input file and read it (which I have done, presumably correctly)... the file contains lists of people. The people can be sorted into two categories. Each person is followed by a secondary list of people which are in the "opposite" category ... |
I have a few Lists of Strings. for example: List AList contains {"a1","a2","a3","a4"} List BList contains {"b1","b2","b3"} List CList contains {"c1","c2","c3","c4","c5"} List DList contains {"d1","d2"} so on and so forth. The number of lists is variable and number of Strings in the list is also variable. I want to write a code that returns ALL POSSIBLE combinations under the following conditions: ... |
Hey there folks, for those who remember me, I posted a topic earlier this weekend on how to write a program that allows the user to take one set of toothpicks to another in order to solve it in 3 steps. The second part was having the computer solve the problem itself, which I also wrote. However, this 3rd step is ... |
|