How do I get all permutations of xPy?

后端 未结 3 722
小蘑菇
小蘑菇 2021-01-19 05:07

I\'d like to calculate all the permutations of size Y of a set of size X. That is if I had (1,2,3) and want all permutations of size 2, 3P2, it would be (1,2) (1,3) (2,1) (

3条回答
  •  生来不讨喜
    2021-01-19 05:38

    I do not exacly get your question about cryptogram. But if you want to find longest permutation (anagram) of this words in your dictionary you can try his way.

    1. create bitmask of your word. You can probably use 64 bit arithmetics so you can fit almost 3 alpahbets inside.

    a-> first bit, b-> second bit and so on. If you have word in your "ouglg ouyakl" case this mean

     abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyzabcdefghijklmnop
     100000100011001000001001000000010000100100000100000000000000000000
    

    (hope i did not missed something) Now you create same bitmasks for your vocabulary.

    And when you chek against vocabulary you just have to do is

     vocabulary & ( ouglg_ouyakl ^ vocabulary)
    

    and this trows 0 if your vocabulary word is from ouglg_ouyakl.

    About permutations

    for each permutation of numbers fom  1-n // that is 1,2 and 2,1
      for(i=0;i

    EDIT: prevous soluton was inapropriate for 24P7.

提交回复
热议问题