18 - DOOR - 100 Doors

Post Reply
Peet
Posts: 257
Joined: Tue Sep 29, 2020 12:01 am
Location: Germany

18 - DOOR - 100 Doors

Post by Peet »

There are 100 doors, all are initially closed. The status of the doors toggles in 100 passes.
At the first pass the status of all doors is changed (i.e. all doors are open now because they were all closed before).
At the second pass only every second door toggles (door 2, 4, 6 ...)
At the third pass every third door toggles (door 3, 6, 9 ...)
At the fourth pass every fourth door toggles (door 4, 8, 12 ...) etc.
At the last (100th) pass only the status of the 100th door is changed.

What state are the doors after the last pass? Which are open, which are closed?

more infos: http://rosettacode.org/wiki/100_doors

The program contains two different approaches/algorithms:
LBL A uses 100 register for the door-status of each door and opens/closes them in 100 passes.
LBL B simulate the 100 passes for each door and only needs 3 register.

Usage: XEQ "DOOR"
Display: A:PRN B:VIEW
<A> prints the status of all 100 doors on the printer (needs SIZE>=103).
<#> <B> shows the status of the doors starting with # one after an other.

Output (e.g.):
D16: 5 O (door 16 toggels 5 times open)
D23: 2 C (door 23 toggels 2 times closed)

Code: Select all

LBL "DOOR"
FIX 0
CF 29
SF 27
1		; default # for <B> 
"A:PRN B:VIEW"
PROMPT
LBL A
CLA
CLRG
2
STO 02
2
STO 01
LBL 01
1
ST+ 01
RCL 01
103
X=Y?
GTO 02
LBL 06
RCL 01
2
-
ST+ 02
RCL 02
103
X<=Y?
GTO 03
1
ST+ IND 02
GTO 06
LBL 03
2
STO 02
GTO 01
LBL 02
CLX
STO 01
LBL 04
3
STO 01
LBL 10
RCL 01
2
-
"|-  D"		; door
ARCL X
"|-: "
RCL IND 01
ARCL X
2
MOD
X#0?
"|- O"		; open
X=0?
"|- C"		; close
RCL 01
2
MOD		; print two results in one line
X=0?
PRA		; or AVIEW to test without printer
X=0?
CLA
1
ST+ 01
103
RCL 01
X#Y?
GTO 10
RTN
LBL B
LBL 00
CLRG
STO 01
2
/
INT
STO 02
LBL 05
RCL 01
RCL 02
MOD
X=0?
ISG 03
X<>Y
DSE 02
GTO 05
RCL 03
1
+
"D"		; door
ARCL 01
"|-: "
ARCL X
2
MOD
X=0?
"|- C"		; close
X#0?
"|- O"		; open
AVIEW 
PSE
1
RCL 01
+
101
X<>Y
X#Y?
GTO 00
END
Attachments
18_DOOR.raw
(188 Bytes) Downloaded 240 times
My programmable calculators - former: CBM PR100, HP41CV, HP28S, HP11C - current: HP48G(256kB), HP35S, Prime, DM41X, DM42
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: 18 - DOOR - 100 Doors

Post by Thomas Okken »

Hmm. That sounds like it doesn't require a program. Each door n is changed as many times as n has divisors, including 1 and itself. Since divisors come in pairs, d and n/d, numbers tend to have an even number of divisors, so the doors are closed as many times as they are opened, and at the end all doors are closed... except for those whose number is a perfect square, since only perfect squares have an odd number of divisors.
Peet
Posts: 257
Joined: Tue Sep 29, 2020 12:01 am
Location: Germany

Re: 18 - DOOR - 100 Doors

Post by Peet »

Thomas Okken wrote:
Fri Dec 18, 2020 12:17 pm
That sounds like it doesn't require a program.
True, it is not necessary. But the various programs that can be found usually do not depict the mathematical but simulates the practical solution. I'm sure someone somewhere in the world even built a wooden model for it. :)
My programmable calculators - former: CBM PR100, HP41CV, HP28S, HP11C - current: HP48G(256kB), HP35S, Prime, DM41X, DM42
toml_12953
Posts: 795
Joined: Wed May 03, 2017 7:46 pm
Location: Malone, NY USA

Re: 18 - DOOR - 100 Doors

Post by toml_12953 »

Peet wrote:
Fri Dec 18, 2020 1:18 pm
Thomas Okken wrote:
Fri Dec 18, 2020 12:17 pm
That sounds like it doesn't require a program.
True, it is not necessary. But the various programs that can be found usually do not depict the mathematical but simulates the practical solution. I'm sure someone somewhere in the world even built a wooden model for it. :)
In the Auriesville, NY USA there's a shrine to three martyred French missionaries. It's called Our Lady of Martyrs officially but most people call it the Church of 100 Doors. I've been there a few times and spent more times counting doors than listening to Mass. Maybe I'll go try this project down there!

https://www.dropbox.com/s/d9viby5nocv8g ... s.jpg?dl=0
Tom L

Some people call me inept but I'm as ept as anybody!
DM10L SN: 059/100
DM41X SN: 00023 (Beta)
DM41X SN: 00506 (Shipping)
DM42 SN: 00025 (Beta)
DM42 SN: 00221 (Shipping)
WP43 SN: 00025 (Prototype)
Post Reply