Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Basil Jet <basil@spamspamspam.com> |
|---|---|
| Newsgroups | sci.math |
| Subject | Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! |
| Date | 2020-10-13 00:33 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <rm2p3q$vso$1@dont-email.me> (permalink) |
| References | (3 earlier) <87tuuz6sk5.fsf@bsb.me.uk> <rm2ik4$o92$1@dont-email.me> <87imbf6qs2.fsf@bsb.me.uk> <rm2m4r$g20$1@dont-email.me> <87d01n6o7o.fsf@bsb.me.uk> |
On 13/10/2020 00:04, Ben Bacarisse wrote:
> Basil Jet <basil@spamspamspam.com> writes:
>
>> On 12/10/2020 23:08, Ben Bacarisse wrote:
> <cut>
>>> I look forward to seeing your solution. I'll be upset if it is as
>>> simple as mine since, it clearly generates shorter solutions.
>>
>> There is a 4 line function that moves a disc and prints it, and a 12
>> line recursive function which does nothing but call itself, call the
>> other function and perform various "if.. else" statements.
>
> Sounds very neat. I look forward to seeing it. Mine does not actually
> move anything. All it does is print the moves required.
>
It's in Swift, but there's nothing non-standard in it, apart form the
explanation marks and underscores, which can be ignored. The towers are
numbered from 0 to 2, instead of 1 to 3.
//solve partial Tower Of Hanoi.
var towers = [[20, 18, 15, 12, 11, 9, 5, 4, 2],
[17, 14, 13, 10, 3],
[19, 16, 8, 7, 6, 1]]
var moveCount = 0
func moveOne( _ source:Int, _ target:Int)
{
let mover = towers[source].removeLast()
//debug test
if towers[target].count > 0 && mover >= towers[target].last!
{
print("panic")
}
towers[target].append(mover)
moveCount += 1
print (" \(mover) from \(source) to \(target) : count = \(moveCount)")
}
func recursively(_ base:Int, _ source:Int, _ target:Int)
{
if base == 1
{
if source != target
{
moveOne(source, target)
}
return
}
let childTower = towers[1].contains(base - 1) ? 1 :
(towers[2].contains(base - 1) ? 2 : 0)
if source == target
{
recursively(base - 1, childTower, target)
}
else
{
let intermediateTower = 3 - (source + target)
recursively(base - 1, childTower, intermediateTower)
moveOne(source, target)
recursively(base - 1, intermediateTower, target)
}
}
recursively(20, 0, 2)
--
Basil Jet recently enjoyed listening to
Care - Diamonds And Emeralds
Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
$500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 05:26 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Basil Jet <basil@spamspamspam.com> - 2020-10-12 14:50 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 12:07 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 15:30 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 15:31 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 15:41 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 16:22 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 16:27 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 16:36 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 16:37 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 16:46 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 17:49 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 17:50 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 17:52 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 17:53 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:02 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:05 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Sergio <invalid@invalid.com> - 2020-10-12 20:05 -0500
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:20 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 18:22 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:24 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:29 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 18:49 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Sergio <invalid@invalid.com> - 2020-10-12 22:50 -0500
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 21:25 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 16:26 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 16:38 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Peter <peterxpercival@hotmail.com> - 2020-10-13 01:47 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-12 21:01 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 13:12 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Basil Jet <basil@spamspamspam.com> - 2020-10-12 21:24 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Peter <peterxpercival@hotmail.com> - 2020-10-12 21:48 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 13:57 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-12 22:49 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Sergio <invalid@invalid.com> - 2020-10-12 15:25 -0500
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-12 22:30 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Basil Jet <basil@spamspamspam.com> - 2020-10-12 22:42 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-12 23:08 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Dario Alpern <darioalpern@gmail.com> - 2020-10-12 15:23 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-13 00:06 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 16:25 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-13 01:24 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-10-12 17:54 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Dario Alpern <darioalpern@gmail.com> - 2020-10-12 17:29 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Basil Jet <basil@spamspamspam.com> - 2020-10-12 23:42 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-13 00:04 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Basil Jet <basil@spamspamspam.com> - 2020-10-13 00:33 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Graham Cooper <grahamcooper7@gmail.com> - 2020-10-12 16:40 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-13 01:06 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-10-13 01:26 +0100
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Archimedes Plutonium <plutonium.archimedes@gmail.com> - 2020-10-12 13:58 -0700
Re: $500 MATHS CHALLENGE ..... just solve this TOWERS OF HANOI ! Dario Alpern <darioalpern@gmail.com> - 2020-10-12 14:33 -0700
csiph-web