@Mast Ugh need to do an average of 3 runs to get it semi-accurate
OP: 97046.9630755 ms
Improved: 102422.017227 ms
I mproved 2: 59848.1377405 ms
Improved 3: 17276.0329956 ms
My code: 0.743039272248 ms
Built in libary: 0.262319591133 ms
My requirement is this :
I have Producer Threads A, B and C producing 3 different types of events Event A, B and C respectively. The Consumer thread can only process only one Event B at a time, where as it can process any number of Events A & C at a point of time.
Below is my take on the implem...
import time
def get_biggest_palindrome():
biggest_palindrome = 0
for i in xrange(100, 10000):
for j in xrange(100, 10000):
product = i * j
product_string = str(product)
if product_string == product_string[::-1]:
if product >= biggest_palindrome:
biggest_palindrome = product
return biggest_palindrome
def main():
print get_biggest_palindrome()
if __name__ == "__main__":
start_time = time.time()
main()
This solves Project Euler 4: Largest palindrome product using C# (specifically, using LINQPad). Any and all suggestions for improvements to either the C# code or the math/algorithm are very welcome.
A palindromic number reads the same both ways. The largest palindrome
made from the product...
0. Overview
Your code is well written and it is clear what it does. However I will argue that if you want a drastic increase in performance you need to switch your algorithm. Testing primality can be done in polynomial time, but is generally a problem which requires sophisticated maths. One of t...
def sum_square_difference(n):
'''The sum of the first natural numbers are
S[1](n) = 1 + 2 + 3 ... n = n*(n+1)/2
The sum of the first square numbers are
S[2](n) = 1^2 + 2^3 + ... n^2 = n*(n+1)*(2*n+1)/6
By computing the difference of these two numbers one gets
S[1](n)^2 - S[2](n) = n*(n-1)*(3*n+2)*(n+1)/12'''
return n*(n-1)*(3*n+2)*(n+1)/12
Looking through your Python PE solutions, my approach is to try and come up with a general solution, rather than one specific to the metrics of that challenge
Welcome to Stack Overflow. Please take the time to familiarize yourself with the Stack Overflow help file, which will help you understand what kinds of questions are appropriate for this site. This site is intended to help you obtain answers to specific programming questions, as opposed to providing tutorial, design or code review assistance. — MarsAtomic54 secs ago
This is x86 version of a C file assignment(I have included both). We were to convert the C code to assembly, I am rather new at assembly and would really appreciate suggestions and help for optimization and functionality.
This is a C implementation of Dijkstra's recursive algorithm for computin...
I'm learning Swift and trying get a good understanding of some of its many features. The following is an AVL tree implementation with extensions that conform to SequenceType, CollectionType and ArrayLiteralConvertible
Everything seems to work correctly. I wish to get some feedback on my overall ...
Input a binary tree (the root node) and 2 other nodes that need to be assessed for finding the least common ancestor (LCA)
Code:
a. Finding the nodes first with either breadthFirstSearch or depthFirstSearch
b. If they both exist, find the LCA.
What searching mechanism would be best here? Using ...
import praw
import time
import database
# Create a user agent and log into Reddit
UA = 'OZBOZZ v0.1'
r = praw.Reddit(UA)
# Log UA into reddit with my personal user name and password
r.login('', '', disable_warning='True')
subreddit = r.get_subreddit('listentothis')
current_time = int(time.time(...
1> Input: Array of sorted integers and an element to check the frequency for.
2> Output: Frequency of the element
public class FrequencyElement {
public static void main(String args[]){
//System.out.println("Enter Input string");
int input_array []= {2,3,4,25,99,99,19000};
int eleme...
I am using below code and for result i am using interface for call back purposes.
@Override
public void onResult(String result) {
if (this.mClient != null) {
this.mClient.cancel();
mProcessing = false;
}
try {
JSONObject j = new JSONObject(result);
J...
Good morning,
I'm working on a report of quality control. I have a list L, which contains the names of files that I should open and import the data into EXCEL, then fill my quality control table by these data.
And at the end, I want to know which file in the list has not been opened, that means...
I'm voting to close this question as off-topic because the question is asking for a code review. Have a look at codereview.stackexchange.com instead, but be sure to read their help center on how to ask a good question first thing. — Erwin Bolwidt41 secs ago
> [6/29/16, 03:02:26] @Phrancis: What's the criteria? [6/29/16, 03:02:31] @EBrown: Vanilla, any map. [6/29/16, 03:02:43] Phrancis: I mean, how do we win? [6/29/16, 03:02:47] EBrown: No idea. [6/29/16, 03:02:52] Phrancis: LOL
Hi there. If the code works but you think it could be improved, try codereview. If you have a question concerning excel or excel-vba, post it as a new question with the correct tag. — arcadeprecinct52 secs ago
I can't wrap my head around that. There seem to be a lot of redundancy, and even if it is not called called more than ten times in the main loop, I still find it hard to swallow that it loops through the whole list at each invocation.
def get_file_info(f, stream, field):
discoverer = GstPbu...
My question is about this sort of table that's simplified here. Often, I find myself putting this element, (int (*)(const void *, const void *))&strcmp for bsearch. I go between prototyping with void pointers, creating dummy functions, and casting, but none is really a satisfactory, especially wh...
OK so a lot of code review is fairly routine. But occasionally there are changes that broadly impact existing complex, fragile code. In this situation, the amount of time it would take to verify the safety of the changes, absence of regression, etc. is excessive. Perhaps even exceeding the time i...
I proposed an edit to this answer to one of my questions.
The edit consisted of replacing two single quotes with two double quotes.The sample code in the original answer failed to compile; the edited version compiled and ran as advertised.
The 6-character-minimum-edit rule forced me to add irre...
I proposed an edit to this answer to one of my questions.
The edit consisted of replacing two single quotes with two double quotes. The sample code in the original answer failed to compile; the edited version compiled and ran as advertised. (Sorry, it's not obvious to me how to find the edit aga...
Question: I'm fluent in Matlab, but have some basic knowledge in other languages. Is it OK to review code in languages where I have limited experience, or is this frowned upon? The reason I'm asking is because it _might_ be that there are better ways to do it than what I propose. See for instance [this one](http://codereview.stackexchange.com/q/133360/109032).
@StewieGriffin Many programming skills/concepts are universal (see: naming). If you think your answer can improve, in any way, on the OP's code, go for it.
CR answers don't have to be the best, just better than what the OP currently has.
@Zak Problems can arise once I/others suggest things that are against common practice. For instance, if someone started to advise people to use eval in Matlab I would call that a bad review (in 99% of the cases), even if it solves a problem seemingly more elegantly than what OP had. (I just proposed using eval in Python).
But I haven't found any sources that advise against it, yet... =)
@Zak and I started answering Matlab questions on SO before I was any good at it :)
Problem from Hacker Earth:
Inverted GCD:
Given an array a of N numbers , you have to find the number of pair of indices i and j that satisfy the following relation:
i < j
ai > aj
gcd( ai , aj )=1
Input:
The first line of the input contains a single integer N - d...
The scenario which I'm trying to implement.
This class tests the Worker class. It invokes the run() method of a Worker instance. The Worker class holds an instance of a queue of Order objects. The max size of this queue is 5. Ten Orders are generated Asynchronously and placed in the queue. Those...
After reading a bit about CSS3-text-shadows and seeing a few advanced examples I had the idea for a "neon light"-banner. Next idea was to animate it.
Finally it has become a mixture between a Sass-mixins and a bit of JavaScript.
One more thing I should mention:
It's a fun-thing. I'm not intend...
I don't know, we're majorly behind release schedules and the product is a pretty shitty angular app. The startup is a inhouse project of another (established) company with an even worse codebase.
I posted the same question on StackOverflow thread
but I think here is the correct place to ask (if is not right, admin please to remove it).Every day I need to format date imported from AS400 (data, time,..).
Usualy (for some thousands of record) I use this code.
Public Sub Cfn_FormatDate(contr...
I posted the same question on StackOverflow thread
but I think here is the correct place to ask (if is not right, admin please to remove it).Every day I need to format date imported from AS400 (data, time,..).
Usualy (for some thousands of record) I use this code.
Public Sub Cfn_FormatDate(contr...
The generic arrays in C I found on the net used either of these methods:
the preprocesser with #define and #include (a lot of repitition and different names, but type-safe)
void *-pointers (no type safety)
void *-pointers and callbacks that fetch specific datatypes from the pointers (troublesom...
I have a simple code that reads from input files and stores the data in a struct.
I use global variables to store input data (I know it is bad practice but suppose that I must do it in this way).
I have 42 input files and read them using a loop. When I do so, the program crashes. However, if I ...
I have a table of groups, and a table of members. Each member belongs to one group. This is how it looks (more groups then 2 are possible):
groups
id | name | year |
------------------
1 | Nice | 1966 |
2 | Hard | 2012 |
member
id | name | idGroup |
----------------------
1 | Bernd | 1 ...
OK so a lot of code review is fairly routine. But occasionally there are changes that broadly impact existing complex, fragile code. In this situation, the amount of time it would take to verify the safety of the changes, absence of regression, etc. is excessive. Perhaps even exceeding the time i...