I have implemented the heap sort algorithm which passes my tests. Although, I would like to ask you if I can improve anything from readability to performance.
Here is my code in Java:
import java.util.List;
/**
* Created by Orestis on 17/07/2015
*/
public class HeapSort {
public static <...
@Quill: It looks like your wiki excerpt for covariance was misleading (and I was about to synonymize it with statistics). I corrected it based on SO's tag wiki.
I want to write a function which returns true if a selected date is smaller than the current date, else return false.
This function is working as expected but I want to know the best possible way to do this.
private boolean isValidDate() {
if(year<yearCurr)
{
//selected year i...
So this is my first time iterating over a json file and appending the values to a HTML element. I'm still learning and want to know if there is a better way to write this piece of javascript code, specifically the appending part. I tried doing it with Javascript using appendChild, but couldnt fig...
There have been a few questions with images from external sources.
The most recent I can remember is the following question:
Iterate JSON GIF collection array to HTML file
It contains the following link:
http://buffalogrove.sat.iit.edu/thumb/turkey_karadeniz_region-t2.jpg
It belongs to the Ill...
There have been a few questions with images from external sources.
The most recent I can remember is the following question:
Iterate JSON GIF collection array to HTML file
It contains the following link:
http://buffalogrove.sat.iit.edu/thumb/turkey_karadeniz_region-t2.jpg
It belongs to the Ill...
@Jamal I'm not familiar with ATL at all, so I don't have an expert opinion. In the absence of any compelling reason, I'd leave it. @Mat'sMug may have input.
I want to create a console program that simulates a raffle draw. It should be able to do the following:
Enter the number of students
Allow the user to input the student's names (only after asking the number of students)
Display the names of the students
Display all winners
Reset the winner list...
Problem Statement
Input
The input begins with the number t of test cases in a single line
(t<=10). In each of the next t lines there are two numbers m and n (1
<= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime numbers p s...
I asked this question on stackoverflow.com but was suggested to ask the question here.So here it goes.
For a program for constructing a symbol table where a key is a word and value is the frequency of the word in a text file and finding the word with maximum frequency, I did it in two ways:
Fir...
I'm using iojs. I have to read some, file streams, process them with a common function.. and join them back into a stream. I decided to create my own solution with Transform streams and PassThrough streams,
This is what I came up with,
"use strict";
let fs=require('fs');
let filePaths=[...
Challenge:
Write a program that will clean up the words from extra numbers and symbols.
Specifications:
The first argument is a path to a file.
Each line includes a test case with a list of words: letters are both lowercase and uppercase, and are mixed with extra symbols.
Print the...
this is the source and i'm interested in finding out if the left menu that activate the product rollover images it's generated by a js / jquery plugin or we have pure css custom made code.
I've found in console a div class called boxy but not a js / jquery related in js source files folder. Coul...
Alice and Bob are playing a game called "Stone Game". Stone game is a two-player game. Let N be the total number of stones. In each turn, a player can remove 1, 2 or 3 stones. The player who picks the last stone, loses. They follow the "Ladies First" norm. Hence Alice is always the one to make th...
I'm new to java and I need help completing the question below. If anyone could help me with a simpler solution of this question. I tried to provide a working solution but I got stuck at number #10.
Create a new file called Rebel.java;
Create two arrays. One of them must store integer numbers an...
@jacwah On a meta post somewhere, there's a chrome extension that has a bunch (10ish) placeholders comments. It's much easier than writing it out, or copy-pasting it from a document
Title says it all, i'm trying to create a modern template class for a generic observable, here's my attempt so far:
typedef int SUBSCRIPTION_ID;
template<typename EventType, typename Event>
class Subject2
{
typedef struct
{
std::function<void(const Event&)> m...
On Code Review we often encounter questions with the same kind of problem over and over again.
Some of us are using the auto comments script which allows you to maintain a list of comments to post.
What are some useful tin-can comments that can be good to have in your list of comments?
If you ...
@Mast good question. I am way too inexperienced in the distributed computing area.
I know that when I went to Ukraine in April and @Duga went down, @rolfl set it up as "StackMonkey". It would be nice to have something trigger automatically though
If Duga's script can be queried, other tasks could 'check' if she's still alive.
If you have a couple of layers asking the layer above whether it's still alive, it should be sufficient.
Yours would be primary, two more would solve most.
@SimonAndréForsberg Everyone with a small server with continuous uptime could run it, right? Of-course there are security concerns, but it can be done.
@Mast I am using a Java/Groovy webserver and a database. But beyond that, yes, anyone could run it.
at least my script to detect Minesweeper Flags multiplayer downtime is working...
Now that I have internet again, I can reply to some things here.
@Mast @200_success @jacwah when I reached for Marshal back in December, I did that by using SEDE to look for obsolete comments (I think @rolfl knows this very well also). It would be very strange for me to tell people to not flag obsolete comments now. That said, I do appreciate "easy" comment flags such as "thanks, edited" as they are very easy to decide on. If you have to think for 10 seconds whether or not it is obsolete, a mod is likely to think for maybe 15-20 seconds.
@RubberDuck keep the secret stuff in a file that is gitignored. That's how I do it. I am personally not a big fan of using environment variables for that.
@IsmaelMiguel @janos Questions that have low view count, and < 0 score and no answers automatically get deleted on sites after a while.
@jacwah funnily enough, in Delphi/Pascal, that is actually called a word.
@RubberDuck Everything is risky if you're not aware of what you actually commit. I've used gitignore for that for a long while and I do perfectly alright.
@SimonAndréForsberg it's not me I worry about. It's Visual Studio I worry about. The integration is still fairly young and .gitignore gets flaky sometimes from inside VS.
I read the documentation part of Eloquent, especially scopes. It describes
Scopes allow you to easily re-use query logic in your models. To define a scope, simply prefix a model method with scope:
And so, with using Slim, I'm retrieving an object of Employee Type and pass it to my view. I only ...
Given two numbers L and R, find the highest occurring digit in the
prime numbers present between L and R (both inclusive). If multiple
digits have the same highest frequency print the largest of them. If
there are no prime no.s between L and R, print -1.
My Code.
package com;
import ...
Sometimes, I think that, with Duga's assistance, Stack Overflow could handle a direct migration path to Code Review. There are still bad recommendations, but I'm certain that's the case with the other direct migration paths as well.
But ultimately, migration has to work in some other way. It can't stay under the close dialog.
Input given is:
Each test case contains two lines. The first line contains a single integer N (1 ≤ N ≤ 105), the number of persons playing the game. The second line contains N integers i(height) (1 ≤ hi ≤ 109) the height of the i-th person. They are numbered 1 to N starting from Druid.
Output g...
On the list would be: - Thou shalt use braces. - Thou shalt not compare floating-point numbers with ==. - Thou shalt never tell another programmer simply "but it does not work".
Honor conventions is a good one. Including context I think gets wrapped into "but it does not work". And while I consider fixing ugly code to be important, in the real world it's not something you necessarily always have time for
Like I'm counting "include all context" as part of not saying just "does not work"
I kind of want to include something about comparing object with == versus the equals method... but that's not universal enough. Not all languages are OOP, and for some, == isn't the reference comparison
- Thou shalt use the right tool for the right job.
Hmm. Being clever is sometimes good though. It's important to not go out of your way to be clever, and yeah, it can be wrapped into premature optimization
Specification:
Given a string (eg, the content of an article),
print the estimated reading time
by bucketizing time into increasingly large chunks
in the form "5-10 min" or "48 min-2 hr", eg.
Notes:
Distribution of time into buckets is arbitrary, to make it "look nice" for the defau...
I have taken part to a coding challenge. They ask for the shorted possible solution (speaking about the number of chars in our code). I submitted the code with 129 chars, but the winner had 50 chars. Below is my C++ function:
int Rocks(int n) {
int c = 0, i, m = n, d = 0;
while (m) {
d++...
I have a simple algorithm that I'm using for code golf, and I'm hoping to find ways to golf it further. The algorithm is somewhat golfed in Python already, and works flawlessly. I asked on meta.codegolf.SE if a question about it would be on topic there, and per the discussion, the community think...
1. The source of the question is from a code-golfing contest. The only way the code's source has a bearing in the question being on/off topic is if the question asker isn't the owner/maintainer isn't the author.
2. The question being asked isn't how to golf the question, but rather how to reduce the size of the source code, which is actually a perfectly valid question here.
Moreover, any reasonable review of that code (one I was about to start writing) would have criticized the cryptic unreadability of the code. It would have never earned the check mark, because the recommendation would've resulted in MORE characters, not less. But it would've earned more upvotes than anything the OP would've been willing to give the checkmark.
@jacwah Code-golfing is a game to use the least amount of characters in order to win some sort of contest.
There are real reasons, outside of the game of code-golfing, for reducing the size of your source code.
I am writing a patch for Busybox's implementation of vi, the classical command line code editor and predecessor of vim. It can open up a files through filenames given as command line arguments. My patch allows initial text to be loaded in to the buffer through a pipe on standard input too.
# nor...
@nhgrif I think that there's a difference. In jacwah's question, he still asks for readability, while on the other question, readability is thrown from a cliff.
This question earned the downvotes it did because the OP's desire seemed too closely related to code golfing, but didn't really deserve close votes because it's not really explicitly asking for help golfing the code.
Started learning and implemented Trie datastructure.
I have implemented Trie datastructure in my way though it is very similar to what major implementations I found but would like to get it reviewed by experts.
I don't see the need to store character in TrieContainer class as position within th...
@IsmaelMiguel There's nothing wrong with this other than short variable names. I've written loops exactly like this... just didn't have 1-letter variable names.
He's not asking. And unless you downvoted, you can only make an assumption as to why any downvotes exist at all (which is no better than he can do). And even if you did downvote, you could only explain your own downvote. You're still making assumptions about the other downvotes.
So all you'd be doing is offering him unsolicited speculation.
Can we do a function inside another function ?
function getReportTitle() {
var segmentArray = window.location.pathname.split('/');
var segment_4 = segmentArray[4];
var segment4Array = segment_4.split('-');
function ucFirst(str) {
...
@nhgrif There is a question among our six magical questions about "Do I want the code to be good code?" the question you've been talking about would answer this question with a "No", which makes it off-topic. Code-golfing is not on-topic here, that question was about a code-golf challenge.
@SimonAndréForsberg I agree in most part, but he could want to reduce the number of instructions. We would beat him for having unreadable code, but the number of instructions could be reduced. He then could reduce the variable names again.
The source code either works or doesn't work. The rest boils down to what the user is asking. We have decided as a community that while asking for code-golfing is off-topic, asking for shortening code isn't inherently off-topic.