Coding Conundrums Evolved 3: Fiddly Fuel
This post is part of a biweekly series of programming problems, targeted at those learning to program using C# at University. The problems will vary in difficulty - some will be rather easy, and some will be quite challenging! Don't worry if you can't solve a problem just yet - come back to it in a few months and it'll seem a lot easier than it did before.
(Above: Some 15 RS-25 rocket engines at NASA. Source: NASA Image and Video Library)
Get ready for 3rd episode of Coding Conundrums Evolved! This time, you've been asked to write some software for a brand new ftl engine.
First though, the password to the last solution is zirros
.
It's the year 2252, and the engineers at the Hazuva spacecraft dry dock orbiting the ocean world Eiriodin are busily working away on putting the finishing touches to a brand new elligon class starship. Capable of FTL travel like no other craft before it, the new ship (dubbed the Lilai by the engineers) will be able to take its crew on an unforgettable journey across the stars.
There's a problem though. The Lilai has a brand new engine that was designed from scratch with a quadrilateral fuel regulation valve. As a result, the standard linear fuel balancing agent on the engine's control computer needs to be completely rewritten! Upon hearing the news, Chief Engineer Nebrilla has hired you to do the job.
The engine in question handles fuel through a grid of reactor cells. Oddly enough, the fuel in the reactor cells must be arranged in ratios such that they form a 5x5 magic square.
17 | 24 | 1 | 8 | 15 |
23 | 5 | 7 | 14 | 16 |
4 | 6 | 13 | 20 | 22 |
10 | 12 | 19 | 21 | 3 |
11 | 18 | 25 | 2 | 9 |
(Above: An example magic square.)
Write a program that outputs a 5x5 magic square.
Helpful Hints
- The Siamese method can be used to programatically generate a magic square.
- Read the description of the algorithm carefully and make sure you understand it before writing any code.
- Follow the algorithm through on paper first.
- You may want to take a look at using a 2D array to store information about your magic square.
- I've written a magic square validator so that you can test your implementation.
- Use it like this on Windows:
type MagicSquare.txt | ./MagicSquareValidator.exe [Order] [MagicNumber]
- ...or this on Linux:
cat MagicSquare.txt | mono ./MagicSquareValidator.exe [Order] [MagicNumber]
- Use it like this on Windows:
Challenge
The new engine design tested in the Lilai was so successful that a second ship, the Iveinya, is going to be retrofitted with a modified version of the engine. This new modified engine takes a 3x3 fuel matrix, which, surprisingly enough, also has to take fuel in ratios that form a magic square.
Since you wrote the control program for the original engine, you've been drafted in to update your program to work with the new engine.
Adjust your program so that it supports generating magic squares of any size.
My solution to this puzzle is here - the password to the archive will be released in the next post.
Find the last post here: Binary Biomass