Highest Number Pairing Problem
This program solves a simple math problem...
Find two numbers that add up to the given number (by default is 8), such that the product multiplied by the difference produces the largest possible value.
From the command line, enter to build:
$ swift build
From the command line, enter to run:
$ swift run
$ swift run HighestNumberPairing
You will get a prompt that allows you to enter the number to use. The default is 8, if nothing is entered.
Optionally, you can add the number as a second argument:
$ swift run HighestNumberPairing 16
This runs the program with 16 as the number to use.
By default, the program displays only the best result. To also display 10 other top results (sorted high to low). You can specify the
-o to show those results.
$ swift run HighestNumberPairing --other-results 8
$ swift run HighestNumberPairing -o 8
To get help, use
$ swift run HighestNumberPairing --help
From the command line, enter to run all unit tests:
$ swift test
Tests can also be run from within Xcode.
On Linux, as of Swift 5.1, tests are auto-discoverable, but you will have enable the option for now.
$ swift test --enable-test-discovery
- Adds the new Swift ArgumentParser package.
- New recursive method to find more accurate answer
- New ability to take user input from command line or input prompt
- Collecting and displaying other results is now optional
- Added unit tests
- Revised module structure for better command line testability
- Updated syntax for Swift 5.1
NumberPairingProblemto a structure
- Ongoing tweaks