Want more features on Pastebin? Sign Up, it's FREE!
Guest

Word Cube in Lua

By: a guest on Jul 20th, 2010  |  syntax: Lua  |  size: 0.40 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- q contains all the letters from s?
  2. function containedIn(s,q)
  3.         local r
  4.         for i=1,#s do
  5.                 q,r=string.gsub(q,string.sub(s,i,i),"",1)
  6.                 if r==0 then return false end
  7.         end
  8.         return true
  9. end
  10.  
  11. function cubeWords(q)
  12.         q5=string.sub(q,5,5)
  13.         for l in io.lines("words.txt") do
  14.                 l=string.lower(l)
  15.                 if #l>3 and string.find(l,q5) and containedIn(l,q) then
  16.                 print(l)
  17.                 end
  18.         end
  19. end
  20.  
  21. cubeWords("ncbcioune")
clone this paste RAW Paste Data