stoichiograph

Spell words with elemental symbols from the periodic table.
Log | Files | Refs | LICENSE

commit 52f74add2a1516be736e163ed3fb22667fa68ce8
parent 7981c598aed5ceb993f625a68d18cfe50464c6f8
Author: Amin Mesbah <mesbah.amin@gmail.com>
Date:   Wed, 11 Jan 2017 00:24:39 -0800

Groupings contain 'batches' instead of 'groups'.

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) )