Results 1 to 11 of 11

Thread: [RESOLVED] Bit manipulation

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] Bit manipulation

    Hi,

    Say I have an x number of bits and I'd like to know all possibilities for that number, but only half of the bits can be toggled at the time.
    For 4 bits these would be:
    Code:
    0011
    0110
    1100
    1010
    0101
    1001
    What would be a methodical way of getting those for a bigger x?

    Thanks
    Delete it. They just clutter threads anyway.

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Bit manipulation

    If I remember my math correctly:

    In your specific example, n=4 and k=2. For 8 bits, you'd use n=8 and k=4 thus get a result of 70. Is this correct?

    Look up combinations here.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Bit manipulation

    OK, so this is the problem
    Code:
    Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.
    How many routes are there through a 20×20 grid?
    So basically the rules state that it can go 20 right and 20 down with a lot of different orders of that movement.
    Hence toggling half of the bits.
    I've worked out that with the values n=40 and k=20 the number should be 137846528800, but that appears to be incorrect.
    (assuming n! = 8,15915283247898E+47 and k! = 2,43290200817664E+18)
    So is my calculator rounding incorrectly? Have I miscalculated the factorials? Or am I completely missing the point here.
    Last edited by TheBigB; Apr 14th, 2010 at 07:10 AM.
    Delete it. They just clutter threads anyway.

  4. #4
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Bit manipulation

    The 137846528800 number is correct. However, I can't really say that the problem is reduced to the same formula for combinatorics. How did you come to the conclusion that the 137846528800 is incorrect?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  5. #5

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Bit manipulation

    I submitted it, but I got a message saying it's not the correct answer.
    The reason I think the formula is related is that you could see move down as 1 and move right as 0.
    In the example with 2x2 grid, either path will always require 2 steps down and 2 steps right.
    Delete it. They just clutter threads anyway.

  6. #6
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Bit manipulation

    I see what you mean, your reasoning sounds right. I made a quick program that actually counted the possible combinations and I made the assumption that you're correct. The results confirm that both a 3x3 and a 4x4 grid are according to the formula (20 and 70).
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  7. #7

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Bit manipulation

    Solved it, I was missing accuracy (missed 20 on the tail of the answer).
    Thanks for your help
    Delete it. They just clutter threads anyway.

  8. #8
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: [RESOLVED] Bit manipulation

    So the answer was the correct one?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  9. #9

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [RESOLVED] Bit manipulation

    It was 137846528820
    Delete it. They just clutter threads anyway.

  10. #10
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: [RESOLVED] Bit manipulation

    I'd never expect Calc to give out a rounding error. How'd you find out about the error?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  11. #11

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [RESOLVED] Bit manipulation

    I asked for a hint on the Project Euler forum.
    They said my accuracy was off and suggested something like Google calc. Used Wolfram to calculate the exact answer.
    Weird thing is that my TI-84 plus gives the same rounding error.
    I'll have to check if I have some accuracy setting I can modify...
    Delete it. They just clutter threads anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width