Last active
August 29, 2015 14:16
-
-
Save RussellAndrewEdson/120723e8b865d4f131dc to your computer and use it in GitHub Desktop.
The "genie" that generates MIU strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a list of MIU strings, this method generates more strings by taking | |
# each of the strings in the list and, if possible, applying each of the Rules | |
# 1, 2, 3, 4 to that string. The resulting collection of strings is then | |
# filtered for duplicates and returned. | |
def generate_more_strings(miu_strings) | |
# Helper method: applies all of the possible rules to a given string, and | |
# returns an array of the results. | |
def apply_all_rules(str) | |
results = [] | |
results << apply_rule1(str) if can_apply_rule1?(str) | |
results << apply_rule2(str) if can_apply_rule2?(str) | |
if can_apply_rule3?(str) | |
results << rule3_indices(str).map { |i| apply_rule3(str, i) } | |
end | |
if can_apply_rule4?(str) | |
results << rule4_indices(str).map { |i| apply_rule4(str, i) } | |
end | |
results | |
end | |
miu_strings.map { |str| apply_all_rules(str) }.flatten.uniq | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment