# LessThanDot

All Blogs

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

## LTD Social Sitings

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

# Collection Of Puzzles For Programmers

by SQLDenis on Mar 02, 2009 in categories Ethics & IT

Did you know that we have a nice collection of puzzles here on less than dot? Some are harder than others so there is something for everyone. You can pic any language you want, you will see that there are solutions in Ruby, Python, Visual Basic, SQL, JavaScript, C++ and other.

Here is a partial list of what we have

Friday the Thirteenths
The goal is to identify all friday the thirteenths for a given timeframe

Regular Pentagon
Given a grid co-ordinate (x,y) as the centre point of a regular pentagon, and the sum of the length of the sides, return the co-ordinates of each point as: "Top", "MidLeft", "MidRight", "BottomLeft", "BottomRight" and the distance from the centre to each of the points.

ASCII Art Shapes
Create some ASCII art in the shortest code possible

Finding Prime Numbers
Find every prime number between 0 and 1,000,000

Calculating the Fibonacci Sequence
Calculate 'X' numbers in the Fibonacci Sequence, which is essentially adding the previous 2 occurring numbers together to make the next

split a filepath
Let's say you have the following 4 items:

C:\data\old\one.jpg
C:\data\old\one.two.jpg
C:\Documents and Settings\My Music\Amazon MP3\The Doors\Gloria.mp3

You have to split this data and also show how many folders are in the path

Given a numerical input of bytes, create a function to format the output to two decimal places along with the relevant postfixes

Convert Between Roman and Arabic Numerals
Write a program to convert to (and from) roman numerals. So your program should be able to take the input of 27 and return XXVII, and take MCMLXXXI and return 1981. And of course any other values.

Find it
Given an array of 1001 elements which contains integers from 1 to 1000 inclusive. The numbers are randomly stored in the array. Only one number repeats itself
First create the array randomly and the one number randomly. But use 10 million integers plus one of course. Do this 10 times and show the times it takes to find the number and then the average time

Weekends between two dates
Write a program that will take two dates as inputs, and output the number of weekends between them.

Hello World! For Hackers
Create the most unique way of writing "Hello World" - the more fantastic, cryptic, oddball the better

Calculate the moon phase
Calculate the phase of the moon as accurately as possible.
We all know that a moon month is not as long as a normal month. It is about 29.53 days long, but that is an average and not very accurate

reverse the order of words
Given an array of characters that form a sentence, give an efficient algorithm to reverse the order of the words (not characters) in it.

Zip me up, Buttercup
Reduce the size of the text in a single transportable file. Then inflate that same file to reproduce the original string exactly (e.g. lossless compression)

Fraud Detection
The challenge is to identify falsification of data sets. Given a set of numbers of natural source (e.g. naturally occuring like credit card payments, not machine/human generated like a telephone number), the program needs to identify the probability of that data being naturally occuring vs. being falsified.

Take numbers between 1 and 100
Take numbers between 1 and 100 and do the following

if the number is a prime mark it
if the number is divisible by 5 mark it
if the number is divisible by 7 mark it
if the number is divisible by 7 and 5 mark it

A simpler calendar
Making a simple calendar, I find that all these months with a different number of days is confussing. So I would like to have a calendar with 30 days per month from now on and 12 months a year. The only problem is that It will no longer be going with the sun. The sun being a 365 day/year cycle the new calendar has 360 days/year. So I need to compensate but only by adding a 13 month at certain years. Write me a program that calculates when to add a month to keep in synch more or less

counting the money
You should give all the possible combinations to pay for the given amount of money.

knowing that you have the following currency
1 chrissiecent
2 chrissiecent
5 chrissiecent
10 chrissiecent
20 chrissiecent
50 chrissiecent
1 chrissie
2 chrissie

also give the solution with the least amount of pieces.

Beers per day
A man earns a certain amount of chrissies a month he has to pay 15% taxes and every year he has to pay 0.5% taxes more than the year before. The man's income is indexed each year by 1%. When will that man's net income be 200% of his begin income

Distance to line segment
Given the coordinates of the line segment, calculate the shortest distance to a given point. The distance that you are to calculate is represented by the red line. If the point is 'outside' the line segment, meaning, you cannot draw a perpendicular line to it, then you should return the distance from the given point to the closest end point

Keep an eye on Programmer Puzzles because every 2 weeks or so we post a new puzzle

Also check out our Google Interview Questions

81209 views
puzzles