   ## 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. • 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. The results are available in the file (79.6 kB) PentominoResults.zip.
• 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.
• 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...
• Five Array Elements - A puzzle by Charles W. Trigg. Using a 5x5 array find five array elements, no two of the same row or column, so that the sum of the five elements is as small as possible.

### Magic Cubes

• Magic Cubes 3x3x3 - Sample code that calculates all 4 magic cubes 3x3x3.
• Magic Cubes 4x4x4 - Sample code that calculates 4728 pan-triagonal self-complementary magic cubes 4x4x4. The results are available in the file (524 kB) MC444.zip.

### Rosetta Code Problems

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible. The following problems were posted on the Rosetta Code web site and solutions coded in various programming languages.
• Pascal's Triangle Puzzle - Also known as "Pyramid of Numbers". Each brick of the pyramid is the sum of the two bricks situated below it.
• Knapsack Problem - Pack a knapsack not to exceed maximum weight while maximizing the value. Multiple identical items not allowed.
• Unbounded Knapsack Problem - Pack a knapsack not to exceed maximum weight while maximizing the value. Multiple identical items allowed.

### Dell Logic Puzzles

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 number of stars shown reflects the puzzle difficulty.

### Enigma Problems

The following "Enigma" problems were published by the New Scientist magazine.

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: October 2, 2015