Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dictionary = {}
- local function insertWord(dict, word)
- local head, tail = word:upper():match('^(%a)(%a*)$')
- if not head then return false; end
- if not dict[head] then dict[head] = {}; end
- if tail == '' then
- dict[head][''] = true
- return true
- else
- return insertWord(dict[head], tail)
- end
- end
- local function confirmWord(dict, word)
- local head, tail = word:upper():match('^(%a)(%a*)$')
- if not head then return false; end
- if dict[head] then
- if tail == '' then
- return dict[head][''] or false
- else
- return confirmWord(dict[head], tail)
- end
- else
- return false
- end
- end
- insertWord(dictionary, 'BAG')
- print(confirmWord(dictionary, 'BAG'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement