Thread: More of an alogirthm problem

  1. #1
    Registered User
    Join Date
    Apr 2007

    More of an alogirthm problem

    I got a 2D array of values that represent a b&w(1 or 0) bitmap(64x64).. Now i need to read the bitmap in a spiral way starting from (31,31) and store them in a 1 dimensional array.. I've been trying to come up with an efficient algorithm for some time now.... Can somebody please help me out?


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps present your algorithm first, then there's no danger of suggesting what you've already tried.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    Well when I try stepping along a square shaped spiral, I move 1 pixel up, 1 pixel right, 2 pixels down, 2 pixels left, 3 pixels up, 3 pixels right, 4 pixels down etc..
    So it seems that your move lengths are 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6 etc.
    I.e movelength(n) = (n+1)/2
    Or you simply increment the move length after each time you move horizontally.

    Last of all you have to track your direction e.g.
    0 = up
    1 = right
    2 = down
    3 = left
    Keep cycling through those.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM