INGLENOOK SHUNTING PROGRAM
For an explanation of the Inglenook shunting puzzle please see this website here -
http://www.wymann.info/ShuntingPuzzles/Inglenook/inglenook-rules.html
http://www.wymann.info/ShuntingPuzzles/Inglenook/inglenook-rules.html
The following code shuffles the eight wagons and allotts them to their final destinations.
The code is written for SmallBASIC which is available on the internet as freeware.
Also the code is relatively simple and should not be a problem to convert to other BASICs or even to be rewritten to someones prefered programming language.
https://smallbasic.github.io/
code
rem INGLENOOK GOODS WAGON SHUNTING PROGRAM
rem SmallBASIC
rem Created: Alan Steelbat 01/01/2023 , Last Modified 15/11/2023
w=window()
w.setFont(1,"em",1,0)
randomise = rnd
let a=0
let r=0
dim Train(8)
dim Wagon$(8)
rem ==== read wagon data into array W$() =======
for i=1 to 8
read Q$
Wagon$(i)=Q$
next i
rem =============== Start of MAIN LOOP ==============
label RESTART
CLS
delay 300
for i= 1 to 8
Train(i)=0
next i
rem ====== put random wagons into array Train() ======
for i = 1 to 8
Repeat
a=0
r = int(rnd*8)+1
for j = 1 to 8
if Train(j)>0 and Train(j)=r then a=1
next j
Until a<>1
Train(i)=r
next i
rem ============= Display Output =================
print " GOODS WAGON SHUNTING PROGRAM"
print
print " In/Out Siding"
for i = 1 to 5
print tab(10) ; Wagon$(Train(i))
print
next i
print
print " Goods Shed"
for i = 6 to 8
print tab(10) ; Wagon$(Train(i))
print
next i
for i = 1 to 8
print
next i
input "Enter 'n' to EXIT or press Return to go again" ; Q$
if LEFT(Q$,1) = "n" then EXIT
goto RESTART
rem =========== Wagon Data Statements ==============
data "Mineral coal wagon"
data "LOCO coal wagon"
data "Grey box van"
data "Brown box van"
data "Meat/Fish van"
data "low sided steel open"
data "7 plank open wagon"
data "Oil tank wagon"
rem ---------END OF PROGRAM STATEMENTS -----------
rem SmallBASIC
rem Created: Alan Steelbat 01/01/2023 , Last Modified 15/11/2023
w=window()
w.setFont(1,"em",1,0)
randomise = rnd
let a=0
let r=0
dim Train(8)
dim Wagon$(8)
rem ==== read wagon data into array W$() =======
for i=1 to 8
read Q$
Wagon$(i)=Q$
next i
rem =============== Start of MAIN LOOP ==============
label RESTART
CLS
delay 300
for i= 1 to 8
Train(i)=0
next i
rem ====== put random wagons into array Train() ======
for i = 1 to 8
Repeat
a=0
r = int(rnd*8)+1
for j = 1 to 8
if Train(j)>0 and Train(j)=r then a=1
next j
Until a<>1
Train(i)=r
next i
rem ============= Display Output =================
print " GOODS WAGON SHUNTING PROGRAM"
print " In/Out Siding"
for i = 1 to 5
print tab(10) ; Wagon$(Train(i))
next i
print " Goods Shed"
for i = 6 to 8
print tab(10) ; Wagon$(Train(i))
next i
for i = 1 to 8
next i
input "Enter 'n' to EXIT or press Return to go again" ; Q$
if LEFT(Q$,1) = "n" then EXIT
goto RESTART
rem =========== Wagon Data Statements ==============
data "Mineral coal wagon"
data "LOCO coal wagon"
data "Grey box van"
data "Brown box van"
data "Meat/Fish van"
data "low sided steel open"
data "7 plank open wagon"
data "Oil tank wagon"
rem ---------END OF PROGRAM STATEMENTS -----------