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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. When coding is harder than it should be...

When coding is harder than it should be...

Scheduled Pinned Locked Moved The Lounge
visual-studiocomalgorithmshelp
11 Posts 6 Posters 1 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.
  • L Offline
    L Offline
    leppie
    wrote on last edited by
    #1

    You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

    J D C G 5 Replies Last reply
    0
    • L leppie

      You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

      J Offline
      J Offline
      Jared Parsons
      wrote on last edited by
      #2

      public static List SplitAndKeep(string target) { List list = new List(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < target.Length; i++) { char current = target[i]; switch (current) { case '.': list.Add(builder.ToString()); list.Add("."); builder.Length = 0; break; case ':': if (i < target.Length + 1 && ':' == target[i + 1]) { list.Add(builder.ToString()); list.Add("::"); i++; builder.Length = 0; } else { builder.Append(current); } break; default: builder.AppendFormat(current); break; } } list.Add(builder.ToString()); return list; } Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/ -- modified at 16:41 Friday 30th December, 2005

      L 1 Reply Last reply
      0
      • J Jared Parsons

        public static List SplitAndKeep(string target) { List list = new List(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < target.Length; i++) { char current = target[i]; switch (current) { case '.': list.Add(builder.ToString()); list.Add("."); builder.Length = 0; break; case ':': if (i < target.Length + 1 && ':' == target[i + 1]) { list.Add(builder.ToString()); list.Add("::"); i++; builder.Length = 0; } else { builder.Append(current); } break; default: builder.AppendFormat(current); break; } } list.Add(builder.ToString()); return list; } Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/ -- modified at 16:41 Friday 30th December, 2005

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        Nice try, but the delimiters can be anything, and any length. :) xacc.ide-0.1.1 released! :) Download and screenshots

        1 Reply Last reply
        0
        • L leppie

          You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

          D Offline
          D Offline
          DavidNohejl
          wrote on last edited by
          #4

          I didn't think too much about it, but doesn't (every) standard string searching algorithm be modified to do that? (I mean, search for ":" and "::" and then in the same time split string according to positions of found delimiters (?) Never forget: "Stay kul and happy" (I.A.)
          David's thoughts / dnhsoftware.org / MyHTMLTidy

          L 1 Reply Last reply
          0
          • D DavidNohejl

            I didn't think too much about it, but doesn't (every) standard string searching algorithm be modified to do that? (I mean, search for ":" and "::" and then in the same time split string according to positions of found delimiters (?) Never forget: "Stay kul and happy" (I.A.)
            David's thoughts / dnhsoftware.org / MyHTMLTidy

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            my current idea is: create indici for each delimiter in input string, then just walk thru the input string. Even using the best string searching algorithm with this approach, will have a 'high' complexity. Hmmm, this reminds of an article I saw recently on CP (leppie tries the dreaded search). xacc.ide-0.1.1 released! :) Download and screenshots

            1 Reply Last reply
            0
            • L leppie

              You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

              C Offline
              C Offline
              code frog 0
              wrote on last edited by
              #6

              That isn't so bad to me as when you spend hours coding this sweet routine that makes some control-thingy do something really cool and when you are all done you discover that it was just a method on the control that takes a single parameter... I've been there! I've done *that* and I think I've hated myself ever since. :doh::laugh:

              Some assembly required. Code-frog System Architects, Inc.

              1 Reply Last reply
              0
              • L leppie

                You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

                J Offline
                J Offline
                Jared Parsons
                wrote on last edited by
                #7

                I think my favorite is when you can't get something to work so you decide to email the authors and ask them about bugs or help. Then you compose a long detailed email describing your problem and the steps you've taken blah blah blah. At which point you discover that your XML file has something slightly mispelled and changing that immediately fixes your problem. Or in a related scenario, you send out the email and then discover your error. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/

                B 1 Reply Last reply
                0
                • J Jared Parsons

                  I think my favorite is when you can't get something to work so you decide to email the authors and ask them about bugs or help. Then you compose a long detailed email describing your problem and the steps you've taken blah blah blah. At which point you discover that your XML file has something slightly mispelled and changing that immediately fixes your problem. Or in a related scenario, you send out the email and then discover your error. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/

                  B Offline
                  B Offline
                  Brian Van Beek
                  wrote on last edited by
                  #8

                  Hey jared...you should add a [^] clicky for your blog link..... Brian Van Beek Inside this room, all of my dreams become realities, and some of my realities become dreams. -Willy Wonka Just started a new blog, yeah! [^]

                  J 1 Reply Last reply
                  0
                  • B Brian Van Beek

                    Hey jared...you should add a [^] clicky for your blog link..... Brian Van Beek Inside this room, all of my dreams become realities, and some of my realities become dreams. -Willy Wonka Just started a new blog, yeah! [^]

                    J Offline
                    J Offline
                    Jared Parsons
                    wrote on last edited by
                    #9

                    Thanks. I forgot to add that back in. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/[^]

                    1 Reply Last reply
                    0
                    • L leppie

                      You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005

                      G Offline
                      G Offline
                      generic_user_id
                      wrote on last edited by
                      #10

                      Okay, this is how a dynamic language would solve the problem: irb(main):003:0> "sys.fun.bar::foo.blah".gsub( /\.|::/, '`\0`' ).split /`/ => ["sys", ".", "fun", ".", "bar", "::", "foo", ".", "blah"] For those who don't know the language - it's Ruby. Admittedly, the code may be a tad obfuscated, but it sure is a lot easier to grok than an entire page of C# code! Cheers, Diederik

                      L 1 Reply Last reply
                      0
                      • G generic_user_id

                        Okay, this is how a dynamic language would solve the problem: irb(main):003:0> "sys.fun.bar::foo.blah".gsub( /\.|::/, '`\0`' ).split /`/ => ["sys", ".", "fun", ".", "bar", "::", "foo", ".", "blah"] For those who don't know the language - it's Ruby. Admittedly, the code may be a tad obfuscated, but it sure is a lot easier to grok than an entire page of C# code! Cheers, Diederik

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #11

                        Again. I am looking for a generic (not generics) solution. But one could always build the Regex string. This could probably done similar in C#. Thanks for the idea, now I just hope .NET RE supports that (char) 0... xacc.ide-0.1.1 released! :) Download and screenshots

                        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