instruction stringlengths 71 95.1k |
|---|
Given this sample input:
ID Sample1 Sample2 Sample3
One 10 0 5
Two 3 6 8
Three 3 4 7
I needed to produce this output using GNU AWK (awk in Linux, gawk in BSD):
ID Sample1 Sample2 Sample3
One 62.50 0.00 25.00
Two 18.7... |
Inspired by Extensible and testable FizzBuzz I have decided to write my own implementation, partially based on my own answer and on the other answers.
First a warning to all of you: Never make such complicated code for such simple jobs!
Now the basic requirements of the code:
Should be capable of solving the FizzBuzz ... |
The user enters coefficients into input boxes on a form, called GetFunction. Upon clicking an OK button on said form, the input is validated using TryStrToFloat. If all the input boxes are valid,CreateGraphis called. As soon as an invalid input box is found,CreateGraph` should not be called and the user should be able ... |
I have written the following meta-tags for SEO, please let me know if you think this could use any improvement. I have used this article to help me put it together. I have left out the page content on purpose, if you wish to see it I posted it here on CR and on Github (note the following updates have not been committed... |
I recently wrote this code as a more versatile stand-in for Convert.ChangeType. I very recently posted an earlier version, for which I received some good feedback. I've incorporated that feedback and further refactored in an attempt to streamline the flow of the method.
/// <summary>
/// Returns an object o... |
I just finished Project Euler #7 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
import Founda... |
Most of the Rx Compelling Examples™ load and store data locally, which I don't find that Compelling.
I spent some time coming up with how to best perform the following actions but want to make sure I am not Doing It Wrong™.
Here are the cases I am trying to solve:
Load data from cache and remote server when view model... |
I had a school project to solve, which I did. The basic focus of the project was to create the simplest code possible to solve it. This topic was created just to ensure if I wrote the code correctly.
The problem is the following:
We have declared a dynamic array which will take numeric values from a txt file. We
wan... |
It takes around 5-8 seconds for me to retrieve a previously-closed stock price and a dividend rate from US Yahoo! Finance. If I wanted to retrieve 10+ stock prices, it would take me more than a minute with the below VBA code.
Is there any other way to speed up or improve the code?
I input multiple stock code on column ... |
I started learning Python a couple of weeks ago, and to test my new knowledge of Python, I decided to use Pygame to code a random walk terrain generator.
# Basic random walker program
import random
import pygame
import sys
# Screen width and height
WIDTH = 900
HEIGHT = 900
# Initalize pygame
pygame.init()
screen = ... |
I have worked for a few hours and this is the result:
$(document).ready(function(){
var canvas = $("#snow-collision")[0];
var stats = new Stats();
stats.setMode(1); // 0: fps, 1: ms
var debug = $("#debug");
var pi = Math.PI;
var hpi = pi / 2;
var tpi = hpi * 3;
// align top-left
stats.domElement.st... |
This is my prime number checker in C++. I know that calculating the square root of a number can be very costly, so I don't do it unless the number is larger than 10k, where we would have to check 2450 extra values \$5k-\sqrt{10k}\over2\$.
void primeChecker(std::vector<int> &primes, int val)
{
int max = val > 10000... |
I've just done Project Euler question 10:
Find the sum of all the primes below two million.
I get the correct answer and it takes about 3.5-4 seconds to run.
I tried to use the Sieve of Eratosthenes to find the solution, but am not sure if my solution is using the method correctly, or if it could be improved in any w... |
Project Euler #3 asks:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
I've written a general solution for any number:
module Main where
isDiv :: Integer -> Integer -> Bool
n `isDiv` k = n `mod` k == 0
fullyDiv :: Integer -> Integer -> Integer
fullyDiv n... |
Project Euler #4 asks:
Find the largest palindrome made from the product of two 3-digit numbers.
The code is as follows:
module Main where
import Data.List (sortBy)
import Data.Ord (comparing)
palindromes :: [Integer]
palindromes = [calcPalindrome a b c | a <- [1..9], b <- [0..9], c <- [0..9]]
where
cal... |
Please take a look at the following Scala program and give me suggestions for improvement. I'm sure there would be plenty. This is my very first Scala code, so please don't be frustrated because of its low quality.
abstract class Expression {
def eval() : List[List[String]] = this match {
case Identifier(token) ... |
If a checkbox is clicked, it will be added to the total, if not, it will be deducted or ignored. (The total number of checkboxes I have in real is 25.)
Is there a way to write the code below in a shorter version?
Function
function tblcheckboxes(){
var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v... |
Data
I have 4 Collection objects of the following kind:
dates1=(12/01/02, 15/01/03, 17/01/03, 25/04/04...)
dates2=(15/02/02, 17/06/07, 10/05/10, ...)
numbers1 = (3,5,2,7,...)
numbers2 = (1,-3,-1,...)
The rules of the game are:
dates1 will always have the same length of numbers1, dates2 will always have the same lengt... |
I feel like I'm repeating a ton of code here and there's got to be a better way to do this but am just completely spacing right now. I basically have an else if clause that, if their conditions are met, repeat the same code, but I'm also repeating the same code in the else statement along with a few other conditions.
W... |
I wrote a simple Fibonacci checker using HTML, CSS, and JS. This is my first JS program, so be sure to tell me everything that is wrong with it. Check it out here (http://jsfiddle.net/z49fyypt/1/), and here is the runnable code snippet:
<!DOCTYPE html>
<head>
<title>Fibonacci checker</title>
<style>
... |
When you start thinking about designing a Match 3 type game, you realize that there are a great many ways to structure the rules. In this particular variant, the direction that the player swipes the orbs determines the way that the board is refilled. The new pieces will enter the board opposite the direction that the... |
I had some time to kill today, and I found the Karate Chop Kata.
Specification:
Write a binary chop method that takes an integer search target and a sorted array of integers. It should return the
integer index of the target in the array, or -1 if the target is not
in the array.
I've never implemented a binary s... |
I was given this project and have changed a lot of code on it, now I am going over the code to make sure that I know what everything does and can maintain it efficiently, and to make sure I want my name on it.
Here is the method they have been using to validate e-mail addresses from a textbox input.
private string Vali... |
Before @bazola asked his recent question, we chatted about it for a bit. I figured that I could try implementing something similar myself.
As I've heard that Scala has all the advantages of Java, but fewer of the disadvantages, I'd figured that I could try it.
I have implemented checking for board matches, removing the... |
I was recently working on a project, something jQuery-related for WP-Admin area.
I enable post-formats and create metaboxes for these post-formats, so at the end I tried to hide these metaboxes until the user checks the radio button. I just want to know if there is a better way I can write this code.
// hide the metabo... |
I have written a functional GUI program using PyQt4, and I'm looking for some feedback because it's not as fast as I would like. It takes in some number of large, same-sized 2D arrays and displays a sub-image of each one in its own sub-window - at full resolution or only zoomed by a factor of 2 or 4. The central GUI ... |
I have a requirement to be able to filter a list of strings by both inclusion and exclusion patterns (using fnmatch-style wildcards), of which there can be many.
For example, given the set of values:
['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
And these inclusion filters:
['a*', 'b*']
It should return:
['a... |
I made this Sudoku solver using depth first search, it takes less than 0.1 second to solve any simple solution(no guessing), but if the solution requires guessing (thus using the DFS) its time grows exponentially.
One puzzle ('hard') makes 10 consecutive branches in the search, thus allowing 210 (I guess) possible outc... |
I have a JSON response from the Facebook API, which contains the app requests of certain Facebook apps via FB.API('/me/apprequests') (using Graph API 2.0, Facebook SDK for Unity 6.0).
There are 3 things I want to collect from the requests:
The response data (a JSON string)
A texture (in Texture2D class)
Status of load... |
This code gets all of a user's Facebook friends who use our app and returns a dictionary with keys that are their id's in our database and values that are a default connection level.
The code should also return all of the users Facebook friends who aren't using our app.
I made fb_id_on_app a dictionary of keys that are... |
Is this a smart method?
public static ArrayList<Integer> getWordLengths( String s )
{
String str = " " + s + " ";
ArrayList<Integer> list = new ArrayList<Integer>();
for ( int i = 0; i < str.length(); i++ )
{
if ( str.charAt(i) == ' ' )
{
for ( int j = i+1; j < str.length(... |
This code works as it is supposed to:
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
char cAgain, type;
int x, y=0;
double addition(double num1, double num2), subtraction(double num1, double num2), division(double num1, double num2),
multiplication(double n... |
I was hoping for someone to review my current project, which was created in Swift and uses a PHP web service. I'm not worried about UI elements, as this is just a 'test' project, but I'm concerned about two things: using the best practices and security. I'm concerned that the SQL query is not safe, among other things.
... |
I'm trying to learn how to build a good test suite, using simple sorting as an example.
Particularly, I am using Nose to generate all the tests based on a simple list of lists, where each sublist is a unit-test for each sorting method, as seen below:
from nose.tools import assert_equal
def check_sort(s, arr):
asse... |
I was hoping people could help me review the following page that I've been working on. The page has a simple form that looks at a list of colours and draw a few divs with those colours as backgrounds (so I could see what the colours look like). I'm hoping to build a few complex interactions on this page, but I feel thi... |
I have a very long switch statement which is expected to have nearly 50-55 cases.
switch (commandType) {
case COMMAND_LOGIN:
command = getCommand(commandType, agentId);
break;
case COMMAND_MAKE_READY:
command = getCommand(commandType, agentId);
... |
I have code which styles standard Android widgets programmatically (not from XML). The code is working, but I have this bunch of if instanceof else if instanceof block which is ugly.
I have read discussions on Stack Overflow, and my conclusion is instanceofis better on my case, but I'm not so sure, maybe I'm missing so... |
Perfect numbers are strictly positive whole numbers of which the sum of their positive divisors equals a multiple of the number itself. An example of a 3-perfect number is 120. The sum of all divisors of 120, namely 1+2+3+4+5+6+8+10+12+15+20+24+30+40+60+120 = 360 equals three times 120.
My code does work, but it's not ... |
I have created a batch script to start the services in a gap of 10 min. My batch file will start the service on the local system and then will wait for 10 mins and starts the service on another system and then another. I have used the timeout command with nobreak statement which does not allows the user to stop the wai... |
I've been trying to learn async coding recently. I've managed to get it to work and the UI thread doesn't block like it does if I don't make the code async. I realise this is a very contrived example, but is this how async should be done?
public partial class MainWindow : Window
{
public MainWindow()
{
Initia... |
I've seen a number of questions on Stack Overflow of the kind of "How do I sort on fields X AND Y?" The most common answers to those questions consists of "Write a custom Comparator."
But what if you have 3 fields you can sort on? Or 13? or 300? My solution is this utility class, so that rather than writing a billion d... |
I have a segment of code:
/*functions return 4 if all digits are the same, 5 if digits are decreasing, 6 if digits are increasing, 7 if number's digits are bouncy.*/
int variable = 0;
cout << number << endl;
variable = sameDigitsTest(number);
if (variable == 0)
variable = dec... |
Please review my pointer class.
template<typename T>
class Ptr {
public:
Ptr(T* t, int s = 1) {
sz = s;
p = new T[sz];
for (int i = 0; i < sz; ++i) {
p[i] = t[i];
}
}
Ptr(const Ptr&) = delete;
Ptr& operator=(const Ptr&) = delete;
Ptr(Ptr &&t) :p{t.p}, sz... |
I just finished Project Euler #8 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.
The four adjacent digits in the 1000-digit number that have the
greatest product are 9 × 9 × 8 × 9 = 5832.
7316717653133062491922511967442657474235534... |
Here is the class I'm using:
<?php
/**
* Pastr 1.0
* @author Lloyd
* Pastr is a quick and easy tool you can use to upload snippets of text and code
* <pastr.co>
*/
class Pastr
{
/**
* Our database information is stored here
* Array
*/
public $dbInfo = array();
/**
* Our array which ... |
I was inspired by this SO post to investigate
a good Java8 way to calculate Pi based on simulation.
I used a similar task to learn about parallel programming on both CUDA,
and Intel Xeon Phi processors. Those systems are more geared for
parallel programming, but I felt inclined to apply it to 'regular' Java
anyway.... |
The Rubberduck Saga continues as I find a need to roll my own configuration. Since the program is really a *.dll and available to several host applications, using app.config is not an option. I decided to leverage XML serialization to allow a user to modify which comments get picked up in the Task List.
I feel like eve... |
In Winter Bash 2014,
since there is no easy way to see the hats I'm missing per site,
I decided to use Gists for that.
A perhaps not so well-known feature of GitHub Flavered Markdown (GFM) format used everywhere on GitHub is that if you write bullet point lists with embedded [ ] like this:
- [ ] Bill Lumbergh: answer ... |
I was bored recently and decided to write a class, MorseString. What this class does, is it takes a String that is coded like Morse (.... ..) and stores it. It also translates the String that is coded like Morse into a more "English-friendly" way (HI). This is just the basics I have written; there is much more to come.... |
Due to a performance profiling hotspot detailed here, I implemented my own BitSet using Java's BitSet. This is intended to replace the Enumeration.ValueSet. However, it's a bit awkward to use, primarily due to my likely misunderstanding of the relationships between the Enumeration class, Enumeration type and concrete... |
I am practicing test-driven development in Python. Feedback about both the tests and the code is appreciated. I'm using luhn algorithm and regex to check credit card numbers for validity.
Here are the tests:
from unittest import TestCase
import luhn_check
class TestLuhnCheck(TestCase):
def setUp(self):
pa... |
In my app, I have this code to display different tutorials about OneNote. This clears and resets certain values, and updates some variables so we know which version we are working with. The main problem is it has a lot of repetition in the three ifs, although all comments are welcomed.
private void SwitchVersion(stri... |
I wrote the below enum from which I need to extract the name and its value:
public enum UserEnum {
TreeUser("/tree"), ParentUser("/parent");
private String value;
UserEnum(String value) {
this.value = value;
}
public String value() {
return value;
}
}
This is the way I am usi... |
I'm mostly used to writing scientific code in MATLAB / Python / Julia and my experience with C++ is very limited. I've implemented a fairly simple computation of the Rotne-Prager-Yamakawa tensor in dimensionless form using the Eigen library in C++11 (currently using the Visual Studio toolchain).
#include <iostream>
#in... |
I am hoping that someone can help me out here. I am creating a PHP web app that requires a user to login to view their data in the MySQL database.
I just want to know if this is a good approach and is it secure enough. I know that nothing is secure in PHP scripting but I need this fairly secure.
Here is what I am doing... |
When reviewing a Graham scan convex hull algorithm implementation, I wrote the following function in an answer:
giftWrap :: [Vector2] -> [Vector2]
giftWrap vs = result
where
-- Decides whether to keep or reject vertex b.
-- Vertex b is provisionally kept if a left turn occurs there; the result
-- is final... |
I have written the following query to figure out activity streaks on a per-user basis. I find it... Ugly... And would love to improve it!
Limitations
Those are explained as commented text at the very top of the query.
Problems
Can this be done without a loop?
Is there a better way to do this than #TempTables?
Bonus... |
I have a dining menu app that scrapes the data from a website and redisplays it in a mobile format, displayed below:
If the user swipes left and right, the app will show the previous/next meal (ex. if current meal is lunch, swiping left will show dinner).
I'm trying to come up with a more efficient way of switching be... |
For the sake of full disclosure, this was written with bananas, not apples. The doctor may not be kept away.
With AppleScript highlighting:
For Copy&Pasting:
activate application "TextEdit"
tell application "System Events"
repeat until first window of application "TextEdit" exists
tell application "TextEd... |
I am trying to create something that is very reusable here so that I can use it in other sites for other pages etc.
This code is for a simple photo gallery,
I took the code from here, but I changed it a bit and would like to add more functionality to it eventually, though.
PhotoGallery.ascx
<%@ Control Language="C#" ... |
This question is from Cracking the Coding Interview and in this question they have asked to solve without using temporary buffer.
I have used Iterator interface. Can I use it or need to re-implement it?
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
p... |
I have a JavaScript array:
var data = [{abc: "vf",def: [{ a:"1", b:"3"},{a:"2",b:"4"}]}];
I want it to convert to:
[{"abc":"vf","a":"2","b":"4"},{"abc":"vf","a":"2","b":"4"}]
I have written the JavaScript code for it:
Javascript:
var push_apply = Function.apply.bind([].push);
var slice_call = Function.call.bi... |
Previous question:
https://codereview.stackexchange.com/questions/74677/text-based-tetris-game-follow-up-final
Summary of improvements:
Implementation of a Drawable class
Separate functionality, input moves to Game class
Implementation of Cloneable class by CRTP
Removed global variables
Added Block class
Improving th... |
I just finished Project Euler #9 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.
A Pythagorean triplet is a set of three natural numbers, a < b < c,
for which,
a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exi... |
This question is a follow-up question of this one.
I've learnt a bit more Python since then. I recently came back to making battleships again, and I think I did better.
These are the changes I've made:
Completely rewritten.
Multiple battleships.
Removed difficulty settings (as the way I was doing it before would... |
I am setting a value to input box and trigger to hear the change. I would also like to always hear the input change, and for that I made this function.
Can any expert please verify the way I did is correct? Or is it further tune-able?
var page = function () {
return {
init : function () {
var in... |
I just started to learn AngularJS. I created a simple site using ASP.NET MVC as a backend.
I created 1 main view and 4 partial views for the CRUD operations with a Company Entity.
In the main page I have this element: <div ng-view></div> I load here the required partial view.
I created 2 angular controllers, one for th... |
I made a piece of software that basically adds the functionality of a compose key to Windows, after switching from one keyboard layout to another (for programming reasons), and being unable to find a piece of proper software that did what I wanted.
This was my first venture into making applications for Windows, never t... |
(A quick note on terminology: I use 'generalized functor' to refer to a functor that can be initialized from any callable entity, similar to the definition from Alexandrescu's Modern C++ Design. I use 'generic functor' to refer to functors in the general C++ sense, meaning anything which implements operator())
I'm work... |
I've been playing around with Jekyll and CoffeeScript the last few days and made a Periodic Table to learn those two.
Now, to create the Periodic Table, I take an array of lis as input which then replaces itself with a table using a custom format like so:
periodicTable = [
[1, "s:16", 2],
[3, 4, "s:10", 5, "-",... |
I coded an executable program (.exe) that I only want run either from my home computer, our main server, or people in our development team.
I have coded logic that will only allow the program to be run from certain IP addresses.
The .txt file that's referenced in the getIPlist function looks like this:
[123.456.78.90]... |
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
I started out with this solution. It's iterative, and not very efficient. It multiplies all number combinati... |
This is currently the code that I'm using to validate and check for errors in a flask app, where the form fields are coming from a /registration html page:
@app.route("/register", methods=["GET", "POST"])
def register():
if request.method == "POST":
if request.form['register'] == 'Register':
if ... |
I have a Windows Store and Windows Phone app, and in this app I have many pages like this:
<Grid Background="Transparent">
<ScrollViewer Style="{StaticResource DataPage}">
<StackPanel>
<TextBlock>
Some text here:
<LineBreak/>
</TextBlock>
<... |
I wrote a simple extension to convert a number into a hours and minutes string in the ##:## format. This seems like a good way to do it, but let me know what you think.
Number.prototype.display_hours_minutes = function () {
var remainder = this % 1;
var remainderTime = new Date(remainder * 3600 * 1000);
return ('... |
I've just done Problem 12 of Project Euler:
What is the value of the first triangle number to have over five hundred divisors?
The \$N\$'th triangle number is the sum of all natural numbers from \$1\$ to \$N\$, for example, the 5th triangle number is \$1 + 2 + 3 + 4 + 5 = 15\$
I get the correct answer in around 2.5 s... |
I've the following problem:
Print all valid phone numbers of length n subject to following
constraints:
1.If a number contains a 4, it should start with 4
2.No two consecutive digits can be same
3.Three digits (e.g. 7,2,9) will be entirely disallowed, take as input
Here's my solution:
public... |
I have not worked with jQuery for years so my knowledge of it is extremely limited. I wrote the following form and received a comment elsewhere saying:
This is some of the worst JavaScript I've seen. Your selectors are
terrible ($('div#foo') instead of $('#foo')), you copy-paste code all
over the place, you retur... |
In my webpage, I have the following @media queries:
/* Smartphones (iPhone 3GS/4 and others; portrait and landscape) */
@media only screen and (min-width: 320px) and (max-width: 480px){
html {
font-size: 60%;
}
}
/* iPhone 5 (portrait and landscape) */
@media only screen and (min-width: 320px) and (ma... |
This is a followup to:
Pointer class/handle
Please review this pointer class.
template<typename T>
class Ptr {
public:
Ptr(T* t, int s = 1) {
sz = s;
p = new T[sz];
for (int i = 0; i < sz; ++i) {
p[i] = t[i];
}
}
Ptr(const Ptr& t) {
sz = t.sz;
p... |
As a practice for interacting with system commands, I wrote a Haskell program that compiles a .tex file specified by the argument.
When one execute this program:
If no argument is specified, print "Specify a file!" then exit
If the specified file does not exist, print "File not found." then exit
If the specified file ... |
I just finished Project Euler #10 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.
I hope I learned some from the previous code reviews :).
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below t... |
I created this script to take informations "at-the-moment" of this site:
Pictures of name channel
Name of channel
Pictures channel
Times
Title
Type
My script (Work):
<?php
$url="http://www.programme-tv.net/programme/toutes-les-chaines/en-ce-moment.html#Grandes%20cha%C3%AEnes";
$code_page = file_get_contents($url);
p... |
I'm looking for a way to generate the following the series of numbers given the version number on the left. For example, given "2", generate [6, 18]. The series of numbers is from the alignment pattern locations for different versions of QR codes.
V2 6 18
V3 6 22
V4 6 26
V5 6 30
V6 6 34
V7 6 22 38
... |
We are working on an application with a splash screen. After a few seconds/loading all the data, a login dialog appears inside the splash screen, asking you to enter username and password. Think of a Visual Studio splash screen when you run it for the first time.
Here is how I have done it:
SplashScreenView.xaml.cs:
pu... |
Could you review it and said if it's written good and/or is better way to do that?
My algorithm is:
Input roomNumber
If length of roomNumber is 8 set goToRoom state Enabled and color 0xFFFFFFFF
Else set goToRoom state Disabled and color 0xBBFFFFFF
Code of that algorithm is:
public class Join_room_screen extend... |
I have Conway's Game of Life working now and was hoping for direction on:
Unclear code - where would comments make it clearer?
Poor design choices - I already know of one in the countNeighbors method, as it needs knowledge of the game object's name
Improvements to make - I have already noted that I wish to add more te... |
Here is my implementation of a lock-free thread-safe Fibonacci number generator. Is it correct? The idea is to use an immutable holder for previous and current numbers (since it's hard to change two values atomically at the same time) and AtomicReference which points to the current Fibonacci number.
Lock-free
public cl... |
I was practicing implementing a hash function. I tried to use linear probing to insert in hash table. The insertion is working alright but I am not satisfied with the recursion. It doesn't feel like "good recursion". The Linear_Probing function instead of being recursive itself uses two other functions (excluding hash ... |
sumMultiples() is a working general solution to Project Euler's first problem. Don't read it if you want to try it yourself.
This question is about preserving this general nature while improving performance, perhaps using math tricks like sumSkip() and sumIndetity(). Unfortunately everything I find that takes advan... |
This code is attributed to Stack Overflow itself here. The path which adds to the sum, which need not be starting from the root, not be ending at the leaf, i.e. a path can be between root and a leaf.
I'm looking for code review, optimizations and best practices. I'm also looking for a solution better than \$O(n^2)\$ ti... |
This is a programming problem:
Write a program that finds and displays all pairs of 5-digit numbers
that between them use the digits 0 through 9 once each, such that the
first number divided by the second is equal to an integer N so that:
abcde / fghij = N
where each letter represents a different digit. The first... |
I'm trying to set multiple attributes in d3 but I get an error for the stroke width attribute due to the dash.
I can get around this by chaining another attribute's call but I would like to keep them all in one call if I can.
Is this possible?
var edges = svg.selectAll("line")
.data(data.edges)
.enter()... |
I am currently implementing a fun project involving lambdas and this project makes heavy use of the ability of Java 8 to have default methods in interfaces.
But when does such "heavy use" turn into an outright abuse? Here is one example of an interface which I have defined, and its 4 methods may extend to even more in ... |
I have tried to implement two methods, one for finding the size of the tree and the other for finding the height of the tree. Can they be optimized further?
package trees;
import java.util.LinkedList;
import java.util.TreeSet;
public class TreeNodeImpl {
public TreeNodeImpl left ;
public TreeNodeImpl ... |
This is probably one of the many follow-ups coming. What I have edited:
Added equals() and hashCode()
Added . and , to my Morse code "dictionary"
Used a Pattern for regex checking
Edited method names
Concerns:
Any bad practices in the new code?
Does it "smell"?
import java.util.regex.Pattern;
public class MorseSt... |
I'm trying to create a little block presenter for Laravel which displays blocks of content in certain positions. I have 2 classes, BlockFactory and Block. The BlockFactory contains all the blocks and creates them whereas the Block class is exactly just that: a simple block.
As can be seen in the code below, when I'm cr... |
Is this implementation correct? Do you find any threading problem? Also, what parts of the code can be changed to be more C++11-ish?
#include <iostream>
#include <vector>
#include <thread>
#include <random>
#include <condition_variable>
namespace {
int sleep_for_random_time() {
std::random_device rd;
... |
I have tried to write JavaScript code to check whether I can form a word from the given string (jumbled):
function findWord(word, jumbledLetters, isSameLength) {
if(isSameLength && word.length !== jumbledLetters.length)
return false;
var uniquePosition = {};
for(var i = 0; i< word.length; i++)
for(var j=0; j< jumbledL... |
I tried to solve Project Euler 12 with a first very naive solution by myself. It took nearly 30 minutes to run until it found the solution. Then I made a change in the function getDivisorCount which should have made the run time to about the square root of the original code, about 5 minutes. At least this was my opinio... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.