stoichiograph

Spell words with elemental symbols from the periodic table.
git clone git://git.amin.space/stoichiograph.git
Log | Files | Refs | LICENSE

commit 9d206237920aa78d1e2e0d60276f54e0e98d43f6
parent d9544dd781ee0c698e1a25173956e12ee24877d5
Author: amin <dev@aminmesbah.com>
Date:   Wed, 11 Jan 2017 08:24:38 +0000

Groupings contain 'batches' instead of 'groups'.

FossilOrigin-Name: 9bc5919e31583b8e9a1ef21a50db02ece28ef2f2b18228ed5f5d8e58c8efbd4b
Diffstat:
Melemental_speller.py | 16++++++++--------
Mtests.py | 6+++---
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/elemental_speller.py b/elemental_speller.py @@ -51,19 +51,19 @@ def spell(word, symbols=ELEMENTS): return elemental_spellings -def generate_groupings(word_length, group_sizes=(1, 2)): +def generate_groupings(word_length, batch_sizes=(1, 2)): """Return all groupings for a word of a given length. A grouping is a tuple representing the distribution of characters in a word. By default, characters can be in - groups of 1 or 2. + batches of 1 or 2. Example: >>> generate_groupings(4) ((2, 2), (1, 1, 2), (1, 2, 1), (2, 1, 1), (1, 1, 1, 1)) """ cartesian_products = ( - product(group_sizes, repeat=r) + product(batch_sizes, repeat=r) for r in range(1, word_length + 1) ) @@ -95,11 +95,11 @@ def map_word(word, grouping): chars = (c for c in word) mapped = [] - for group_size in grouping: - group = "" - for _ in range(group_size): - group += next(chars) - mapped.append(group) + for batch_size in grouping: + batch = "" + for _ in range(batch_size): + batch += next(chars) + mapped.append(batch) log.debug('Grouping: {}. Mapped word: {}'.format(grouping, mapped)) diff --git a/tests.py b/tests.py @@ -20,13 +20,13 @@ def test_verify_data(): def test_groupings(): - assert es.generate_groupings(4, group_sizes=()) == () + assert es.generate_groupings(4, batch_sizes=()) == () - assert es.generate_groupings(4, group_sizes=(1, 2)) == ( + assert es.generate_groupings(4, batch_sizes=(1, 2)) == ( (2, 2), (1, 1, 2), (1, 2, 1), (2, 1, 1), (1, 1, 1, 1) ) - assert es.generate_groupings(4, group_sizes=(1, 2, 3)) == ( + assert es.generate_groupings(4, batch_sizes=(1, 2, 3)) == ( (1, 3), (2, 2), (3, 1), (1, 1, 2), (1, 2, 1), (2, 1, 1), (1, 1, 1, 1) )