PARTITN.BAS
HMAGIC.BAS
December 1998 by Marc Kummel aka Treebeard.
Contact mkummel@rain.org, http://www.rain.org/~mkummel/
What are PARTITN.BAS and HMAGIC.BAS?
-------------------------------------
These are two small Basic programs I wrote so that I could answer a stumper
on my Stumper Page at :
Holiday Magic
18 December 1998
Put the numbers 1 to 12 on the holiday stars, trees, and wreaths
shown below, with one number in each design, so they add up to the
same sum in each of these seven ways:
* each of the two center columns (tree-wreaths-tree)
* each of the two center rows (star-wreaths-star)
* the four stars together
* the four trees together
* the four wreaths together
The magic sum must be 26. (Why?) How many different ways are there
to solve this stumper?
__/\__ __/\__
\ / \ /
|/\| |/\|
_...._ _...._
/\ .::o:::::. .::o:::::. /\
//\\ .:::'''':o:. .:::'''':o:. //\\
///\\\ :o:_ _::: :o:_ _::: ///\\\
////\\\\ `:(_>()<_):' `:(_>()<_):' ////\\\\
...##... `'//\\'' `'//\\'' ...##...
// \\ // \\
_...._ _...._
/\ .::o:::::. .::o:::::. /\
//\\ .:::'''':o:. .:::'''':o:. //\\
///\\\ :o:_ _::: :o:_ _::: ///\\\
////\\\\ `:(_>()<_):' `:(_>()<_):' ////\\\\
...##... `'//\\'' `'//\\'' ...##...
// \\ // \\
__/\__ __/\__
\ / \ /
|/\| |/\|
PARTITN.BAS is a snippet to solve a problem that arises with this stumper
and other magic squares:
What are all the ways in which m different numbers (p or less)
can add up to n, without regard to order?
Partitioning is a bit like factoring in that it decomposes a number, but it
uses addition rather than multiplication. This was a fun programming
challenge that uses a recursive function.
HMAGIC actually solves the stumper. It doesn't print all the 13,952
solutions, but it finds all the 75 families of solutions in 31 groups.
This program is strictly brute force! I kept trying shortcuts and missing
solutions. It uses data from the PARTITN.BAS program that figures additive
partitions. See HMAGIC.TXT for more info.
Using PARTITN.BAS and HMAGIC.BAS:
----------------------------------
These are simple DOS programs. Run them in DOS, or a DOS session in
Windows. It's best to run them within QBasic or QB4.5 since the only way
to change parameters is to change the code. HMAGIC just does one thing.
But PARTITN.BAS can partition any number into any number of parts. Change
the parameters n%, m%, and p% to test different numbers.
The Files:
-----------
I wrote these programs to solve a stumper. You'll have to study the source
code for more info. I wrote them using MS Basic PDS v7.10, but they run
fine in QBasic or Quick Basic.
PARTITN.BAS BASIC source code to partition a number
HMAGIC.BAS BASIC source code to solve stars/trees/wreaths stumper
HMAGIC.TXT Analysis of the stumper
PARTDAT.DAT All the ways to add 4 numbers <= 12 and get 26
HMAGIC.DAT All the answers in 75 families and 31 groups
README.TXT This file
TBVAULT.TXT Treebeard's Basic Vault info
Conditions:
------------
This program and source code are yours to use and modify as you will, but
they are offered as freeware with no warranty whatsoever. Give me credit,
but do not distribute any changes under my name, or attribute such changes
to me in any way. You're on your own!
If you find this program or code useful, then let me know what you do with
it, as a courtesy to a fellow programmer who still hacks for fun and glory.
Any suggestions or comments will be much appreciated.
Send comments and fixes to:
Marc Kummel aka Treebeard
mkummel@rain.org
http://www.rain.org/~mkummel/
http://www.treebeard.org/
For more interesting Basic software with source code, check out Treebeard's
Basic Vault at