Sunday, November 1, 2009

Periodic table puzzle

My son has homework. The task is to try to find 50 of the elements from the periodic table in this matrix of letters, whether by row or column or diagonal, backward or forward. (DISCLAIMER: I typed the puzzle in from his handout, and may have made a mistake here or there).

AYMR-------------------------------ASSM
RNUE-------------------------------BLUE
GNTN-------------------------------EIRG
OOSI-------------------------------TTOS
NCADMIUMN----------------DEFLUORINEHLHU
AINOEOBOC----------------GHPBROMINEDAPL
ILOIJENLH----------------KLMUINEHTURCSP
MIDNZELYO----------------PMQRTSCMUVHEOH
WSAYXMDBZ----------------YDURXEUASLBLHU
LCRNURBDD----------------PENITIFGOHOIPR
EJKIORLEM----------------OENODVPRDNLQTH
KNDGARTNR----------------THHNIAISIIAAHE
CNEDSTIUHYAHEMPERBENITATSAIAOGNLUUDNIAN
INIOBIUMOCLEIDETANABELEGOSCFFEAMLMTTTLI
NUHTNEELDEULMBORONMLENNTSSISLNDLIAGHHLU
MNOBRACMISMUINITCALCIUMMUINOCRIZLTPASIM
ORMMMOUTUEIDBUPUTUNETTVERUEEOTUUHIENIUL
ESULUNGCMNNRMYMMRORNTAHTUMSIBIMNMIUULMN
GMIIIIEEAVUERMUIRTTYNTYIFIRIAIRIDIUMVVE
RUNTSECMNBMKLIUEMECHROMIUMANLTSUOXYGENM
EIAHELRNICEMNMDESENAGNAMAMPSTRONTIUMRAN
PLTINEADANBE---------------------------
PEIUGMIUARLA---------------------------
OHTMAUDRMEFD---------------------------
CMUAMUIMSOLD---------------------------


After he finished, naturally, I wrote a Python script to solve this. I won't impose on you by showing the whole listing. It is here. But there are two things worth noting. First, as before, I used this trick for transposing a matrix (consisting of a list of lists). And I found a new (one-liner) trick i didn't know for reversing a string:

>>> s = 'abcde'
>>> print s[::-1]
edcba


I've never seen this before, and a search of 6 or 7 minutes did not reveal where it is documented, but it's very easy!

Are you're wondering which elements were found? I typed in 74 to look for, as indicated below. The puzzle said that it skipped some---the ones not shown in the 18-column view (lanthanoids and actinoids). I found 72.


ALUMINUM     col fwd  10  13  ------------ALUMINUMEBLFL
ANTIMONY dia fwd 0 1 ANTIMONYZ---EDOTTOTHG----
ARGON col fwd 0 1 ARGONAIMWLEKCINMOEGREPPOC
ARSENIC col rev 26 14 ----EHLMDEEHICINESRAP----
ASTATINE row rev 12 19 CNEDSTIUHYAHEMPERBENITATSAIAOGNLUUDNIAN
BARIUM dia rev 92 8 UDUACMEMUIRAB-------D----
BERYLLIUM dia fwd 3 7 OCNIZMBERYLLIUMIME----
BISMUTH row rev 17 23 ESULUNGCMNNRMYMMRORNTAHTUMSIBIMNMIUULMN
BORON row fwd 14 14 NUHTNEELDEULMBORONMLENNTSSISLNDLIAGHHLU
BROMINE row fwd 5 29 AINOEOBOC----------------GHPBROMINEDAPL
CADMIUM row fwd 4 2 NCADMIUMN----------------DEFLUORINEHLHU
CALCIUM row fwd 15 17 MNOBRACMISMUINITCALCIUMMUINOCRIZLTPASIM
CARBON row rev 15 2 MNOBRACMISMUINITCALCIUMMUINOCRIZLTPASIM
CESIUM dia rev 106 5 ----MUISECNALSDHBESL
CHLORINE dia rev 105 12 ----AIFMEOLENIROLHCPU
CHROMIUM row fwd 19 19 RUNTSECMNBMKLIUEMECHROMIUMANLTSUOXYGENM
COBALT col fwd 28 16 ----LBURRIONOFLCOBALT----
COPPER col rev 0 20 ARGONAIMWLEKCINMOEGREPPOC
FLUORINE row fwd 4 28 NCADMIUMN----------------DEFLUORINEHLHU
FRANCIUM dia rev 13 4 IUOMUICNARFD
GALLIUM dia fwd 41 13 --------YENNGALLIUMEA-
GERMANIUM dia fwd 89 3 UMGERMANIUMDP------------
GOLD dia rev 103 20 ----GOYTRIIFOIVFAUUDLOG
HAFNIUM dia fwd 39 12 ----------OHAFNIUMIYM---
HELIUM col rev 1 19 YNNOCILISCJNNNUNRSMUILEHM
HYDROGEN dia rev 77 2 NNEGORDYH------
INDIUM dia fwd 76 1 INDIUMLLC-----
IODINE col rev 3 2 RENIDOINYNIGDOTBMLITHIUMA
IRIDIUM row fwd 18 30 GMIIIIEEAVUERMUIRTTYNTYIFIRIAIRIDIUMVVE
IRON dia rev 6 4 IIANORIMDSIRRID----
KRYPTON dia fwd 93 6 IRANEKRYPTONE------GE----
LEAD dia rev 14 8 NNMLIERDAEL
LITHIUM col fwd 3 18 RENIDOINYNIGDOTBMLITHIUMA
MAGNESIUM col rev 4 17 ----MEJZXUOASBNRMUISENGAM
MANGANESE row rev 20 16 EIAHELRNICEMNMDESENAGNAMAMPSTRONTIUMRAN
MERCURY dia fwd 25 13 YUN-IBLO----MERCURYRN----
MOLYBDENUM col fwd 7 5 ----MOLYBDENUMLMTCEMNDURM
NEON dia fwd 10 2 ENEONAUCABEE---
NICKEL col rev 0 10 ARGONAIMWLEKCINMOEGREPPOC
NIOBIUM row fwd 13 2 INIOBIUMOCLEIDETANABELEGOSCFFEAMLMTTTLI
NITROGEN dia fwd 11 2 KNITROGENCBA--
OSMIUM row rev 24 5 CMUAMUIMSOLD---------------------------
OXYGEN row fwd 19 33 RUNTSECMNBMKLIUEMECHROMIUMANLTSUOXYGENM
PALLADIUM dia rev 43 8 ------KMUIDALLAPNLVM
PHOSPHORUS col rev 37 1 SUROHPSOHPTHALLIUMVNA----
PLATINUM dia fwd 85 1 PLATINUMDCA------------
POLONIUM dia rev 107 12 ----AMRIORDMUINOLOP
POTASSIUM col fwd 25 10 ----DGKPYPOTASSIUMIMM----
RADIUM dia rev 78 1 MUIDARBBO-------
RADON col rev 2 6 MUTSANODARKDEIHOMUINATITU
RHENIUM col fwd 38 10 MEGSULPHURHENIUMLNEMN----
RUBIDIUM dia rev 91 1 MUIDIBURBNOTR------------
RUTHENIUM row rev 6 28 ILOIJENLH----------------KLMUINEHTURCSP
SCANDIUM dia fwd 102 11 ----ARTHEUSCANDIUMTEHTRE
SELENIUM dia fwd 95 1 SELENIUMTAMBI----PLPL----
SILICON col rev 1 3 YNNOCILISCJNNNUNRSMUILEHM
SILVER col fwd 36 16 SLITLACELIQAITHSILVER----
SODIUM col fwd 33 9 ----NNTUSODIUMATIIIXI----
STRONTIUM row fwd 20 28 EIAHELRNICEMNMDESENAGNAMAMPSTRONTIUMRAN
TANTALUM dia rev 110 8 ----SLIMULATNATR
TECHNETIUM dia fwd 101 16 ----NHNAVMSSIHOTECHNETIUM
TELLURIUM dia rev 96 5 OFA-MUIRULLET---YMMBU----
THALLIUM col fwd 37 11 SUROHPSOHPTHALLIUMVNA----
TIN row rev 9 28 LCRNURBDD----------------PENITIFGOHOIPR
TITANIUM col rev 2 17 MUTSANODARKDEIHOMUINATITU
TUNGSTEN dia fwd 99 9 ----SETNTUNGSTENRTNMI--BS
VANADIUM col fwd 30 11 ----OONSEIVANADIUMRSO----
XENON dia fwd 75 5 CNKNXENON----
YTTRIUM row rev 18 14 GMIIIIEEAVUERMUIRTTYNTYIFIRIAIRIDIUMVVE
ZINC dia rev 3 2 OCNIZMBERYLLIUMIME----
ZIRCONIUM row rev 15 24 MNOBRACMISMUINITCALCIUMMUINOCRIZLTPASIM
found 72 elements
tested 74 in total
not seen:
SULFUR
LUTETIUM