Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. What's the most challenging algorithm you've ever faced

What's the most challenging algorithm you've ever faced

Scheduled Pinned Locked Moved The Lounge
algorithmsregexjsonannouncement
42 Posts 15 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PIEBALDconsult

    What's a line?

    D Offline
    D Offline
    Daniel Pfeffer
    wrote on last edited by
    #6

    Something bounded by two points. :-\

    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

    D 1 Reply Last reply
    0
    • H honey the codewitch

      ... that you can explain the purpose of in one (reasonable) line, say a sentence or two brief ones. Mine is implementing a 2D polygon fill algorithm on a write only display device. I know how in theory - vaguely - to do it, but it's mind bending to attempt in practice, and I say that as someone who writes old-school table based LR parsers. UPDATE: Randor humbled me. There's an easy way to do this. I even knew about it at one point but blanked on it here. I am very grateful, despite feeling a little foolish. My most complicated algo... probably GLR parsing. In terms of ones I haven't solved - there's one that should be simple but I can never get it right -> converting an NFA or DFA state machine into a regular expression.

      Real programmers use butterflies

      D Offline
      D Offline
      Daniel Pfeffer
      wrote on last edited by
      #7

      Many (~ 500) moons ago, I had to write a line "fitting" program with some unusual constraints. None of the usual "least squares", "cubic spline" etc. methods did exactly what was wanted, so I had to roll my own.

      Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

      1 Reply Last reply
      0
      • H honey the codewitch

        ... that you can explain the purpose of in one (reasonable) line, say a sentence or two brief ones. Mine is implementing a 2D polygon fill algorithm on a write only display device. I know how in theory - vaguely - to do it, but it's mind bending to attempt in practice, and I say that as someone who writes old-school table based LR parsers. UPDATE: Randor humbled me. There's an easy way to do this. I even knew about it at one point but blanked on it here. I am very grateful, despite feeling a little foolish. My most complicated algo... probably GLR parsing. In terms of ones I haven't solved - there's one that should be simple but I can never get it right -> converting an NFA or DFA state machine into a regular expression.

        Real programmers use butterflies

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #8

        true love

        «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

        H D Greg UtasG 3 Replies Last reply
        0
        • B BillWoodruff

          true love

          «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #9

          Treating love like an algorithm might have something to do with it. :laugh:

          Real programmers use butterflies

          B 1 Reply Last reply
          0
          • B BillWoodruff

            true love

            «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

            D Offline
            D Offline
            Daniel Pfeffer
            wrote on last edited by
            #10

            Obligatory [xkcd: Useless](https://xkcd.com/55/)

            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

            1 Reply Last reply
            0
            • H honey the codewitch

              Treating love like an algorithm might have something to do with it. :laugh:

              Real programmers use butterflies

              B Offline
              B Offline
              BillWoodruff
              wrote on last edited by
              #11

              When "true love" is your patient, then, doctor, treatment "primum non nocere" is even more critical. I find it fascinating that the original sigil of the Asclepian healing cult had only onw serpent twining around the staff, not two (as on the Caduceus of Mercury).

              «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

              1 Reply Last reply
              0
              • B BillWoodruff

                true love

                «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                Greg UtasG Offline
                Greg UtasG Offline
                Greg Utas
                wrote on last edited by
                #12

                Given these truths: o Time is money. o Money is the root of all evil. o Girls cost time and money. We obtain

                time = money
                _____
                money = V evil

                girls = time x money

                girls = money x money
                _____ _____
                girls = V evil x V evil

                girls = evil

                Robust Services Core | Software Techniques for Lemmings | Articles
                The fox knows many things, but the hedgehog knows one big thing.

                <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                D D 2 Replies Last reply
                0
                • H honey the codewitch

                  ... that you can explain the purpose of in one (reasonable) line, say a sentence or two brief ones. Mine is implementing a 2D polygon fill algorithm on a write only display device. I know how in theory - vaguely - to do it, but it's mind bending to attempt in practice, and I say that as someone who writes old-school table based LR parsers. UPDATE: Randor humbled me. There's an easy way to do this. I even knew about it at one point but blanked on it here. I am very grateful, despite feeling a little foolish. My most complicated algo... probably GLR parsing. In terms of ones I haven't solved - there's one that should be simple but I can never get it right -> converting an NFA or DFA state machine into a regular expression.

                  Real programmers use butterflies

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #13

                  Mine, and I have not completed it after a few years.. :/ :-O Is to do 2D shape (bordered by bezier line) intersection...

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  1 Reply Last reply
                  0
                  • Greg UtasG Greg Utas

                    Given these truths: o Time is money. o Money is the root of all evil. o Girls cost time and money. We obtain

                    time = money
                    _____
                    money = V evil

                    girls = time x money

                    girls = money x money
                    _____ _____
                    girls = V evil x V evil

                    girls = evil

                    Robust Services Core | Software Techniques for Lemmings | Articles
                    The fox knows many things, but the hedgehog knows one big thing.

                    D Offline
                    D Offline
                    Daniel Pfeffer
                    wrote on last edited by
                    #14

                    You forgot the branch cut - a square root has two solutions. This gives us:

                    time = money
                    _____
                    money = ± V evil

                    girls = time x money

                    girls = money x money
                    _____ _____
                    girls = ± V evil x ± V evil

                    girls = ± evil

                    This is closer to the real world, in that: 1. Money may be either positive (credit) or negative (debit) 2. Some girls are good :D

                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                    1 Reply Last reply
                    0
                    • H honey the codewitch

                      ... that you can explain the purpose of in one (reasonable) line, say a sentence or two brief ones. Mine is implementing a 2D polygon fill algorithm on a write only display device. I know how in theory - vaguely - to do it, but it's mind bending to attempt in practice, and I say that as someone who writes old-school table based LR parsers. UPDATE: Randor humbled me. There's an easy way to do this. I even knew about it at one point but blanked on it here. I am very grateful, despite feeling a little foolish. My most complicated algo... probably GLR parsing. In terms of ones I haven't solved - there's one that should be simple but I can never get it right -> converting an NFA or DFA state machine into a regular expression.

                      Real programmers use butterflies

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #15

                      honey the codewitch wrote:

                      Mine is implementing a 2D polygon fill algorithm

                      Are you saying that the most complex algorithm you've ever implemented is a depth-first/breadth-first traversal? Or am I misunderstanding something. I glanced through your latest articles but didn't see anything mentioned. I guess the most complicated I've dealt with is noisy sparse signals recovery using Kalman filter[^] variants while I was working at Marine Technologies[^] circa ~2006. Kalman wasn't even the hard part... the underlying Gaussian mixture model[^] was where all the magic really happens. The reason it's considered difficult is because it's an approximation and there is always a better approximation to be found. We had to hire a mathematics professor from Norway as a consultant to help. Math is hard. Best Wishes, -David Delaune

                      H 1 Reply Last reply
                      0
                      • L Lost User

                        honey the codewitch wrote:

                        Mine is implementing a 2D polygon fill algorithm

                        Are you saying that the most complex algorithm you've ever implemented is a depth-first/breadth-first traversal? Or am I misunderstanding something. I glanced through your latest articles but didn't see anything mentioned. I guess the most complicated I've dealt with is noisy sparse signals recovery using Kalman filter[^] variants while I was working at Marine Technologies[^] circa ~2006. Kalman wasn't even the hard part... the underlying Gaussian mixture model[^] was where all the magic really happens. The reason it's considered difficult is because it's an approximation and there is always a better approximation to be found. We had to hire a mathematics professor from Norway as a consultant to help. Math is hard. Best Wishes, -David Delaune

                        H Offline
                        H Offline
                        honey the codewitch
                        wrote on last edited by
                        #16

                        It's just not depth first or breadth first traversal - that part is easy. I think you're thinking of a flood fill algorithm, which won't work on a write only device because you need to read the pixel data. It also won't work if you try to draw a filled polygon over existing draws. What I need to do for example: _/\_ \__/ Say that's my poly here /\ I need to go top to bottom, left to right from the beginning of each point of the left line to each point on the right line, across. I also need to sort the points so I can figure out where to start drawing.

                        Real programmers use butterflies

                        L 1 Reply Last reply
                        0
                        • H honey the codewitch

                          It's just not depth first or breadth first traversal - that part is easy. I think you're thinking of a flood fill algorithm, which won't work on a write only device because you need to read the pixel data. It also won't work if you try to draw a filled polygon over existing draws. What I need to do for example: _/\_ \__/ Say that's my poly here /\ I need to go top to bottom, left to right from the beginning of each point of the left line to each point on the right line, across. I also need to sort the points so I can figure out where to start drawing.

                          Real programmers use butterflies

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #17

                          Hi, A few more questions; 1.) Does your algorithm support polygons with holes[^]? 2.) Did you invent something new or implement an existing algorithm? 3.) Where can I find your work? I'd like to look at it. Best Wishes, -David Delaune

                          H 2 Replies Last reply
                          0
                          • L Lost User

                            Hi, A few more questions; 1.) Does your algorithm support polygons with holes[^]? 2.) Did you invent something new or implement an existing algorithm? 3.) Where can I find your work? I'd like to look at it. Best Wishes, -David Delaune

                            H Offline
                            H Offline
                            honey the codewitch
                            wrote on last edited by
                            #18

                            1. Heck no!* 2. I haven't been able to implement the algorithm. It is described at tutorialspoint somewhere but no implementation 3. I'll publish it here when I solve it. Sorry if my OP implied I solved it. I did not mean to. If I had solved it I'd have found something else to get stuck on by now. :laugh: * adding, there's no way to even describe it with my API, except you should be able to approximate any polygon with holes by one without one that loops back on itself - as long as it's filled you won't be able to tell the difference.

                            Real programmers use butterflies

                            1 Reply Last reply
                            0
                            • L Lost User

                              Hi, A few more questions; 1.) Does your algorithm support polygons with holes[^]? 2.) Did you invent something new or implement an existing algorithm? 3.) Where can I find your work? I'd like to look at it. Best Wishes, -David Delaune

                              H Offline
                              H Offline
                              honey the codewitch
                              wrote on last edited by
                              #19

                              I just figured out a much easier way in theory to do it. Just scale the thing smaller and smaller by 1 pixel in any direction and keep redrawing it until you get down to a single point. Unfortunately, in practice this won't work - the way the bresenham line drawing algo works it will leave little holes in the result. *sadface*

                              Real programmers use butterflies

                              L 1 Reply Last reply
                              0
                              • H honey the codewitch

                                ... that you can explain the purpose of in one (reasonable) line, say a sentence or two brief ones. Mine is implementing a 2D polygon fill algorithm on a write only display device. I know how in theory - vaguely - to do it, but it's mind bending to attempt in practice, and I say that as someone who writes old-school table based LR parsers. UPDATE: Randor humbled me. There's an easy way to do this. I even knew about it at one point but blanked on it here. I am very grateful, despite feeling a little foolish. My most complicated algo... probably GLR parsing. In terms of ones I haven't solved - there's one that should be simple but I can never get it right -> converting an NFA or DFA state machine into a regular expression.

                                Real programmers use butterflies

                                Greg UtasG Offline
                                Greg UtasG Offline
                                Greg Utas
                                wrote on last edited by
                                #20

                                I was slow to reply because I guess algorithm implies a fairly contained piece of code. So I'd say it was an event dispatcher for telecom state machines. It wasn't so much the algorithm, but the design around it. When you add lots of supplementary services to a basic call, building One Big State Machine creates a Big Ball of Mud. To keep the state machines separate, they run in an event-routing framework that allows state transitions to be announced, overridden, and/or supplemented. Chain of Responsibility plays a role in instantiating the state machines. The algorithm for this was implemented in the state machine base class. I've thought about writing an article about it, but I doubt it would have much value because I haven't heard of another domain that requires this kind of solution.

                                Robust Services Core | Software Techniques for Lemmings | Articles
                                The fox knows many things, but the hedgehog knows one big thing.

                                <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                H 1 Reply Last reply
                                0
                                • Greg UtasG Greg Utas

                                  I was slow to reply because I guess algorithm implies a fairly contained piece of code. So I'd say it was an event dispatcher for telecom state machines. It wasn't so much the algorithm, but the design around it. When you add lots of supplementary services to a basic call, building One Big State Machine creates a Big Ball of Mud. To keep the state machines separate, they run in an event-routing framework that allows state transitions to be announced, overridden, and/or supplemented. Chain of Responsibility plays a role in instantiating the state machines. The algorithm for this was implemented in the state machine base class. I've thought about writing an article about it, but I doubt it would have much value because I haven't heard of another domain that requires this kind of solution.

                                  Robust Services Core | Software Techniques for Lemmings | Articles
                                  The fox knows many things, but the hedgehog knows one big thing.

                                  H Offline
                                  H Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #21

                                  I could see it in a message passer system like that used in microkernel operating systems.

                                  Real programmers use butterflies

                                  1 Reply Last reply
                                  0
                                  • H honey the codewitch

                                    I just figured out a much easier way in theory to do it. Just scale the thing smaller and smaller by 1 pixel in any direction and keep redrawing it until you get down to a single point. Unfortunately, in practice this won't work - the way the bresenham line drawing algo works it will leave little holes in the result. *sadface*

                                    Real programmers use butterflies

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #22

                                    Well, That doesn't really make any sense. I don't understand the technical issues you are encountering. Drawing, filling and scaling 2D polygons is exceedingly trivial. Based on what you have said I see the following requirements: 1.) You are only supporting simple polygons[^]. 2.) You need to write to the video device in a scanline pattern[^]. 3.) You cannot read pixels. 4.) You have not stated why you can't draw in a frame buffer. But I will assume that you either can't or are unwilling. So I don't think that you can use the Nonzero-rule[^]. But you could use the even–odd rule[^]. Some other things for you to read for scaling your polygons: Dot product[^] Best Wishes, -David Delaune

                                    H 2 Replies Last reply
                                    0
                                    • L Lost User

                                      Well, That doesn't really make any sense. I don't understand the technical issues you are encountering. Drawing, filling and scaling 2D polygons is exceedingly trivial. Based on what you have said I see the following requirements: 1.) You are only supporting simple polygons[^]. 2.) You need to write to the video device in a scanline pattern[^]. 3.) You cannot read pixels. 4.) You have not stated why you can't draw in a frame buffer. But I will assume that you either can't or are unwilling. So I don't think that you can use the Nonzero-rule[^]. But you could use the even–odd rule[^]. Some other things for you to read for scaling your polygons: Dot product[^] Best Wishes, -David Delaune

                                      H Offline
                                      H Offline
                                      honey the codewitch
                                      wrote on last edited by
                                      #23

                                      You know I've even read about that technique years ago, and for some reason I completely overlooked it - it went down the memory hole. I'm not entirely sure even-odd will work until I try it, but I'll certainly try it. Thanks in advance, even if it leaves me feeling like a bit of an idiot. I'll take it if it means a solution. :)

                                      Real programmers use butterflies

                                      L 1 Reply Last reply
                                      0
                                      • H honey the codewitch

                                        You know I've even read about that technique years ago, and for some reason I completely overlooked it - it went down the memory hole. I'm not entirely sure even-odd will work until I try it, but I'll certainly try it. Thanks in advance, even if it leaves me feeling like a bit of an idiot. I'll take it if it means a solution. :)

                                        Real programmers use butterflies

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #24

                                        honey the codewitch wrote:

                                        it leaves me feeling like a bit of an idiot

                                        You are obviously not an idiot, but rather experimenting with geometry and probably never looked here before. Everyone is clueless when they poke around in an unfamiliar topic. Everybody is standing on the shoulders of giants and very rarely do you find a human that generates something new. That's why I wanted to see what you created, I wanted to see if it was something new. Anyway, I forgot to mention why you probably can't use the nonzero-rule. It works by summing the angles which means it would need to use a minimum of 3 rows. The even–odd rule would allow you to cast a single photon (ray of light) across one scanline and simply check for even/odd values. I would recommend testing this stuff on your desktop and get out of that restrained environment during the test development. Good luck, -David Delaune

                                        H 1 Reply Last reply
                                        0
                                        • L Lost User

                                          honey the codewitch wrote:

                                          it leaves me feeling like a bit of an idiot

                                          You are obviously not an idiot, but rather experimenting with geometry and probably never looked here before. Everyone is clueless when they poke around in an unfamiliar topic. Everybody is standing on the shoulders of giants and very rarely do you find a human that generates something new. That's why I wanted to see what you created, I wanted to see if it was something new. Anyway, I forgot to mention why you probably can't use the nonzero-rule. It works by summing the angles which means it would need to use a minimum of 3 rows. The even–odd rule would allow you to cast a single photon (ray of light) across one scanline and simply check for even/odd values. I would recommend testing this stuff on your desktop and get out of that restrained environment during the test development. Good luck, -David Delaune

                                          H Offline
                                          H Offline
                                          honey the codewitch
                                          wrote on last edited by
                                          #25

                                          Randor wrote:

                                          I would recommend testing this stuff on your desktop and get out of that restrained environment during the test development.

                                          That's actually part of why I wrote GFX to be runnable anywhere. I didn't want to develop it on a constrained environment. But it has to run on them. My initial GFX library dumped its output solely using printf() and drawing ascii art after converting bitmaps to 16 color grayscale. I used that to test my line drawing algorithms and such. But now that all of that is done and pretty predictable, I find myself going back to the PC to code this thing less and less, either because I'm dealing with things like asynchronous draws which have no support on the PC, or most of what I'm doing works the first time or two after it compiles because i've built the foundation up by now enough that the coding is fairly high level.

                                          Real programmers use butterflies

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups