Optimization is the act of improving a method or design. In programming, optimization usually takes the form of increasing the speed of an algorithm, or reducing the resources it requires.
-1
votes
0answers
17 views
Using for loop to get the Hamming distance between 2 strings [closed]
So i'm having some trouble with this code. i need to get the Hamming distance (the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols ...
5
votes
1answer
135 views
Code Review for Hangman in C++
I have the following C++ program:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
void printVector (std::vector<int>& vec)
{
for (int ...
4
votes
2answers
103 views
How can I memoize or otherwise optimize this code?
The code checks many more conditions like the one below. I was thinking to memoize it, but I can't think about how (writers block). How else could I optimize this? I know it seems silly, but my code ...
1
vote
1answer
77 views
Help me speed up this Java code. Deals with HUGE list of ints
Below is the code I have written. I started yesterday with prime numbers and playing around with them. What the code does it determines the "prime gap" between primes numbers, prints them, then finds ...
0
votes
1answer
29 views
JavaScript - Does this bookmarklet need some optimization?
I'm working on JavaScript bookmarklet that lets users send a text and link to a site.
This is the bookmarklet:
...
0
votes
1answer
19 views
autocomplete jquery -renderItem- option
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#grille" ).scrollTop( 0 );
}
$( "#my_ac" ).autocomplete({
source: ...
0
votes
1answer
63 views
I've finally found a satisfactory way to create classes on JavaScript. Are there any cons to it?
Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that ...
3
votes
1answer
223 views
Which is better: the short, clever way, or the long, ctrl+c way?
The code below is equivalent. I can see pros and cons for both versions. Which one is better?
Short version:
character.on("key",function(key){
var action = ({
...
1
vote
1answer
79 views
Playing Card Class - is this right?
The Art and Science of Java, a course book that uses the ACM library has an exercise that reads like this.
Implement a new class called Card that includes the following entries:
• Named ...
1
vote
1answer
37 views
Improve file-path finding method
I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: {'Tkinter.py': 'C:\Python27\Lib\lib-tk\Tkinter.py', ...}.
I am using this in a ...
1
vote
1answer
24 views
Improving my jQuery animation
I wrote the following fo create an animation which collapses a navigation bar, load new content for it and expands it again. Meanwhile, the rest of the page content fades out, loads and fades in ...
2
votes
3answers
94 views
Largest Palindrome efficiency
I have written an algorithm to find the largest palindrome under a given number, but I am sure my code loses efficiency by creating new arrays in every pass. I am currently learning about efficiency ...
1
vote
1answer
122 views
Which code is better? And why?
I found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods.
This ...
2
votes
1answer
39 views
Is there a more optimized way for this MySql Query
with below query i'm getting the results that i want but it's quite slow taking nearly 0.2 seconds (on an i5 machine). Is there a more optimized way to get the same results.
Basically this query ...
1
vote
1answer
72 views
Add checkbox with label to a form
For a WordPress login form I have written a small plugin. It adds a checkbox with a unique name to the form and if that name is not present in the login POST request it just dies.
The idea is ...