Re: Combinatorics question



On Apr 6, 8:21�am, Ketakop...@xxxxxxxxx wrote:
I understood the general method, but I don't quite get the Python
algorithm. Let's see, you first create some kind of vector with all
combinations of S elements, that is, size 2^S, filled with binaries.

Just a for..loop, no need to track all of them,
just the solutons.

You then enter the method for those with popcount=4.

This is called inside the for..loop, while the binary numbers
are created, not afterwards.

But I don't get what gmpy is,

It's an extension module for Python. Third party, not
part of the standard distribution. I don't recall the
site, but it's easily found by Google.

It's a math library, specifically, the GNU Multi-Precision
(GMP) library with a Python wrapper. Highly recommended
as it's very fast, supports things Python doesn't have
like Rationals & unlimited precision Floats and includes
a lot of specialized math functions including the
bit manipulations popcount and Hamming Distance.
Also does base two conversion which makes the mapping
easier.

nor the_combos; is it a string, integer...?

That's the list of numbers that gets created that matches
your requested criteria, every one has 4 bits and no
pair in the list have a Hamming Distance of 2 or less
(meaning no pair has more than 2 matching bits).

The rest of the program maps these binary numbers to
the letters 'abcdef', complicated by bit order being
reversed.

If you use MSA's corrected algorithm to generate 4-bit
numbers, I think you still have to do the Hamming
Distance and you may want to note that for mapping
purposes I make sure each base 2 string has the appropriate
leading 0's so that 15 becomes 001111. That's waht the
.zfill(6) does.


.



Relevant Pages

  • Re: Combinatorics question
    ... It's an extension module for Python. ... bit manipulations popcount and Hamming Distance. ... Also does base two conversion which makes the mapping ... If you use MSA's corrected algorithm to generate 4-bit ...
    (sci.math)
  • Re: hide python code !
    ... doors or installing burglar alarms, ... Compiling code to machine language isn't like locking your door. ... Compiling code doesn't prevent me from seeing your code or your algorithm, ... Would you argue that Python source code hides your ...
    (comp.lang.python)
  • String similarity
    ... The algorithm that I have chosen for the comparison between string was ... Python reducing the code from 1394 lines of "C" to 152 lines of Python ... Initially I have rearranged part of "C" code in one module "simil" ... Comparing string this is not possible and the only way that I have found ...
    (comp.lang.python)
  • Re: hide python code !
    ... Compiling code to machine language isn't like locking your door. ... Compiling code doesn't prevent me from seeing your code or your algorithm, ... Would you argue that Python source code hides your ... 'imperfect protection' with 'pointless protection'. ...
    (comp.lang.python)
  • Re: Slowness!
    ... I am using the python profiler - and ... >>LOS algorithm for a simpler one that takes less time. ... >>I will stick with Python until I feel the code is as fast as I can make ...
    (rec.games.roguelike.development)