Oct
31
Number Series #1
Filed Under Puzzles | 2 Comments
The Problem
What are the next two numbers in this series? This is a purely arithmetic series.
30, 33, 42, 50, 55, 80, 88, 152, 162, 174, ?, ?
The Solution
202, 206. To figure out the next number in the series multiply each of the non-zero digits of the previous number and add them to that previous number.
Oct
31
String Permutations
Filed Under Programming | Leave a Comment
The Problem
Write a function to print all of the permutations of a string.
The Solution
See: StringUtil.permute(String)
Oct
31
AtoI
Filed Under Programming | Leave a Comment
The Problem
Write a function that takes in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value.
The Solution
Oct
31
Quicksort
Filed Under Programming | Leave a Comment
The Problem
How would you write quicksort?
The Solution
See: RecursiveQuickSort.java and IterativeQuickSort.java
Oct
31
All Files Recursively
Filed Under Programming | Leave a Comment
The Problem
Implement an algorithm to print out all files below a given root node.
The Solution
See: FileProcessorRecursive.java
Oct
31
Bridge Crossing
Filed Under Puzzles | Leave a Comment
The Problem
There are 4 women who want to cross a bridge. They all begin on the same side. You have 17 minutes to get all of them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. The flashlight must be walked back and forth, it cannot be thrown, etc. Each woman walks at a different speed. A pair must walk together at the rate of the slower woman’s pace.
- Woman 1: 1 minute to cross
- Woman 2: 2 minutes to cross
- Woman 3: 5 minutes to cross
- Woman 4: 10 minutes to cross
For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes? Now, what’s the other way?
The Solution
Let’s think about this. How many different ways can we add the numbers 1, 2, 5 and 10 together to get 17? There’s only one combination that works: 10, 2, 2, 2, 1. This tells us a few things.First, ten and five cross exactly once and they cross together (ten “masks” the five because ten is larger/slower). We also know that the exercise will take place in five steps. We know that two crosses three times and one crosses at least once (because it could cross with two and therefore be “masked”). I use the term masking, but it’s kinda like big-O notation in a way.
That all said, here are the two solutions.
Send over women one and two. Send back woman two. Woman two sends women three and four across the bridge together. Woman one then returns for woman two. Women one and two then cross back over together. Total time == 10 + 2 + 2 + 2 + 1 == 17 minutes.
Send over women one and two. Send back woman one. Woman one sends women three and four across the bridge together. Woman two then returns for woman one. Women one and two then cross back over together. Total time == 10 + 2 + 2 + 2 + 1 == 17 minutes.
Oct
31
Four Jars of Pills
Filed Under Puzzles | Leave a Comment
The Problem
You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just one measurement?
The Solution
We have to assume a unit weight of one for uncontaminated pills to solve this. Take one pill from the first jar, two pills from the second, three pills from the third and four pills from the fourth. You now have ten pills. Put all ten pills on a scale. Subtract ten from the weight and you have the number of the jar with poison pills.
Oct
31
The Problem
You have two jars, 50 red marbles and 50 blue marbles. A jar will be picked at random, and then a marble will be picked from the jar. Placing all of the marbles in the jars, how can you maximize the chances of a red marble being picked? What are the exact odds of getting a red marble using your scheme?
The Solution
Fill the bottom half of each jar with blue marbles. Then fill the top half of each jar with red marbles. You then have a 100% chance of picking a red marble.
Oct
30
San Francisco Scramble
Filed Under Puzzles | Leave a Comment
The Problem
The San Francisco Chronicle has a word game where all the letters are scrambled up and you have to figure out what the word is. Imagine that a scrambled word is 5 characters long:
- How many possible solutions are there?
- What if we know which 5 letters are being used?
- Develop an algorithm to solve the word.
The Solution
This is a fantastic way to phrase the question. There are 265 solutions (each letter can be one of 26 possible values). If we know which five letters are being used there are 55 possible solutions.
Oct
30
Rope Burns
Filed Under Puzzles | Leave a Comment
The Problem
A rope burns non-uniformly for exactly one hour. How do you measure 45 minutes, given two such ropes?
The Solution
Let’s call the ropes A and B. Light rope A at one end and rope B at both ends. B will burn in exactly 1/2 hour. When B burns out light the unlit end of rope A. Rope A will burn out 15 minutes later. Total elapsed time, 45 minutes.