All Questions

Filter by
Sorted by
Tagged with
40
votes
5answers
3k views

Regularity in the “Rusty Towel of Mutual understanding”

I have the following Java class: ...
40
votes
4answers
4k views

Rock-Paper-Scissors-Lizard-Spock Challenge

"Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitate lizard, lizard eats paper, paper ...
40
votes
3answers
52k views

Delete folder if it exists in PowerShell

In my PowerShell script I'm trying to delete a folder, but only if it exists: if (Test-Path $folder) { Remove-Item $folder -Recurse; } I find myself repeating ...
40
votes
5answers
22k views

Determining if two words are anagrams

I was given a this problem at a technical interview and failed miserably in the time given. Afterwards, I sat down and worked out what I think is a good solution. The task was actually to build an ...
40
votes
2answers
227k views

Converting DataTable to List of class

I am using ExcelDataReader to import an Excel file to a dataset. Example Excel table: ...
40
votes
1answer
3k views

The right way to hang a man

Problem: I have seen a few questions around hangman. Usually this is done in a very hackish way, which usually can not be generalized any further. My thought or question is about the creation of the ...
40
votes
1answer
2k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
40
votes
0answers
804 views

Swiftly turning wheels – The May 2017 Community Challenge

This is my attempt at the May 2017 Community Challenge in Swift, with a chain consisting of rigid links. I took this as an opportunity to learn SpriteKit, Apple's framework for 2D games. At least ...
39
votes
8answers
17k views

Deck of cards as an interview exercise

I was asked to write a test code for an exercise for a job I applied for. I was rejected, and I didn't know why. And I want to ask your opinions about my code. The exercise is like that: Write a ...
39
votes
6answers
3k views

SHOUTY_SNAKE_CASED NUMBERS

WE_ALL_LOVE_SHOUTY_SNAKE_CASE_SO_I_WROTE_A_PROGRAM_FOR_IT!!1! Alright, enough of this. This is a rags-to-riches from this question. The pattern is pretty simple, it takes a ...
39
votes
7answers
3k views

Is my code a 'safe' singleton?

I was wondering if my code will produce a true singleton. I am creating an Android app, and all activities should access my API through one instance of the SyncApi ...
39
votes
2answers
4k views

Hello, Brainfuck

It has been bugging me for a while that while I understand how the basics of Brainfuck works, I can't get a firm grasp on the advanced features of the language. So I started to re-evaluate what I know ...
39
votes
2answers
70k views

Finding the closest point to a list of points

I'm trying to find the closest point (Euclidean distance) from a user-inputted point to a list of 50,000 points that I have. Note that the list of points changes all the time. and the closest distance ...
38
votes
3answers
10k views

Exporting doc types using queues and multithreading

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
38
votes
5answers
4k views

Easier user input in C++

A more proper version of this utility can be found at the following link here: Giveth me thy easier user input in C++ - follow up. I've always been a little bothered by the fact, that in order to get ...
38
votes
5answers
24k views

Designing a coffee machine

I was recently rejected from what looked like a really promising string of interviews. I did very well in a questionnaire style review, and then they handed me this assignment (more or less): ...
38
votes
8answers
17k views

Rendering a person's time clock record in HTML, with many color-coded conditions

I have coded this mess of JavaScript and a bit of jQuery. Everything here works perfect as intended, however it is a real mess. What would be the best way to clean this up with best practices and ...
38
votes
5answers
9k views

Database connection in constructor and destructor

I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This ...
38
votes
5answers
5k views

Parallel sieve of Eratosthenes

For the first time, I tried to use threads by myself in order to implement a parallel sieve of Eratosthenes. The trick is that each time a prime is found, a thread is spawned to eliminate all the ...
38
votes
7answers
11k views

Logging without Code Bloat

I was wondering if any of you know any best practices or design patterns so that I can have good logging in my programs without them looking messy or bloated. I am currently using C# and NLog, ...
38
votes
4answers
5k views

Everyone loves Fibonacci

I was bored and burnt out on more serious projects.... until I saw this Computerphile video on YouTube. Now I'm inspired again. Now I feel like spending some time implementing that recursive algorithm ...
38
votes
3answers
8k views

Why is my C program for calculating Euler's constant of poor quality?

I was trying to post this code to a Wikipedia article, but it was soon removed. I then asked about the code in the page's talk section, and some other contributors said that is was "very poor" and ...
38
votes
5answers
31k views

Incrementing Integers in Map

I have a HashMap<Token, Integer>, which counts occurrences of Token. Each time Token ...
38
votes
2answers
392k views

Snake game in C++

This is my version of the Snake game, written in C++. How could it be improved, and what general advice would be useful for future projects? ...
38
votes
4answers
6k views

Ultimate Tic-Tac-Toe in C

Here is my attempt at the UTTT code-challenge (in response to the the Weekend-Challenge Reboot). Here is what I would like critiqued: I tested the code a few times for bugs, but I may have missed ...
38
votes
2answers
34k views

Balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For example,...
38
votes
1answer
448 views

Beta-Blue B. Gone

I've written a Code Review design using Userscripts and CSS. It works by fetching the CSS from my GitHub repo, and using the built in gm_addStyle function to add ...
38
votes
2answers
971 views

Brainfuck to x86 Assembly Compiler

After my Brainfuck Interpreter written in x86 Assembly I decided that it was time to get to the next step, writing a Brainfuck Compiler in Java that generates x86 Assembly and compiles that to an ...
37
votes
4answers
5k views

Beheading of knights, who survives?

We have a round table of n knights, where n is some positive integer. These have failed to satisfy the expectations of the mad ...
37
votes
10answers
7k views

Which FizzBuzz is better, and why?

I was in an interview and the guy asked me to do the typical FizzBuzz question of printing numbers 1-100, but for each factor of 3 print Fizz, each factor of 5 print Buzz, and each factor of both ...
37
votes
5answers
2k views

First Time HTML5/CSS Site

I am working on my first HTML5/CSS web site and, like all of my first-time projects, they end up cumbersome, crude, and hard to work with when changes need to be made later in the life cycle. I am ...
37
votes
4answers
7k views

“How are you spending your time on the computer?”

I've made a Windows Forms application to track all of the processes running on my machine and it also saves the time an application is "active", an active application is the one that is on focus ...
37
votes
4answers
4k views

Someone thinks poorly of my server log parser

I have just been informed that the following code written by me is extremely poor. I have absolutely no idea why. It is memory efficient, and looks clean to me. But still the feedback is very poor. I ...
37
votes
5answers
3k views

Running Lights - Embedded “Hello World”

I'm getting my feet wet in embedded development, and like all those before me, my first task was to make an LED blink. I went a bit further than that and made a "runner" that lights up each led from 0 ...
37
votes
8answers
8k views

The FizzBuzz challenge in Java 8 written in a short, readable and interesting way

I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program. This in contrary ...
37
votes
4answers
30k views

Swift 1.2 Singleton Implementation

I am pretty new to Swift, as a solo developer I was wondering if somebody could pass comments on the singleton implementation below. The code does work, but being new to Swift and knowing that there ...
37
votes
6answers
7k views

Calculation of prime numbers making use of Parallel.ForEach

In my spare time I decided to write a program that would systematically identify prime numbers from 2 to 18,446,744,073,709,551,615. This is for fun and learning, as I know it will take too long to ...
37
votes
3answers
4k views

Displaying courses in an HTML calendar

I'm struggling for a while now with the readability of my code, I after I tried to get as much insight as possible (for my standards). On my level, I think I understand and use it all right for my ...
37
votes
1answer
6k views

Python package for handwriting recognition

I am currently writing my bachelor's thesis about on-line handwriting recognition. This is not OCR, because I have the information how a symbol is written as a list of pen trajectory coordinates (x, y)...
37
votes
2answers
3k views

KISS my… unit of work

I've seen many, many UoW+Repository implementations. Whenever one was built on top of Entity Framework, I'd cringe at the added complexity. Sure the complexity buys you (sometimes) full decoupling ...
37
votes
1answer
3k views

Recursive shared_mutex implementation

I found myself in need of a Readers-Writer mutex. With C++17 TR2 support not yet available in our compiler, I set out to implement std::shared_mutex so that we have ...
37
votes
1answer
1k views

Utility that decodes and logs UDP packets

I have written the following utility, as my first non-tutorial program in Go. The purpose of the utility is to connect to a torque/force sensor (aka load-cell) via UDP; to send an initialization ...
37
votes
0answers
1k views

JSON formatter in your least favorite language

Just joking guys, Brainfuck is an awesome, challenging language. I've tested the following code with bf-x86 compiler and rather big JSON file. I believe code is fully functional on a valid (!) JSON ...
36
votes
6answers
13k views

Random IP Address Generator

randip.py I know there are probably better, easier ways to do this. It was just a bit of a learning exercise for the sake of familiarising myself with Python. It takes a single argument (positional ...
36
votes
5answers
142k views

String.IsNullOrEmpty in JavaScript

I am aware of it being frowned upon to do something like write C# in JavaScript. (see this if you don't know what I'm talking about) But as a judgement call, I think we could stand to have a ...
36
votes
6answers
3k views

Resolving a link

How can I clean this up? ...
36
votes
11answers
27k views

Perform instruction in loop every time except the last time?

The specific issue is this: I am writing to a file and want to output a new line after each line written. If I use a normal loop without any further checks, this will create a blank line at the very ...
36
votes
2answers
5k views

Quicksort implementation seems too slow with large data

I've written a program to compare different sorting algorithms with the array size being 10, 1,000, 100,000, 1,000,000 and 10,000,000. I, of course, expect Insertion to win out on 10 and merge heap ...
36
votes
5answers
13k views

Event scheduler in C

One of my university assignments asked us to create a program using struct in order to create a simple event scheduler. This program is for a single day only, not ...
36
votes
4answers
6k views

Rainfall challenge

About a year ago when I was applying to jobs for the first time, I had an interview at a company and they posed the following problem to me, which I preceded to bomb. A year later I actually came up ...

15 30 50 per page