@Edward Which is exactly why we need more information about these requirements. A restriction on something like % almost certainly means that there's some compiler option being set somewhere.
And if the best answer to the problem is something that the compiler actually optimizes into num % 9 anyway, then we haven't actually met the requirement, and we've written code that's considerably worse than writing num % 9 because it's harder to read/understand for the developer despite the compiler treating it identically.
Code Review questions generally follow the form:
I have implemented code, which, given X input, will return Y output. How can it be improved?
To which simply the following is an acceptable answer:
You have written a lot of code, but did you know function F in the standard library alrea...
I wrote this in C#, but seeing as how we aren't using anything to fancy I think it should function the exact same way in C
I really didn't like the way that @Edenia wrote the code, mine is like her's, only I think it is much cleaner and straightforward
public static bool isDivisibleBy(int n...
@Malachi Sorry, but I have to downvote that one because C# on a C question with plenty of C answers...
Again, this would be best done on the answer itself. Either you are wrong and the answer will now benefit from an explanation of why that's not the case, or you are right and the answer will now benefit from an edit to fix its problem.
If there's a long explanation, then he'll probably ping you here for it.
I'm running a jQuery function to equalize heights. I want to equalize the heights of several pairs of elements, and can't think of a way to do so without repeating the whole function.
How can I combine the separate functions below into one function that equalizes the heights of each pair of <div>...
I am creating a game called Othello, the objective of the game is to close in your opponents stones either horizontal, vertically or diagonally.
All the stones that get closed in are then turned to your color.
Win the game by having the most stones of your color.
Small example:
b = black
w = whi...
I tried to develop a new way to check if a number is divisible by 9. I have written my code and it is working fine. I'm not allowed to use *,/ and %.
int isDivby9(int x)
{
int status = 0;
int divby8 = 0;
int orgx = x;
if(x>=9)
{
divby8 = x >> 3;
...
I also thought how I could improve my code further.
Readability
First Convert, this
#define xIndex (blockIdx.x * blockDim.x + threadIdx.x)
#define yIndex (blockIdx.y * blockDim.y + threadIdx.y)
unsigned long dataIndex = (xIndex + (yIndex * width)) * PIXEL_SIZE;
#define BLUE bitmapData[dat...
I wrote this so I can learn CUDA. This is coded to work on my laptop's Nvidia GeForce GT 540M.
Main points I need reviewed:
CUDA programming conventions
Performance, especially kernel speed
C programming conventions
Preprocessor and macro conventions
Making it DRY
kernel.cu
/*************...
I have "operating system" data, "valuable" data (things that are mine, can never be downloaded, etc. - photos, videos, code, emails, documents, etc.), "media" - ripped CD's, torrents, PVR (MythTV recordings, etc.), and finally "Backups".
Each of these things has dedicated space.
OS is on the SSD
Valuable is on a RAID5 array of three 3TB drives
"Media" is on a RAID0 array of 2 2TB drives
Backups is on a RAID1 array of 2 4TB drives.
in each case, the data is actually managed by what's called the LVM, the logical volume manager.
what that means is that the drives are really only 'virtual' space. I can add more drives, and use 1 command to 'move' the data on to the new drives, and have no downtime.
The filesystem is on the logical drive, not the physical drive
At the moment I have WD Black editions, 5yr warrantee.
I don't get it because of the warrantee, I get it because, in theory, they last longer
Those are just the new disks. I also have Seagates, and others.
disk reliability is a crapshoot anyway
2
With the LVM in place, if a disk dies, I buy some replacementrs, create a NEW RAID array for them (about 2 minutes of downtime to install the new disks....).
then, I build the RAID array, this takes 10 minutes to get going...
then I tell the LVM that the new RAID array is "space" it can use, and tell it to relocate the data from the old disks to the new disks.
that can take most of a day.
when it is complete, I tell it not to use the old disks any more.
then power-down, and remove the old drives.
Two things to note here.... 1. yes, one of the old disks is broken, 2. the data is still there... on the other disk....
So, in the event of a drive failure, I get an e-mail immediately (often before the disk breaks - thanks SMART).
I go out and buy more disks, do the process, done....
about 5 minutes of system downtime, and no additional interruptions.
The following JS code object displays the date and time and updates whenever it changes.
I'd like to have a full review on any aspects of my code.
Any suggestions for improvement are always welcome!
LiveDateTime.js
'use strict';
function LiveDateTime(startTime, dateElement, timeElement, opti...
So, for example, occasionally I change files in /etc/ and I need to go back to an old setting, well, I can.
Backups schedulked are:
panabox:/snapshotng# ls
cp.sh etc fawcet gallery22 gallery_cache home local lost+found mysql netshare opt pana pictures root slapd versioncontrol webdav www
In order to learn both scala and functional programming, I've been rewriting the projects from my introductory CS class in scala. One of the projects was a plinko game, where the user picks a slot to drop a token into and then the path that the token took and the money won from the end slot is pr...
My internet also drives my VoIP "land line", and (in Canadian dollars), I am paying $81 (taxes included) a month, for: 25/10MBit ADSL, static IP, phone service (including world-wide no-cost)
substantial cap on that (400GB per month).
(and bandwidth used between 01h00 and 08h00 is not counted)
Add $8 per month for netflix, $25 per year for a "listings service" I use for MythTV (get program details and schedules), and $30 for the domain name.....
> Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems.
> Technology has allowed Dutch people to get even further ahead in war-on-weather. Its no surprise that one of the most popular iPhone apps is actually Buienradar –a weather tracking system, showing you nice little rain clouds above the outline of the Netherlands, predicting the exact time it will rain and for how long. Now yes, I will admit, that the Buienradar app may have somehow made it onto my iPhone, and may have somehow been frequently checked….but I digress.
I have some glibc error like ;* glibc detected * double free or corruption (out): 0x00000000005099d0 ***
In my code, when I compiled it with n = 10, it works well, but not with other numbers like 9,11 29..
Since I am in a beginner level for coding, I have not been able to make progress more. C...
And it works, but I have this error. <-- that is an indication that it does not work to the level required to be on-scope on Code Review. You need your code to be working correctly before it is on topic here. — rolfl ♦29 secs ago
I had been trying to find a suitable solution to implement localization in my Phonegap/Cordova application. My search proved that any localization through seperate .xml or .json files was a nightmare (mostly due to cross-access-origin).
Because of this, I decided to create a (very) simple, light...
why doesnt my code work :( i am using python 3.0 and my intention is if someone types in the word it will print something and if they type the wrong "word" it will deny access to them but if they type the right thing they will gain access
hacker = ("we have reported you now , good bye")
tim = ...
Well, this is bad. When a control gets to this code then odds are indeed not good that it won't bomb, especially so when exiting. It is not getting cleaned-up the normal way, getting disposed when the host form closes. In other words, you have a "leak". Could be that you are removing it with Controls.Remove/At() or Clear() and forgetting to dispose it. Could be another bug in your program causing it to bomb, then triggering this one. You need a code review and a talk with the user. — Hans Passant56 secs ago
@SimonAndréForsberg The additional dependency is not ideal, but, if the math is needed, then it's probably worth pulling it in, and then ddeciding later.
The code has the same license, so, with attribution, if it's just a bit, we can just copy/paste it.
The Gauss–Newton algorithm is a method used to solve non-linear least squares problems. It is a modification of Newton's method for finding a minimum of a function. Unlike Newton's method, the Gauss–Newton algorithm can only be used to minimize a sum of squared function values, but it has the advantage that second derivatives, which can be challenging to compute, are not required.
Non-linear least squares problems arise for instance in non-linear regression, where parameters in a model are sought such that the model is in good agreement with available observations.
The method is named after the...
^^ that is the algorithm I plan on using
I implemented something like this in Matlab about 4 years ago. But that was in Matlab. And four years ago.
Well, this is bad. When a control gets to this code then odds are indeed not good that it won't bomb, especially so when exiting. It is not getting cleaned-up the normal way, getting disposed when the host form closes. In other words, you have a "leak". Could be that you are removing it with Controls.Remove/At() or Clear() and forgetting to dispose it. Could be another bug in your program causing it to bomb, then triggering this one. You need a code review, a memory profiler and a talk with the user. — Hans Passant27 secs ago
@rolfl many people seem to have problems knowing what the complexity of their code is. I figured that by providing a void doSomethingToFindComplexity(int n) method, and in that method create an input and sort it using some algorithm or whatever, it would be possible to estimate the actual complexity of the code.
The Gauss–Newton algorithm is a method used to solve non-linear least squares problems. It is a modification of Newton's method for finding a minimum of a function. Unlike Newton's method, the Gauss–Newton algorithm can only be used to minimize a sum of squared function values, but it has the advantage that second derivatives, which can be challenging to compute, are not required.
Non-linear least squares problems arise for instance in non-linear regression, where parameters in a model are sought such that the model is in good agreement with available observations.
The method is named after the...
Hello fellow Meteor developers. I am hoping a Meteor guru can please review my code below and verify if I am making proper use of return false and event.preventDefault(), especially in the context of form submission. The reason being, the Meteor docs use this approach:
// Prevent default form s...
@skiwi - the assumptions are: 1. the user wants to get "some idea" of the scalability (not the complexity), by varying a single input. 2. it does not need to be accurate, just "useful".
and 3.. it's OK to be wrong, or to say "I don't know".
Frankly, a graphical plot of: "this is how your function scales relative to variable X, and this is how other common functions scale...." would be really useful
....
so, given, for example, the function that produces random data in an array:
private static final int[] randomData(int size) {
Random rand = new Random(size);
return IntStream.generate(rand::nextInt).limit(size).toArray();
}
We can sort the data with:
Arrays.sort(data);
what is the plot/complexity of the arrays.sort data relative to different input array sizes...?
I'm doing K & R C Exercises. I could use a code review to see how I can improve my logic.
"Write a program that prints its input one word per line with getchar."
My basic idea is we need to know whether or not we're in a word. We use the IN status. Every time we hit a blank space, tab, or...
If you already have working code and would like to others to offer their opinions and/or suggestions, you will be better of moving it to the Code Review site. — PM 77-122 secs ago
thanks .. for some reason didn't Code Review — ANM1 min ago
I'm voting to close this question as off-topic because OP is asking for a code review/suggestions to improve — Yatrix1 min ago
As I'm new to HTML + CSS + JS I've been building a calendar (which I think anyone can use as a basis) but would like to get your suggestions on how I could improve my code specifically from the perspectives of:
Adherence to best practices in HTML + CSS + JS.
Usability.
Browser compatibility.
...