instruction stringlengths 71 71.9k |
|---|
I've implemented a small program in JavaScript to count the number of lines of a string of java source code.
This was done for one of the Code Kata exercise: http://codekata.com/kata/kata13-counting-code-lines/
Overall, the goal of this exercise is summarised as follow:
The mixture of line-based things (single line co... |
I'm trying to optimize this repetitive piece of code. I think I need to set subsection href as a variable and then figure out a way to merge the functions?
$(document).ready(function () {
$('#alphabetical').click(function () {
$('.subsection').attr('href', function () {
return this.href + '&sort... |
In order to learn Prolog, I have implemented the cat command in Prolog. I want to know if the code is idiomatic and what could be improved.
File args.pl:
:- module(args, [withFilesOrUserInput/2]).
withFilesOrUserInput(StreamFunction, []) :-
call(StreamFunction, user_input).
withFilesOrUserInput(StreamFunction, [F... |
I am new to async and was wondering if any improvement can be made to the solution I put together from scattered information on the web.
The following (working) code shows how a button press runs logic and if there are any errors they will appear in the returned task.Exception.Handle variable which I can check in my C... |
I am new to the world of jQuery plugins, I don't know why I didn't get into this sooner. What I have a working validator that validates bootstrap styled forms. What I have discovered is that the way it is set up causes error when there are more than one form on the page. I would like to know how to make it more efficie... |
I'm transforming this:
[["Apples", "fruitgroup", "123"], ["Bananas", "fruitgroup", "012"], ["Jumbo Jet", "planegroup", "99"], ["Crop duster", "planegroup", "40"], ["Melons", "fruitgroup", "55"]]
into this:
["Apples or Bananas or Melons [x]", "Jumbo Jet or Crop duster [x]"]
Because basically I have to group the child ... |
What my query is doing:
I have two SQL tables and I want to copy datarows from the one table to the other table. I am doing this for statistics. The source table includes all current member-sessions/logins and with my statistics table I also want to see member-logins of the past. Thus I want to store these data into my... |
I have this code, but it looks a bit verbose:
enum MonitoringMode
{
Seek,
Destroy
}
void ToggleMonitoringMode()
{
if (_monitoringMode == MonitoringMode.Seek)
_monitoringMode = MonitoringMode.Destroy;
else
if (_monitoringMode == MonitoringMode.Destroy)
_monitoringMode = MonitoringMod... |
As C does not have a native string type, I decided to try making a similar type. It's not perfect by any means, so I was coming here to see what I could do to improve it.
I have tested my code and it works; if I were to write 'User', the output would then be 'Hello User'
#include <stdio.h>
#include <stdlib.h>
#include ... |
My program is complete and working, but I would like second opinions on it. The program prompts the user to enter something like a phrase or some words. Then it will create an acronym of what was entered. What are some adjustments I can make to my program to make it more efficient?
#include <iostream>
#include <strin... |
This is a simulation attempt of an "old-style game", where a "car" (nothing more than a red rectangle) must dodge some "obstacles" (blue squares) falling from the upper edge of the frame. If an obstacle hits the car, the game stops.
The app works fine, but since this is my first project involving painting and moving ob... |
I am new to Angular. Am I following best practices here? I understand controllers should not do too much. My controller seems to have a lot of logic here. Can I do anything to improve it? It is just a basic ToDo App.
var app = angular.module('app', []);
app.controller('FirstCtrl', function($scope, todos){
$scope.t... |
I just started learning MIPS assembly at my university and I would like some feedback on this code. The program is Project Euler Problem #1, finding the sum of multiples of 3 or 5 less than 1000. It works but I am interested to hear what I could do to improve it (best practice, efficiency, etc). I found x86 solutions t... |
Applying a lot of unprecedented concepts here, it's a simple chat server capable of handling multiple clients, which are run through JavaFX, and have their individual threads instantiated and handled within the application thread (was more complex than anticipated).
The Chat Server:
import java.io.BufferedReader;
impor... |
I have the following Oracle SQL query to generate some system-stats. I am interested in making it a more efficient and readable query.
SELECT
SUM("Req Lines") as "Requisitions Created",
SUM("Approved Req") AS "Requisitions Approved",
SUM("Non Approved PO") AS "PO Started",
SUM("Approved PO") AS "PO... |
Since I couldn't find any good answers I made my own class called DuplicateDictionary for personal usage. I would like some tips to improve it.
public class DuplicateDictionary<TKey, TValue>: List<KeyValuePair<TKey, TValue>>
{
public DuplicateDictionary()
{
}
public DuplicateDictionary(List<KeyValuePa... |
Here is my second attempt at writing clean code for "Sherlock and Pairs" challenge. For my previous thread please look here: Calculate pairs in a Set ("Sherlock and Pairs" HackerRank challenge)
Problem statement:
Sherlock is given an array of N integers (A0,A1…AN−1) by Watson. Now
Watson asks Sherlock how many diffe... |
This code works just fine, but could obviously be more elegantly written.
The basic idea is to create an array of categories from a text input. The code splits up the text input by commas to create the array and trims away white space.
I considered using unshift to add the 'Inbox' default category to the beggining, b... |
My program is complete and running, but I would like second opinions on how I can make it more efficient. The program prompts the user for the message and the amount s/he would like to shift the letters. For the implementation part, is there another "faster" way to do it instead of having the if else if statements to r... |
I am using the java.awt.Rectangle class to construct subsets of a GEOTIFF file. In order to do this I would need to specify the x,y offsets, height and width of each subset image. In my particular case I would need to crop the original GEOTIFF image bottom to top. The java.awt.Rectangle class specifies that the origin ... |
I am developing an e-commerce site and am confused about this.
Customers come on the site and add some products to the cart.
Customers click on the checkout link if already logged in, then will go to the "thanks" page (this is your order number, total price, etc.).
I want to insert the total price into Order table.
<... |
I wrote an Array class with iterators:
#include <iostream>
using namespace std;
template <class T>
class Array
{
T* data;
int size;
public:
class mException { };
Array(int nsize=1)try:data(new T[nsize]),size(nsize)
{
}
catch(bad_alloc& r)
{
cout<< "Cant allocate";
throw;... |
Running on Cygwin, I cannot easily use perl -pi -e because it will always produce .bak files even though I don't want them. I wrote this script below to emulate perl -pi -e behavior and unlink the backup files after processing.
Also I wanted to simplify the call of the script. Instead of:
$ git ls-files | xargs perl -p... |
I need to call the function that will get the value of a datatable cell with the ColIndex, either a text (column name) or an integer (columnindex).
To avoid writing two functions that, I wrote this code:
Public Function DTableCellValue(ByRef RowData As DataRow, _
ByVal ColIndex As Ob... |
I've created code for a menu system that can show / hide menus and submenus. Now I wonder if the structure of the code is good enough or if you find something that can be done better?
var initExpanders = function () {
"use strict";
function lsTest(){
var test = 'localstoragetest';
try {
... |
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
public class Java {
public static void main(String[] args) {
long start = System.nanoTime();
long sum = 0;
for (int i = 2; i < 2000000; i++) {
boolean isPrime = true;
if ((i % 2 == 0... |
I have a simple function that takes a string and reverses it:
def reverse(string):
begin = 0
end = len(string) - 1
strlist = [i for i in string]
while(begin < end):
temp = strlist[begin]
strlist[begin] = strlist[end]
strlist[end] = temp
begin += 1
end -= ... |
I have a system that accepts free text from users. This can either be plain text or a heavily limited subset of HTML. I've written the below with Html Agility Pack and Microsoft's AntiXss library. I have had to remove a few things from the below code which do things like whitespace normalization, punctuation normalizat... |
I am currently done with this little Rock, Paper, Scissors, Lizard, Spock game in JavaScript. The game is working fine, but I am not pleased with the code. Is there a way to refactor these if statements? I was thinking about ternary operators and I tried doing so but failed. This is basically my function based on which... |
I am new to Java Swing and have decided to create a calculator to learn some of the basic. I would like someone to look over my code to see if they can give me any improvements.
I have 6 classes and 2 interfaces. I have chosen to split the communication of both operators and digits. The mainframe is the controller and ... |
I been having discussion with colleagues recently about good use of matchers. Consider the following sample:
@RunWith(MockitoJUnitRunner.class)
public class LoginRestServiceImplTest {
@Mock
private LoginService loginService;
@InjectMocks
private LoginRestService loginRestService = new LoginRestServic... |
Shall I make a curry function this way, or is it best to avoid Function constructor in all means? What I want to know is if this is "bad practice" and how else currying can be done. For instance, one can bind arguments to a function with Function.bind, but it is more like a partial application thing. And will doing cur... |
I got to show the createdAt date in a message timeline, I tried to make a separate array only for dates, but don't know if it is the right path to follow. It seems to me that my workaround is too tricky.
I'd like to be sure that what I've done is not necessarily the right way, but at least it isn't a wrong way (Edison'... |
I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should be added.
This is my current code that looks a bit dirty to me:
def my_join(major, minor, patch=None, pre_release=None,... |
I made a Tic Tac Toe game, but I think there's a lot of hard-coding and useless variables. Can you check it out and tell me what I can improve on? It works, but it has a couple of bugs.
#include <iostream>
#include <stdlib.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<iomanip>
using namespace std;... |
My Racetrack is just that. A Racetrack. You can't race it (yet) because I had trouble with collision detection, but I wanted to share it anyway.
It creates a base polygon by using numpy and shapely. matplotlib (together with descartes) does the plotting and cPickle is used to write states to file so the exact same trac... |
I'm trying to dive deeper into C#, and so I've been experimenting with some code. I'm creating a console application that shows the path of a projectile depending on the angle, and it works great! You can check it out here actually. It's not perfect, but I like it.
Is there a better way to use my for loops? I'm using 3... |
I needed a data structure to quickly find all previously inserted values, that have the given string as key or substring (full text search).
At first, I tried out some tree structures (infix trie/tree) and was shocked by the slow insertion time and memory usage.
That's when I developed the InfixDictionary<T>, which is ... |
Problem statement:
Write a function which returns the total number of combinations whose difference is k.
For example, 4 8 15 16 23 42 and the difference 7 has 2 pairs, 8, 15 and 16, 23.
I liked the Finding number of number pairs with given difference question so much (despite its brokenness) that not only did I rev... |
I have created an inventory that works via QR codes. Briefly: the QR code codes for an email with the book/student checking it out. The email is downloaded into R using the gmailR package (code not shown). The info from the email is taken and added to a table which is compared to a master table (the inventory) and the ... |
Given a set of points, what is the number of isosceles triangles that can be formed with the combinations of all points in the set?
It is certain that 3 collinear points never exists in the set.
#include <stdio.h>
typedef unsigned long long llu;
typedef struct {
llu x,y;
}point_t;
inline llu distance_p(point_t &... |
I wrote a small code in Python to conduct a backtest. My rebalance function is very slow and I would like to improve it. I need to profile it but I would welcome any opinion on how to refactor my code nicely.
def Rebalance(self, currentDate, data, VolatilityForSizing,Wthtslippage=True):
# Handle open positions... |
Today I saw an extremely interesting question on the Rock, Paper, Scissors, Lizard and Spock game. I've decided to take my swing at it and I've written the following OOP implementation:
function RockPaperScissors(name, hard_action, soft_action) {
this.name = (name + '').toLowerCase();
this.hard_action = hard_ac... |
hackerrank.com - diagonal difference:
Problem Statement
You are given a square matrix of size N×N. Calculate the absolute
difference of the sums across the two main diagonals.
Input Format
The first line contains a single integer N. The next N lines contain N
integers (each) describing the matrix.
Constraints
\$... |
This is a school project and took me a while to write the code. Any help to improve my code is welcome!
#include <fstream>
#include <conio>
#include <stdio>
#include <stdlib>
#include <iomanip>
#include <windows>
#include <time>
typedef char string[50];
int ra;
/***************************************
Modified gets() f... |
Basically I am trying to iterate over one collection moduleList and adding to another collection targetList
Is this a good practice in Java 8? Do we have better way of doing this?
modulesList.forEach(
m -> targetList.add(new ModuleType().withModuleNum(m.getLeft()).withModuleName(m.getRight())));
|
I've created a Windows Form Number to Word converter application in C# which converts any number from 0 to 1 million. I would love a review based on efficiency and best practices.
MainInterface.cs
using System;
using System.Windows.Forms;
namespace NumberToWords
{
public partial class MainInterface : Form
{
... |
I have been fiddling around with creating my own Sprite Cache.
Currently, I am using the C header file, dirent.h, to open up a directory and load all .bmp files. I do not have to check if the file ends with .bmp, as SDL_LoadBMP will return a null pointer if it can not read the supplied file as a bitmap image.
One thi... |
I wanted to implement a van Emde Boas Tree in Rust, to start learning the language. Much of my implementation is derived from the pseudo-code on wikipedia, with the exception that empty subtrees are not stored.
Besides the obvious lack of docstrings on public methods, what could be improved?
use std::mem;
#[derive(Deb... |
It's a script that I've ripped off elsewhere, and have modified it via help from Stack Overflow on a couple of other questions, so that it tops out at 10 fields.
My knowledge of JS/jQuery is barely there. I'm terrified that I did it badly or wrongly. Could you please let me know if this is the correct way of doing it,... |
I have this query here that I am trying to make more efficient as it is taking an extremely long amount of time, about 40s on 3 million records.
The query basically takes X amount of rows per company and turns them into columns for a given existing column.
SQLFiddle
SET @sql = NULL;
SET @sql1 = NULL;
SET @sql2 = NULL;
... |
I have a table that reads every minute, but the data on one meter only changes once every 60 minutes. It will then repeat that value for 60 minutes before changing again.
I need to take the sum of these values and add them up for the day. But if I grab it by the hour, I will get duplicates. So what I decided to do was... |
This code runs fine without a bug, I need to optimize this code for following interview requirement.
Lets say i need to send it to 1 million contacts and emailBody is ~100Kb.
What code optimization do you recommend to make it faster ?
Write code or algorithm to explain the optimization you think will make this code fa... |
Write a menu-driven program to represent Polynomials as a data
structure using arrays and write functions to add, subtract and
multiply two polynomials; multiply a polynomial with a constant, find
whether a polynomial is a “zero” polynomial, return the degree of the
polynomial. Assume that a new polynomial is ... |
This is a follow-up question to this question.
Is this a reasonable implementation for a blocking version of method ArrayBlockingQueue.drainTo(Collection)?
/**
* This blocking method blends {@link #take()} with {@link #drainTo(Collection)}.
* <br>
* Chiefly, {@code take()} blocks and {@code drainTo(Collection)} does... |
I've been on a quest to learn C++, and to learn, I've started building a small Role-Playing-Game skeleton to help myself learn the language. I've tried to make sure that I've followed C++ styles/standards correctly.
This is the first "part" of my development of the skeleton, and it includes a usable class, Character. T... |
Is there a more efficient way to do the below without two for loops in actionscript 3? In java there is NavigableMap or something like that where dont need to loop.
var treasureItemsWeights:Object = { "1" : 5 , "2" : 20, "3" : 400, "4" : 60, "5" : 20,
"6" : 20 , "7" : 20 ,... |
I've been playing around synchronizing two scrollbars on a web application using JavaScript and jQuery (1.11.3). So far what I've been doing is any time a scroll event happens on one div, I use scrollTop to adjust the position on the other div:
$left = $("#left")
$right = $("#right")
$left.scroll(function () {
$ri... |
I would like to refactor that code.
def experiences
work_experience_array = @coach.delete(:work_experience)
education_array = @coach.delete(:education)
array = []
array << work_experience_array.map do |experience|
Db::Experiences::Work.new(experience.for_indexing)
end
array << education_array.map do |e... |
I want to store some user settings into a file, so that the users get the same experience on all machines they're working on. The built-in user.config turned out to be insufficient, as I can't store Nullable<T> values in it.
I created a simple class for my program that stores the user settings in an XML file. This is h... |
Given a bunch of latitudes and longitudes stored as Points, I would like to determine the points that are closest to each point given some maximum threshold in meters. This is my first stab at this:
DECLARE @ThresholdInMeters FLOAT = 1000000.0;
IF OBJECT_ID('tempdb..#Points1') IS NOT NULL
DROP TABLE #Points1
CREAT... |
I have this PHP curl function to check if a site is online or not:
function check($proc,$url,$keyword,$method,$timeout,$maxredirs) {
// Format Link
$link = $proc."://".$url;
// Agent
$user_agent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.... |
How would you simplify the following block of jQuery code?
I use this in a tab-box to size the tabs to style the tabs to the full width of the box no matter if it's 2 or 10 tabs...
It works perfectly, just interested if there's a better/shorter way to achieve the goal.
$(document).ready(function() {
$('ul.tabs-list')... |
I saw this question:
Is this FizzBuzz Swift-y? and I couldn't resist the temptation to attempt a Swift2 implementation:
for i in 1...100 {
switch i {
case _ where i % 15 == 0: print("FizzBuzz")
case _ where i % 3 == 0: print("Fizz")
case _ where i % 5 == 0: print("Buzz")
default :... |
I made a code and it is doing what I want.
But, I would like to know if I am doing it right or in the best way.
Could you please give me your thoughts about it? Thank you.
$result = mysqli_query($sql);
$p_before = "";
$year_before = "";
while ($rows = mysqli_fetch_array($result)) {
$p_now= $rows["cop"];
i... |
I'm building a bounding volume hierarchy in Golang. I can tell my code works because I did some test on it and it gives the same results as the brute force implementation (brute force is to test all possibilities, in \$O(n^2)\$).
My problem is that the code is slower than the brute force implementation (not by that muc... |
I have written this function but I am not so proud on it. I could use some help refactoring it.
Would recursion improve my code?
Data sample.
{
"Name":"test2",
"DepartmentUnitId":"test",
"ParentDepartmentUnitId":"test",
"NestedDepartments":[
{
"Name":"test2",
"DepartmentUnitId":"test",
... |
In this scenario, the main page contains a list of links to the subpages. The requirement is to navigate to each page (if a condition passes) and perform some actions.
I have written the loop using Geb:
at MainPage
ListItem.each {
if(Button.present){
Button.click()
at SubPage
... |
I found a few question about the game and IMHO it's a relational problem and better addressed by set logic. Thus I created this solution in SQL to get away from ugly JavaScript, elegant java and practical C#
--drop table [Hand]
--drop table [Action]
create table [Hand]
(
Id int primary key not null
,Name varc... |
I have the following table definition:
CREATE TABLE ProductPointValues (
id INT,
effective DATE,
minPoints INT,
maxPoints INT,
CONSTRAINT PK PRIMARY KEY (id, effective),
CONSTRAINT FK FOREIGN KEY (id) REFERENCES Products(id)
)
;
INSERT INTO ProductPointValues
VALUES
(1, '1/... |
Win32 File API Wrapper
Based on a few fundamental frustrations with VBA (namely the lack of ability to work with files larger than 2GB, the lack of encapsulation of the file functions and the lack of intellisense to guide my use of the file statements) I put together a wrapper for the Win32 File API. This includes 64-... |
Background
I work at a company that makes hardware products. All the test settings are stored on the server so it updates all our test stands.
I'm currently working on a web-based app using ASP.NET so we can quickly change the test settings. I've been working to make the UI easier to use by adding modals, AJAX, and som... |
I wrote an ugly mess of a JavaScript function that pops up a dialog box based on validation data, when a checkbox is clicked. I am wondering if it can be refactored somehow.
varButtons contains code for which buttons are used as a parameter to BootstrapDialog function.
//checkbox validation
var varButtons = [];
if (is... |
I'm studying C# and trying to work on efficiency and making the best use of C# 6.0 features. I have created the following program based on an exercise challenge in a book, and have used Resharper to fix certain things; however, I still feel my novice knowledge of C# is preventing me from creating the below program in a... |
This is a start towards implementing a poker-like game called Jacks Or Better.
Before proceeding to improve the way cards are shuffled and dealt, I would really appreciate help cleaning up my code.
using Sandbox.Properties;
using System;
using System.Windows.Forms;
namespace Sandbox
{
public partial class Form1 ... |
I have written code to check any birthday input's validity. As I am new in programming, and after going through several debugging steps, the code became very ugly.
month_dict = {'jan':'January',
'feb':'February',
'mar':'March',
'may':'May',
'jul':'July',
'sep':'Septembe... |
I have trouble understanding recursion, so I'm trying to implement algorithms using it. I wrote this code that calculates the length of the longest increasing sub-sequence. How can I improve this?
int _lis(int arr[], int n){
if(n==0) return 1;
int m=1, temp;
for(int i=0; i<n; i++){
if(arr[i]<arr[n]){
... |
After reading a lot of tutorials, I was finally able to code my version of a Tic-Tac-Toe game. I would like to have some honest review of the code to see what I can do to better my coding.
class Game
attr_reader :board , :marker
def initialize
@board = Array.new(3," "){Array.new(3," ")}
@marker = ["X", "... |
I have created a simple program that is supposed to be the core of a roguelike game. The program uses ncurses, and all that is supposed to happen is you choose a race and class, then choose an arena. The player can move around, and if the player moves onto deep water or lava, they die.
/*
* main.c - main file for the ... |
I wrote this encrypter based on the idea of a Vigenere cipher, but instead of using only one key, it "makes" another key from the existing key. The length of the second key also depends on the different characters in the first key. And so it uses both keys in the shifting of letters.
def scram(key):
key2 = []
#... |
This is an implementation of the Nothing programming language. The language spec is as follows:
Design philosophy
In the current software industry focus lays on solving complex
problems by using complicated algorithms. The language "Nothing" was
created to shift this focus from complex problems towards the
expec... |
I am working on some code that will generate a link with a relativly unique 10 character hash. I am not worried to much about colisions as long as they are rare enough that I could have a couple thousand links out standing since I soft delete after they are used and a colision between an open item and a closed item is... |
My program is complete and runs, and gives me the output I expect. For example, if I enter the string "HELLO" I should get 8. Are there any improvements that can be made?
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int gameScore(string word);
int letterValue(ch... |
I managed to finish my approach on the legendary Snake game. You move around with the WASD keys. I would like to hear your opinion and maybe ideas on how I can improve frame rate because now it sort of flickers (but it is playable).
#include <conio.h>
#include <stdio.h>
#include <ctime>
#include <vector>
#include <win... |
I was assigned to write a piece of Haskell code that makes an infinite list containing increasing numbers of 'a's.
My first thought was to write it as a list comprehension like this:
aStar = [replicate n 'a' | n <- [0..]]
But when I asked my professor he said I should use explicit recursion so I came up with this:
aSt... |
I've created a working XML RSS reader. I wanted to know if it's a good one or not and if it's efficient for the server or not. I run this code every 12 hours or something give or take the amount of time that a new article will be published.
This is the code itself with all the explanation of every part of the code. Tel... |
I've been working on this utility for a while now, and have since gone through a couple reworks to try and increase the readability and best practices, but since I don't usually work a lot with Swing, or UI design in general, I still have the nagging feeling there's a better way to approach this. Code for both files is... |
Since I learnt about refactoring, I've been busy creating my own Module of Standard Methods. I feel it's about time they got a review of their own.
Open to all aspects of advice but particularly interested in:
Method Naming:
Are they completely unambiguous about what the method does/returns?
Use of Optional / Variable ... |
template<typename... T>
constexpr std::size_t sizeof_struct()
{
// Helper
auto alignto = [](auto x, auto a) { return (x + a - 1) / a * a; };
// Algorithm
std::size_t max_align{0};
std::array<std::pair<std::size_t, std::size_t>, sizeof...(T)> arr{{
{alignof(T), sizeof(T)}...
}};
a... |
Code shows duplicate values of integers in an array with indexes and the number of occurrences. Can you please critique my code and provide your thoughts on where I should improve my code?
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;
public class DuplicatesInAnArray {... |
Rubberduck's unit testing feature (heck, the whole project) started with a VBA unit testing framework that was ported from vba to c#; the VBA logic was pretty much simply rewritten in another language, and a dockable toolwindow is now available in the VBA IDE for Rubberduck users around the world:
For the next major r... |
I wrote a little fractal noise generator the other day, and to test it I wanted to display the dark values with a darker character and the bright values with bright characters (I use a dark background with light foreground). So I wrote a simple java program to do this, and here it is:
package com.loovjo.brightSort;
im... |
I'm trying to solve this problem. I changed Scanner and used BufferedReader but I'm still getting TLE with the given code. Can I have a code review to help determine where else performance can be optimized?
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.InputStreamReade... |
I am working on an application in which I have to parse an XML file. Nodes of the XML file corresponds to an object. I have to populate the properties of the objects at run time. The code below queries the metadata of property and sets its value. Is there a better way to do it or is there a better way to map the elemen... |
I'm doing a problem from Project Euler to find the sum of all primes under two million.
My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it just won't finish.
import time
import math
def primes_sum(limit):
num_list = range(2, limit)
i, counter = 2, 1
... |
This is my first attempt to draw using FLTK libraries *:
// Objective: Draw an 8-by-8, red and white checkers board
#include "std_lib_facilities.h"
#include <iostream>
#include "Simple_window.h"
int main(){
try{
// create a window in the center of the screen wiht size: 600x600
int wWidth = 660;
int wHe... |
As my first Java program, I have written a number-guessing game. I would appreciate any suggestions on how I can clean it up or streamline it. I don't mean cut down on the general tasks executed within the program, but rather if there were better methods/classes/syntax I could have used to make it better. I took a few ... |
First off, this is the 3rd (and probably last) review of the project in question. You can find the previous question here.
The Macro accesses a workbook containing 8 worksheets each with similarly structured but not identical tables of data (submitted business for my company). It then filters this data for desired colu... |
I have been trying to get better at functional programming, which includes understanding map/reduce. I wrote a function intended to fill an autocomplete with values. The challenge I was encountering was my Mongo records, which had a category array that needed to be flattened for the autocomplete to work. Being a novice... |
I currently have what seems to be a very overly complicated underscore template full of conditionals and as the data grows I'm worried the conditions are going to get more and more extreme. Can anyone advise how I could make this template logic a little easier for my inputs, right now I'm running if...else just to make... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.