commit 5658e0ac46c65afc80cce76a0a32f5c7d0dfed71 Author: hellerve Date: Wed Sep 27 16:15:57 2017 +0200 initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..7dab829 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# di + +*From little fig, while groves halfway.* + +An implementation of the Diastic technique. diff --git a/di.py b/di.py new file mode 100644 index 0000000..85899a8 --- /dev/null +++ b/di.py @@ -0,0 +1,20 @@ +import sys + +def diastic(word, phrases): + words = [] + + cur = 0 + + for idx, c in enumerate(word): + for nxt, phrase in enumerate(phrases[cur:]): + if len(phrase) > idx and phrase[idx] == c: + words.append(phrase) + cur = idx + 1 + break + + return " ".join(words) + +if __name__ == "__main__": + with open(sys.argv[2]) as f: + words = f.read().split() + print(diastic(sys.argv[1], words))