Advertisement
Guest User

combinatorics

a guest
May 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.79 KB | None | 0 0
  1. import hashes
  2. import combinatorics  
  3. echo()
  4. echo "testing permutations"
  5. echo()
  6. # https://bitbucket.org/nimcontrib/nimcombinatorics
  7.  
  8.  
  9. let cc = @["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  10.  
  11. let ts = "efghi"   # a string which will be hit early
  12.  
  13. let okhash = hash(ts)
  14. var ms = ""
  15. var trials = 0
  16.  
  17. for x in permutations[string](cc):          
  18.     for z in x:
  19.          ms = ms & z
  20.          if ms.len == ts.len:
  21.              inc trials
  22.              echo "Trials : ",trials,"  ms : ",ms
  23.              if hash(ms) == okhash:
  24.                      echo()
  25.                      echo ms,"   hash : ",okhash
  26.                      echo "trials : ",trials
  27.                      quit(0)
  28.              else:  ms = ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement