# DelphiForFun Challenges

The DelphiForFun website has a huge number of problems together with solutions, usually as form-based applications. We have selected some of these in the table below and placed them in categories. Within each category, the earlier examples are the ones we consider to be most straightforward. Follow the links to see the sources of the problems and an explanation of the method(s) of solution chosen by a very experienced Delphi programmer. You can learn a lot by studying the downloadable code and modifying it. Indeed, many of the web pages contain suggestions for enhancements.

Keen students will learn a lot from DelphiForFun, but may find some of the content daunting at first. We endeavour to help you to benefit from it. Many solutions employ a "brute-force" approach whereby all permutations of a list are generated by the SEPA algorithm and tested to find out if they match the targeted criteria. We begin with a demonstration of the algorithm on the following page.

The following terminology is relevant.

• A quotient is the result of division.
• A palindromic number is one that reads the same forward and backward.
• A combination is a way of selecting several objects out of a larger group, where (unlike a permutation) order does not matter.
• A permutation is a possible arrangement of a group of objects.
• A word square is a square letter grid in which the rows are words and the same words also occur if read vertically.
Integers for Fun
T-Shirt #2 Find the smallest 3 digit number equal to the sum of its digits cubed.
T-Shirt #3 Find the only known non-palindromic number whose cube is a palindrome.
T-Shirt #4 Find the smallest 3-digit prime number abc such that abc + cba is prime.
T-Shirt #5 Find the smallest 3-digit prime number abc such that cba is a different prime.
T-Shirt #6 Find the only integer equal to the sum of the 6th powers of its digits.
T-Shirt #7 Find three prime 3-digit numbers that contain all of the digits 1 through 9 and have a 3-digit sum.
Reversed Number Find a six digit number which, when multiplied by an integer between 2 and 9 inclusive, gives the original number with its digits reversed.
Rotating Grid Put all the digits 1-9 in a 3x3 grid such that the first row added to the second row equals the third row in the original grid and in the grid rotated clockwise through 90 degrees.
Squares and Cubes Find the smallest integer that can be formed as the sum of two squares in two different ways. Follow the link to see four other problems involving squares and cubes.
Most Divisors Which positive 3-digit integer has the most positive integer divisors?
Pandigital Fractions If each of the first 9 letters represents a different digit from 1 to 9, find the smallest integer ABCDEFGHI for which A/BC + D/EF + G/HI = 1
Palindromic Sums If any two digit number is reversed and added to itself, and the process repeated long enough, a palindromic number will result. Find (1) which two-digit number requires the most steps before a palindromic sum is reached and (2) this maximum number of steps.
Remainder of 1 Find the smallest multiple of 13 which leaves a remainder of 1 when divided by each of the numbers 2 through 12.
Recurring Quotient For all 5 digit numbers that divide evenly by the sum of their digits, what quotient occurs most often?
The 9321 Problem Complete the equation X = 9 op 3 op 2 op 1 by filling in the "op" operators +, -, * or / to produce X values of 0 through 9 in as many ways as possible.
Statistics
Six of a Kind What is the probability that six rolled dice will all show the same number on top?
How many Golf Courses? Find the number of possible combinations of (par 3, 4, or 5) holes in a championship 18 hole golf course with a total par for the course of 72 strokes.
Car and Goats Game Write a program to simulate the Monty Hall problem.
Circular Reasoning Find the probability that three points placed randomly on the circumference of a circle will lie within the same semicircle.
Centuries On Sunday Calculate the probability that a century begins on a Sunday.
"Physics World" simulation
Bouncing Ball Enable the user to drop a ball and watch it bounce.
Cannon Balls Build on the bouncing ball program by adding some horizontal movement to the ball, drawing a primitive cannon that you can aim, a target that can be moved and an adjustable powder charge to give the initial push to the ball.
Simple Cart Represent a simple gravity driven cart that knows how to accelerate under the influence of gravity and has some rolling friction that will cause it to coast to a stop eventually.
Spring Mass Model the actions of a coiled spring with a weight hanging from it when it is given a push or stretched and released.
Pendulums, Simple and otherwise Model the motion of three types of pendulum: Simple, Double, and Forced.
Catapult Simulator Simulate "cup" type catapults with tensional or torsional driving forces and user-specified design parameters.
Roller Coaster Simulation Simulate a roller coaster, enabling the user to set cart and cart train properties and simulation parameters.
Molecules Simulate random molecular motion.
Solar System (very challenging)
Moon Phase Dates Calculate the dates and times of new and full moons for any given start date and number of months.
Where's my Shadow? Display the shadow cast when sun is at a given azimuth and altitude.
Solar Position Calculate the time and location of sunrise and sunset for any location on earth as well as the sun's location for any date and time.
Astronomy Demo Calculate, for example, the position of the sun, moon and the planets for any given date and time.
Letter Grids
No 3 X's In a Row Place 6 X's on a noughts and crosses grid such that there are not 3 X's in a row horizontally, vertically or diagonally.
Word Grid Find the word shown in the partially filled grid (on the linked web page) which starts in one corner and circles the board to end in the centre square. (This requires the use of a dictionary).
Word Grid - 3 Letter Words Insert a 6 letter word into the top row of the 6x3 grid (shown on the linked web page) to form 6 three letter words in the vertical columns. (This requires the use of a dictionary).
Find hidden words (formed by moving vertically, horizontally or diagonally from letter to letter, without revisiting any letter) in a random grid. (This requires the use of a dictionary).
Crossword Generator Randomly generate a crossword puzzle grid from a given list of words.
Word Squares Create word squares and (even more challenging) word square games. (These require the use of a dictionary).
Simulation of physical game/puzzle
Towers of Hanoi Move an ordered stack of differently-sized disks one disk at a time from one of three pegs to another without resting a disk on a smaller one.
Write a program to play NIM (where and two players take turns removing 1, 2 or 3 items at each turn from a pile and the player who takes the last item loses).
Connect Four #1 Connect Four without computer play
Connect Four #2 Connect Four with computer play
Peg Solitaire Game Remove pegs by jumping them with another peg in any of the 4 major directions until a single peg remains in the centre hole.
Checkers A basic game of draughts allowing human versus human play by using the mouse to drag draughts to valid destination squares.
Chess PGN Player Enable the visual replay of Portable Game Notation files recording the moves of chess games.
15 Puzzle #1 Arrange the jumbled fifteen numbered tiles in a 4 by 4 grid into ascending order by sliding them one at a time into the vacant slot.
Sliding Coins Puzzle Sort an alternating linear arrangement of 3 dimes and 2 quarters by moving adjacent dime/quarter pairs.
Game Of Go Two opponents take turns placing black and white stones on a square board, aiming to capture opponent's stones by surrounding them.
Situation problem
Jumping Frogs The action takes place on a line of seven lily pads to support the frogs with the centre one initially unoccupied and two groups of three frogs facing it. A frog can move one space forward into the empty pad or jump forward over one frog to land on the empty pad. Plan the actions necessary for the groups to exchange places.
River Crossing Puzzle Enable the farmer to get the fox, duck and corn across the river intact.
Missionaries and Cannibals Plan the crossings necessary to get three cannibals and three missionaries across the river in good condition in a boat that holds two.
The Castle Escape Plan the escape of an elderly queen, her daughter, and little son from the top of a castle by means of two baskets suspended from a rope hanging over a pulley. Follow the link for the weights of the escapees and the cannonball that can be used as a counterbalance.
Shape Manipulation
TileFit Tiling Program Create random tilings of a rectangular area from a defined set of tiles.
Robot Rooms (Exact rectangle covering) Exactly cover a rectangular area with random rectangles meeting certain size and shape constraints.
Dudeney's_Dissection Print the set of polygons that you can rearrange into either a square or an equilateral triangle.
Tangram 1 Display seven pieces cut from a square (five triangles, a square and a parallelogram) object and enable the user to drag and rotate them to reform the square.
FlatLand Piano Movers Determine if a given piano will fit around a corner in a corridor.
Delphi Techniques
Stopping loops Enable the user to terminate early a long-running loop.
Simple Drag Drop Enable the user to drag and drop a coloured TShape to change the colour of the target.
Memo Clicks Recognize user clicks on a TMemo and determine the line number and the position within the line where the click occurred.
StringGrids and Bitmaps Change a cell's colour or contents on mouseover and enable the user to "paint" an image into the cells.
PrintGrid - StringGrid Printing Print a string grid starting at a specified location and within a specified width and height.
Volume Control Demo Use Delphi code to change the master volume control (normally set via the taskbar).
Programming - a skill for life!

Plenty of suggestions to start you off