From 092019121ad5ef6f82cd8fe7bf6ee143fce9648d Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sat, 11 Feb 2017 11:34:04 +0700 Subject: Add /r/dailyprogrammer Challenge #302 [Easy] --- daily/302easy/README.md | 155 +++++++++++++++++++++++++++++++++++++++++++++++ daily/302easy/ptspell.py | 86 ++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) create mode 100644 daily/302easy/README.md create mode 100755 daily/302easy/ptspell.py (limited to 'daily') diff --git a/daily/302easy/README.md b/daily/302easy/README.md new file mode 100644 index 0000000..6c0adf4 --- /dev/null +++ b/daily/302easy/README.md @@ -0,0 +1,155 @@ +# [[2017-02-06] Challenge #302 [Easy] Spelling with Chemistry](https://www.reddit.com/r/dailyprogrammer/comments/5seexn/20170206_challenge_302_easy_spelling_with/) + +## Description + +The [IUPAC Periodic Table of the Elements](https://iupac.org/what-we-do/periodic-table-of-elements/) +is one of the most recognizable features of modern chemistry - the organization +of all known chemical elements along with some of their most fundamental +properties, together with their names and symbols. Today we're going to use +that as we spell some words. + +Here's the list of the elements alphabetized by the element's name. We can also +see the symbol (1 or 2 letters - we're omitting the emerging elements that +often contain three letters), atomic number and weight, and Pauling +Electronegativities (c), which are unused in this challenge. + +| Element | Symbol | Z | Atomic Weight | c | +| ------------- | :----: | --- | ------------- | --- | +| Actinium | Ac | 89 | (227) | 1.1 | +| Aluminum | Al | 13 | 26.9815 | 1.5 | +| Americium | Am | 95 | (243) | 1.3 | +| Antimony | Sb | 51 | 121.75 | 1.9 | +| Argon | Ar | 18 | 39.948 | | +| Arsenic | As | 33 | 74.9216 | 2.0 | +| Astatine | At | 85 | (210) | 2.2 | +| Barium | Ba | 56 | 137 | 0.9 | +| Berkelium | Bk | 97 | (247) | 1.3 | +| Beryllium | Be | 4 | 9.0122 | 1.5 | +| Bismuth | Bi | 83 | 208.980 | 1.9 | +| Boron | B | 5 | 10.81 | 2.0 | +| Bromine | Br | 35 | 79.904 | 2.8 | +| Cadmium | Cd | 48 | 112.40 | 1.7 | +| Calcium | Ca | 20 | 40.08 | 1.0 | +| Californium | Cf | 98 | (251) | 1.3 | +| Carbon | C | 6 | 12.011 | 2.5 | +| Cerium | Ce | 58 | 140.12 | 1.1 | +| Cesium | Cs | 55 | 132.9054 | 0.7 | +| Chlorine | Cl | 17 | 35.453 | 3.0 | +| Chromium | Cr | 24 | 51.996 | 1.6 | +| Cobalt | Co | 27 | 58.9332 | 1.8 | +| Copper | Cu | 29 | 63.546 | 1.9 | +| Curium | Cm | 96 | (247) | 1.3 | +| Dysprosium | Dy | 66 | 162.50 | 1.1 | +| Einsteinium | Es | 99 | (254) | 1.3 | +| Erbium | Er | 68 | 167.26 | 1.1 | +| Europium | Eu | 63 | 151.96 | 1.1 | +| Fermium | Fm | 100 | (257) | 1.3 | +| Fluorine | F | 9 | 18.9984 | 4.0 | +| Francium | Fr | 87 | (223) | 0.7 | +| Gadolinium | Gd | 64 | 157.25 | 1.1 | +| Gallium | Ga | 31 | 69.72 | 1.6 | +| Germanium | Ge | 32 | 72.59 | 1.8 | +| Gold | Au | 79 | 196.966 | 2.4 | +| Hafnium | Hf | 72 | 178.49 | 1.3 | +| Helium | He | 2 | 4.00260 | | +| Holmium | Ho | 67 | 164.930 | 1.1 | +| Hydrogen | H | 1 | 1.0079 | 2.1 | +| Indium | In | 49 | 114.82 | 1.7 | +| Iodine | I | 53 | 126.904 | 2.5 | +| Iridium | Ir | 77 | 192.22 | 2.2 | +| Iron | Fe | 26 | 55.847 | 1.8 | +| Krypton | Kr | 36 | 83.80 | | +| Lanthanum | La | 57 | 138.905 | 1.1 | +| Lawrencium | Lr | 103 | (256) | | +| Lead | Pb | 82 | 207.2 | 1.8 | +| Lithium | Li | 3 | 6.941 | 1.0 | +| Lutetium | Lu | 71 | 174.97 | 1.2 | +| Magnesium | Mg | 12 | 24.305 | 1.2 | +| Manganese | Mn | 25 | 54.9380 | 1.5 | +| Mendelevium | Md | 101 | (258) | 1.3 | +| Mercury | Hg | 80 | 200.59 | 1.9 | +| Molybdenum | Mo | 42 | 95.94 | 1.8 | +| Neodymium | Nd | 60 | 144.24 | 1.1 | +| Neon | Ne | 10 | 20.179 | | +| Neptunium | Np | 93 | 237.048 | 1.3 | +| Nickel | Ni | 28 | 58.70 | 1.8 | +| Niobium | Nb | 41 | 92.9064 | 1.6 | +| Nitrogen | N | 7 | 14.0067 | 3.0 | +| Nobelium | No | 102 | (255) | 1.3 | +| Osmium | Os | 76 | 190.2 | 2.2 | +| Oxygen | O | 8 | 15.9994 | 3.5 | +| Palladium | Pd | 46 | 106.4 | 2.2 | +| Phosphorus | P | 15 | 30.9738 | 2.1 | +| Platinum | Pt | 78 | 195.09 | 2.2 | +| Plutonium | Pu | 94 | (244) | 1.3 | +| Polonium | Po | 84 | (210) | 2.0 | +| Potassium | K | 19 | 39.098 | 0.8 | +| Praseodymium | Pr | 59 | 140.908 | 1.1 | +| Promethium | Pm | 61 | (147) | 1.1 | +| Protactinium | Pa | 91 | 231.036 | 1.4 | +| Radium | Ra | 88 | 226.025 | 0.9 | +| Radon | Rn | 86 | (222) | | +| Rhenium | Re | 75 | 186.207 | 1.9 | +| Rhodium | Rh | 45 | 102.906 | 2.2 | +| Rubidium | Rb | 37 | 85.4678 | 0.8 | +| Ruthenium | Ru | 44 | 101.07 | 2.2 | +| Rutherfordium | Rf | 104 | (261) | | +| Samarium | Sm | 62 | 150.4 | 1.1 | +| Scandium | Sc | 21 | 44.9559 | 1.3 | +| Selenium | Se | 34 | 78.96 | 2.4 | +| Silicon | Si | 14 | 28.086 | 1.8 | +| Silver | Ag | 47 | 107.868 | 1.9 | +| Sodium | Na | 11 | 22.9898 | 0.9 | +| Strontium | Sr | 38 | 87.62 | 1.0 | +| Sulfur | S | 16 | 32.06 | 2.5 | +| Tantalum | Ta | 73 | 180.948 | 1.5 | +| Technetium | Tc | 43 | 98.9062 | 1.9 | +| Tellurium | Te | 52 | 127.60 | 2.1 | +| Terbium | Tb | 65 | 158.925 | 1.1 | +| Thallium | Tl | 81 | 204.37 | 1.8 | +| Thorium | Th | 90 | 232.038 | 1.2 | +| Thulium | Tm | 69 | 168.934 | 1.1 | +| Tin | Sn | 50 | 118.69 | 1.8 | +| Titanium | Ti | 22 | 47.90 | 1.5 | +| Tungsten | W | 74 | 183.85 | 1.7 | +| Uranium | U | 92 | 238.029 | 1.5 | +| Vanadium | V | 23 | 50.9414 | 1.6 | +| Xenon | Xe | 54 | 131.30 | | +| Ytterbium | Yb | 70 | 173.04 | 1.1 | +| Yttrium | Y | 39 | 88.9059 | 1.2 | +| Zinc | Zn | 30 | 65.38 | 1.6 | +| Zirconium | Zr | 40 | 91.22 | 1.4 | + +## Input Description + +You'll be given a list of words, one per line. Example: + + genius + +## Output Description + +Your program should emit the word as a series of elements by name with proper +capitalization from the above table. Example: + + GeNiUS (germanium nickel uranium sulfur) + +## Challenge Input + + functions + bacon + poison + sickness + ticklish + +## Challenge Output + + FUNCTiONS (flourine, uranium, nitrogen, carbon, titanium, oxygen, nitrogen, sulfur) + BaCoN (barium, cobalt, nitrogen) + POISON (phosphorus, oxygen, iodine, sulfur, oxygen, nitrogen) + SiCKNeSS (silicon, carbon, potassium, neon, sulfur, sulfur) + TiCKLiSH (titanium, carbon, potassium, lithium, sulfur, hydrogen) + +## Bonus + +Note that *bacon* has a few different possibilities. Which is the heaviest by +atomic weight? diff --git a/daily/302easy/ptspell.py b/daily/302easy/ptspell.py new file mode 100755 index 0000000..b9adbbd --- /dev/null +++ b/daily/302easy/ptspell.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +from sys import stdin + +PERIODIC_TABLE = {'Ac': ('Actinium', 227.0), 'Ag': ('Silver', 107.868), + 'Al': ('Aluminum', 26.9815), 'Am': ('Americium', 243.0), + 'Ar': ('Argon', 39.948), 'As': ('Arsenic', 74.9216), + 'At': ('Astatine', 210.0), 'Au': ('Gold', 196.966), + 'B': ('Boron', 10.81), 'Ba': ('Barium', 137.0), + 'Be': ('Beryllium', 9.0122), 'Bi': ('Bismuth', 208.98), + 'Bk': ('Berkelium', 247.0), 'Br': ('Bromine', 79.904), + 'C': ('Carbon', 12.011), 'Ca': ('Calcium', 40.08), + 'Cd': ('Cadmium', 112.4), 'Ce': ('Cerium', 140.12), + 'Cf': ('Californium', 251.0), 'Cl': ('Chlorine', 35.453), + 'Cm': ('Curium', 247.0), 'Co': ('Cobalt', 58.9332), + 'Cr': ('Chromium', 51.996), 'Cs': ('Cesium', 132.9054), + 'Cu': ('Copper', 63.546), 'Dy': ('Dysprosium', 162.5), + 'Er': ('Erbium', 167.26), 'Es': ('Einsteinium', 254.0), + 'Eu': ('Europium', 151.96), 'F': ('Fluorine', 18.9984), + 'Fe': ('Iron', 55.847), 'Fm': ('Fermium', 257.0), + 'Fr': ('Francium', 223.0), 'Ga': ('Gallium', 69.72), + 'Gd': ('Gadolinium', 157.25), 'Ge': ('Germanium', 72.59), + 'H': ('Hydrogen', 1.0079), 'He': ('Helium', 4.0026), + 'Hf': ('Hafnium', 178.49), 'Hg': ('Mercury', 200.59), + 'Ho': ('Holmium', 164.93), 'I': ('Iodine', 126.904), + 'In': ('Indium', 114.82), 'Ir': ('Iridium', 192.22), + 'K': ('Potassium', 39.098), 'Kr': ('Krypton', 83.8), + 'La': ('Lanthanum', 138.905), 'Li': ('Lithium', 6.941), + 'Lr': ('Lawrencium', 256.0), 'Lu': ('Lutetium', 174.97), + 'Md': ('Mendelevium', 258.0), 'Mg': ('Magnesium', 24.305), + 'Mn': ('Manganese', 54.938), 'Mo': ('Molybdenum', 95.94), + 'N': ('Nitrogen', 14.0067), 'Na': ('Sodium', 22.9898), + 'Nb': ('Niobium', 92.9064), 'Nd': ('Neodymium', 144.24), + 'Ne': ('Neon', 20.179), 'Ni': ('Nickel', 58.7), + 'No': ('Nobelium', 255.0), 'Np': ('Neptunium', 237.048), + 'O': ('Oxygen', 15.9994), 'Os': ('Osmium', 190.2), + 'P': ('Phosphorus', 30.9738), 'Pa': ('Protactinium', 231.036), + 'Pb': ('Lead', 207.2), 'Pd': ('Palladium', 106.4), + 'Pm': ('Promethium', 147.0), 'Po': ('Polonium', 210.0), + 'Pr': ('Praseodymium', 140.908), 'Pt': ('Platinum', 195.09), + 'Pu': ('Plutonium', 244.0), 'Ra': ('Radium', 226.025), + 'Rb': ('Rubidium', 85.4678), 'Re': ('Rhenium', 186.207), + 'Rf': ('Rutherfordium', 261.0), 'Rh': ('Rhodium', 102.906), + 'Rn': ('Radon', 222.0), 'Ru': ('Ruthenium', 101.07), + 'S': ('Sulfur', 32.06), 'Sb': ('Antimony', 121.75), + 'Sc': ('Scandium', 44.9559), 'Se': ('Selenium', 78.96), + 'Si': ('Silicon', 28.086), 'Sm': ('Samarium', 150.4), + 'Sn': ('Tin', 118.69), 'Sr': ('Strontium', 87.62), + 'Ta': ('Tantalum', 180.948), 'Tb': ('Terbium', 158.925), + 'Tc': ('Technetium', 98.9062), 'Te': ('Tellurium', 127.6), + 'Th': ('Thorium', 232.038), 'Ti': ('Titanium', 47.9), + 'Tl': ('Thallium', 204.37), 'Tm': ('Thulium', 168.934), + 'U': ('Uranium', 238.029), 'V': ('Vanadium', 50.9414), + 'W': ('Tungsten', 183.85), 'Xe': ('Xenon', 131.3), + 'Y': ('Yttrium', 88.9059), 'Yb': ('Ytterbium', 173.04), + 'Zn': ('Zinc', 65.38), 'Zr': ('Zirconium', 91.22)} +MEM = {} + + +def spell(s): + if s in MEM: return MEM[s] + if not s: return [] + + s, l = s.capitalize(), [] + if len(s) == 1 and s in PERIODIC_TABLE: + MEM[s] = [(s,)] + return MEM[s] + if len(s) == 2: + if s in PERIODIC_TABLE: l.append((s,)) + t = tuple(s.upper()) + if all(i in PERIODIC_TABLE for i in t): l.append(t) + MEM[s] = l + return l + + if s[0] in PERIODIC_TABLE: + l.extend([(s[0],) + i for i in spell(s[1:])]) + if len(s) > 1 and s[0:2] in PERIODIC_TABLE: + l.extend([(s[0:2],) + i for i in spell(s[2:])]) + MEM[s] = l + return l + + +for i in stdin: + d = {sum(PERIODIC_TABLE[k][1] for k in j): j for j in spell(i.strip())} + t = d[max(d)] + print(''.join(t), '(' + ' '.join(PERIODIC_TABLE[j][0] for j in t) + ')') -- cgit 1.4.1