Let’s take a certain word, change one letter in it and rearrange the letters
to get another valid word .
Denote this operation by
→.
Examples: sport
→ trips
→ shirt
or bread
→ dares
→ cards.
Find solutions fitting the following pattern:
Country I → Capital I → Country II
Capital II → Country III → Capital III
All the cities and countries above are 5-letter words.
Countries with their capitals were downloaded from Wikipeda, brought into a Spreadsheet and saved as a comma-delimited file to be perused by:
DECLARE FUNCTION except1! (a$, b$)
OPEN "cityco~1.txt" FOR INPUT AS #1
OPEN "city5.txt" FOR OUTPUT AS #2
OPEN "country5.txt" FOR OUTPUT AS #3
DO
LINE INPUT #1, l$
ix = INSTR(l$, ",")
IF ix > 5 THEN
city$ = LTRIM$(RTRIM$(LEFT$(l$, ix - 1)))
l$ = MID$(l$, ix + 1)
ix = INSTR(l$, ",")
IF ix = 0 THEN ix = LEN(l$) + 1
country$ = LTRIM$(RTRIM$(LEFT$(l$, ix - 1)))
IF LEN(city$) = 5 THEN PRINT #2, LCASE$(city$)
IF LEN(country$) = 6 THEN PRINT #3, LCASE$(MID$(country$, 2))
END IF
LOOP UNTIL EOF(1)
CLOSE
OPEN "city5.txt" FOR INPUT AS #1
OPEN "ccmatch4.txt" FOR OUTPUT AS #3
DO
INPUT #1, c$
OPEN "country5.txt" FOR INPUT AS #2
DO
INPUT #2, n$
IF except1(c$, n$) THEN PRINT #3, c$, n$
LOOP UNTIL EOF(2)
CLOSE 2
LOOP UNTIL EOF(1)
CLOSE 1
FUNCTION except1 (a$, b$)
x$ = a$: y$ = b$
FOR i = 1 TO LEN(y$)
ix = INSTR(x$, MID$(y$, i, 1))
IF ix THEN x$ = LEFT$(x$, ix - 1) + MID$(x$, ix + 1)
NEXT i
IF LEN(x$) = 1 THEN except1 = 1: EXIT FUNCTION
except1 = 0
END FUNCTION
finds this list of cities:
abuja
accra
alofi
amman
cairo
dakar
dhaka
hanoi
kabul
minsk
paris
praia
quito
rabat
seoul
sofia
tokyo
tunis
vaduz
and this list of countries:
ghana
china
egypt
syria
sudan
gabon
spain
kenya
burma
india
palau
niger
tonga
aruba
haiti
benin
yemen
chile
japan
libya
malta
nauru
and finds these correlations:
abuja aruba
hanoi china
paris syria
paris spain
rabat aruba
As Paris connects to Syria and Spain, and Aruba connects to Abuja and Rabat, the solutions are:
Syria --> Paris --> Spain
Abuja --> Aruba --> Rabat
Of course the direction in each case can be reversed.
|
Posted by Charlie
on 2015-04-20 15:28:27 |