An algorithm is a precise plan (in the format of a sequence of steps) on how to solve a particular problem.
0
votes
1answer
76 views
Deep copying objects with circular references
I've found a good example of how to do this in Java and how you can get the same behavior in c#, so I've made made an attempt at it:
public class CircularReferenceOne
{
public int Identifier;
...
2
votes
1answer
65 views
General case of the 24-challenge problem
I'm working on an algorithm to solve the 24-challenge game. The basic idea is to combine positive integers using arithmetic operators to produce an expression that evaluates to exactly 24. For ...
-1
votes
0answers
29 views
Java: Linked list reverse couldn't work [closed]
I have read this stackoverflow thread
I want to test if it works.
However, the result was not expected, it should print out
apple
orange
banana
instead of
apple
banana
My testing code
...
2
votes
0answers
108 views
Connect Four AI (Minimax) in Clojure
I wrote a Connect Four game inlcuding a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc.
But ...
1
vote
2answers
54 views
Check if a Binary Tree <String> is aBinary Search Tree
i'm understanding the question but wanna make sure if my implementation is correct or not =|
The Q is :
Write a method that accepts as its argument a BinaryTree object and returns true if the ...
0
votes
0answers
63 views
Hanoi Towers - need help with the code
I made an algorithm solving Hanoi Tower puzzles, for n disks and m pegs.
It uses lists as pegs, each list's element contains disks array - {0, 0, 0} means the peg is empty, {1, 2, 0} means the peg ...
-1
votes
1answer
33 views
C++: Last digit of an exponent of number - wrong answer [closed]
I'm trying to implement a simple program that takes base and exponent and output the last digit of a result of exponentiation, but online judge says that my program gives wrong answers. What could be ...
2
votes
1answer
123 views
Is this implementation of Kruskal's algorithm maintainable and efficient?
Update
I've posted some updated code and included the definition of Vertex and Edge to try to answer as many questions as I could. To summarize what's changed:
I've followed the advice here to ...
4
votes
2answers
97 views
Prime sieve: improve efficiency while keeping it reasonably simple?
public static void listPrimesThree(int maxNum){
long startTime = System.currentTimeMillis();
boolean[] booleanArray = new boolean[maxNum+1];
int root = (int)Math.sqrt(maxNum);
for (int m = 2; m ...
0
votes
2answers
85 views
C++: Prime Number Generator algorithm optimization
I've implemented a simple program that finds all prime numbers between two integer inputs using Sieve of Eratosthenes, but online judge is still complaining that time limit is exceeding. Maybe I'm ...
0
votes
2answers
78 views
How to take the some elements of a list of random numbers and sort them?
I want to create a file consisting take rows of distinct numbers in ascending order. They are randomly taken from the first total integer. The file will be used to make an excerpt as discussed here.
...
1
vote
0answers
35 views
Can I make my render method more efficient?
I get great FPS with this as is, but I'm a performance freak and I don't know AffineTransform or the Java graphics libraries very well. I'm sure there is something I could be doing differently to make ...
5
votes
4answers
142 views
Readability and Performance of my Trie implementation
As an interesting exercise in Python 3.3, I implemented a Trie (also known as a Prefix Tree).
Example usages
Create from list of key-value-tuples
mapping = (('she', 1), ('sells', 5), ('sea', 10), ...
2
votes
1answer
90 views
PHP - Alternated Caesar Cipher, code could be improved?
I've recently picked up PHP and due to having an IT-security class I tried out to code the first assignment in PHP.
The algorithm I took upon is an alternation of the caesar cipher, instead of using a ...
3
votes
1answer
43 views
Finding missing items in an int list
Here is a problem I am trying to solve: trying to find missing photographs from a sequence of filenames. The problem boils down to: given an unsorted list of integers, return a sorted list of missing ...