FormulaOne Sample Source Code
This page contains an assorted mix of Formula
One sample source codes, listed in no particular order.
- Queens -
Generalized N-queens problem.
Place N queens on a chessboard NxN so that the queens don't attack each
other.
- Knight Tour - Another
chessboard related problem: Move the knight on the chessboard so it visits all
places exactly once.
- Einstein's Puzzle -
The almost compulsory logic puzzle known both as Einstein's puzzle or Five
Houses puzzle can be found here.
- Cannibals - Solve how to transport
missionaries without being eaten by cannibals.
- The Coconuts Puzzle
(a.k.a. The Monkey and the Coconuts) - Martin Gardner says that this is
"probably the most worked on and least often solved" algebraic puzzle.
- Dividing The Spoils - Simple problem by Sam Loyd.
- Professor Schuh - An old arithmetic problem given in the book of puzzles by
Professor F. Schuh.
- Sudoku, SudokuGUI - Sudoku a.k.a. Euler's Magic Squares. Finds all solutions of even the most difficult Sudoku puzzles.
Extremely simple source code demonstrating the advantages of declarative constraint logic programming. The sample code solves
9x9 square puzzles, but can be easily modified for other dimensions.
Standalone Sudoku solver with a GUI interface can be downloaded using this link:
SudokuGUI (revised July 1, 2005).
- FourWordGUI - Solve a FourWord puzzle. Finds all solutions.
Simple source code demonstrating how to use Graphical User Interface (GUI) using external modules.
Standalone FourWord Puzzle Solver with a GUI interface can be downloaded using this link:
FourWordF1Setup. The complete source code, including a fairly comprehensive list of
English four letter words can be downloaded here..
Some more source code samples:
- Hudred Fowls Problem - Solve an old Chinese problem.
- Factorial - See the result of Factorial(100000) here
- Crypto Words - Simple code to solve some well known alphametics.
- Alphametics - Generalized code to solve any alphametic.
- Narcissistic Numbers - Also known as Armstrong numbers or perfect digital invariants.
- Tank Tour - One of Clif Pickover's Extreme Challenges.
- Czech Logical Labyrinth - A problem posted at the 2nd World Puzzle Championship.
- Apocalyptical Numbers - Another one of Clifford A. Pickover's problems.
- FourWord - Solve a FourWord puzzle, demonstrates how to use index files. Also create a database of English four letter words.
- Dean Clark's Problem
(Clock Triplets Problem). This problem was discussed in Dr. Dobbs's Journal, May 2004 in an article by Timothy Rolfe.
- Fibonacci Numbers - Simple program to calculate huge numbers in reasonable time.
- Anagram - Simple program to find word anagrams. This program demonstrates how to create
and search a simple indexed relational database.
- Anagram123 - A more sophisticated program to find one, two and three word ASCII anagrams. This program
requires a list of reference words, which can be found in this file (2630kB): AllAnagramWords.zip.
- Pentomino - Fill rectangles with 12 pentomino pieces.
- Nine Cards Puzzle - One of the "nifty" assignments as listed at http://nifty.stanford.edu/2003/backtracking.
Arrange nine squares so that the edges that touch each add to zero.
- Ultra Super Magic Squares 5x5 - Sample code that calculates all 16 ultra super magic squares 5x5.
- The Riding Stable Puzzle - A puzzle popular in Prolog CS assignments. Six kids ride six horses.
Solve which kid rides which horse, the ages of the kids and the stall number of each horse...
- Benjamin Franklin's Magic Squares 8x8 -
In 2006 in the article published online by the Proceedings of the Royal Society
"Enumerating the bent diagonal squares of Dr Benjamin Franklin FRS"
by Daniel Schindel, Matthew Rempel and Peter Loly the authors showed there are 1,105,920 variations of Benjamin Franklin's 8x8 magic square.
This F1 program calculates all 1,105,920 Benjamin Franklin's magic squares 8x8. The results are available in the
file (25241 kB) FRANKLIN8X8.zip.
The following word puzzles were copied from Doug Edmund's web page
Learn Constraint Logic Programming With Logic Puzzles.
This page offers a nice introduction to solving logic puzzles and contains dozens of various word puzzles
ranging from simple to difficult with corresponding solutions programmed in ECLiPSe and B-Prolog.
By following the links below you can find some of these puzzles solved using Formula One.
These puzzles present a unique opportunity to compare syntax of Formula One, B-Prolog and ECLiPSe.
The sample programs were converted into HTML format by F1toHTML.
If you would like to submit sample source code, contact support@f1compiler.com.
Last updated: August 19, 2007