challenge

Is there a way to split strings with String.split() and include the delimiters?

I'm trying to split a string with all non-alphanumeric characters as delimiters yet Java's String.split() method discards the delimiter characters from the resulting array. Is there a way to split a string like the "\W" regex pattern does, yet keep the delimiters? ...

Puzzle: Find the most common entry in an array

You are given a 32-bit unsigned integer array with length up to 232, with the property that more than half of the entries in the array are equal to N, for some 32-bit unsigned integer N. Find N looking at each number in the array only once and using at most 2 kB of memory. Your solution must be deterministic, and guaranteed to find N. ...

Sort numbers by sum algorithm

Hello all, I have a language-agnostic question about an algorithm. This comes from a (probably simple) programming challenge I read. The problem is, I'm too stupid to figure it out, and curious enough that it is bugging me. The goal is to sort a list of integers to ascending order by swapping the positions of numbers in the list. Each ...

How do I get a JEditorPane to highlight the full width of a line (not just the text)?

I'm trying to get a JEditorPane to highlight the full width of a displayed line. All the examples I've tried only highlight the textual content. For example if I have content such as this: --------------------------------- |Here is some text | |some more text | --------------------------------- withi...

Enumerate or list all variables in a program of [your favorite language here]

A friend asked me last week how to enumerate or list all variables within a program/function/etc. for the purposes of debugging (essentially getting a snapshot of everything so you can see what variables are set to, or if they are set at all). I looked around a bit and found a relatively good way for Python: #!/usr/bin/python ...

Designing a process

I challenge you :) I have a process that someone already implemented. I will try to describe the requirements, and I was hoping I could get some input to the "best way" to do this. It's for a financial institution. I have a routing framework that will allow me to recieve files and send requests to other systems. I have a database I ...

Favorite Online Judge Challenge

For years I have visited the UVa Online Judge site to practice programming skills and just recently ( thanks to this site ) discovered the Sphere Online Judge site. I am interested to know which challenges from these sites folks here found the most interesting, difficult, satisfying, perplexing, or amusing. ...

Challenge: quickly populate the fields of a decorator class

Let's assume that we have a Model with several properties on it and we want to create a decorator class of this model to enhance it with some extra properties. Now we want to create a new instance of the DecoratedModel populated with all the property values of Model, perhaps using a constructor with Model as a parameter: public class De...

Lua Challenge: Can you improve the fannkuch implementation's performance?

Lua is currently the fastest scripting language out there, and its not so much slower than C/C++ for some sort of programs (on par when doing pidgits 1:1), however Lua scores really bad in a few benchmarks against C/C++. One of those is the fannkuch test (Indexed-access to tiny integer-sequence), where it scores a horrible 1:148 -- The...

Lua Challenge: Can you improve the mandelbrot implementation’s performance?

Status: So far the best answer's program executes in 33% of the time of the original program! But there is probably still other ways to optimize it. Lua is currently the fastest scripting language out there, however Lua scores really bad in a few benchmarks against C/C++. One of those is the mandelbrot test (Generate Mandelbrot set p...

Lua Challenge: Can you improve the spectral-norm implementation’s performance?

Lua is currently the fastest scripting language out there, and its not so much slower than C/C++ for some sort of programs (on par when doing pidgits 1:1), however Lua scores really bad in a few benchmarks against C/C++. One of those is the spectral-norm test (Eigenvalue using the power method N=5,500 ), where it scores a horrible 1:148...

Good Programming Projects/Assignments for Students

I remember when I took my first programming class in the 11th grade in high school. The course was called AP Computer Science. Anyway, the teacher had some very cool and challenging assignments to help us learn. One of which was a 2D fish tank simulation. The fish in the tank had a sex and other characteristics. Fish were born of other ...

What's the most insidious way to pose this problem?

My best shot so far: A delivery vehicle needs to make a series of deliveries (d1,d2,...dn), and can do so in any order--in other words, all the possible permutations of the set D = {d1,d2,...dn} are valid solutions--but the particular solution needs to be determined before it leaves the base station at one end of the route (imagine t...

Factorial in C without conditionals, loops and arithmetic operators

How can I find the factorial of a number (from 1 to 10) in C, without using: loop statements like for, while, and do while; conditional operators like if and case; and arithmetic operators like + , − , * , % , /, ++, −−? FYI: I found this question in C aptitude. ...

Programming challenge: can you code a hello world program as a Palindrome?

So the puzzle is to write a hello world program in your language of choice, where the program's source file as a string has to be a palindrome. To be clear, the output has to be exactly "Hello, World". Edit: Well, with comments it seems trivial (not that I thought of it myself of course [sigh].. hat tip to cobbal). So new rule: no...

Patterns of set bits in a byte

Joel mentioned counting the number of set bits in a byte as a programming question in his Guerrilla Guide to Interviewing, and talked of a way to take advantage of patterns that occur in the lookup table. I wrote an article about it awhile back after I found the pattern. To summarize: Number of bits set in a byte in 16x16 0 1 1 2...

What's wrong with this algorithm?

This is an abstracted form of the bug that led me into the code that formed the basis of my prior question. It's obvious once you see it, but several professional programmers familiar with the original problem and original language looked over the code and overlooked the bug before we caught it (admittedly, in its native environment it ...

Where can I find small but fun challenges? (Project Euler for the weak)

Duplicates: What are your programming exercises? Where can you find fun/educational programming challenges? Algorithm Questions Website Web site for Some Good Programming Puzzles? Sometimes I like programming a self-contained, "small" problem just for leisure and fun. Project Euler's problems in this regard are to big and need to ...

Eric Lippert's challenge "comma-quibbling", best answer?

I wanted to bring this challenege to the attention of the stackoverflow community. The original problem and answers are here. BTW, if you did not follow it before, you should try to read Eric's blog, it is pure wisdom. Summary: Write a function that takes a non-null IEnumerable and returns a string with the following characteristics: ...

What is the most difficult /challenging regular expression you have ever written ?

Whether Regex use with C#, VB.NET, Perl or any language. So, regardless of the language you use, share with us one or two of your challenging regular expression. ...