A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

What is the most interesting algorithm you know?

  • This Question is Closed
  1. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Can you define what you mean by interesting?

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No :(

  3. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ok then the most interesting algorithm I know is one that I wrote. ;)

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \begin{array}l\color{#FF0000}{\text{Nice}}\text{ }\color{#FF7F00}{\text{what}}\text{ }\color{#FFE600}{\text{does}}\text{ }\color{#00FF00}{\text{it}}\text{ }\color{#0000FF}{\text{do?}}\text{ }\color{#6600FF}{\text{When}}\text{ }\color{#8B00FF}{\text{did}}\text{ }\color{#FF0000}{\text{you}}\text{ }\color{#FF7F00}{\text{write}}\text{ }\color{#FFE600}{\text{it?}}\end{array}

  5. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Which one lol.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \begin{array}l\color{#FF0000}{\text{Y}}\color{#FF0000}{\text{ }}\color{#FF7F00}{\text{o}}\color{#FF7F00}{\text{ }}\color{#FFE600}{\text{u}}\color{#FFE600}{\text{ }}\color{#00FF00}{\text{r}}\color{#00FF00}{\text{ }}\color{#0000FF}{\text{ }}\color{#0000FF}{\text{ }}\color{#0000FF}{\text{a}}\color{#0000FF}{\text{ }}\color{#6600FF}{\text{l}}\color{#6600FF}{\text{ }}\color{#8B00FF}{\text{g}}\color{#8B00FF}{\text{ }}\color{#FF0000}{\text{o}}\color{#FF0000}{\text{ }}\color{#FF7F00}{\text{r}}\color{#FF7F00}{\text{ }}\color{#FFE600}{\text{i}}\color{#FFE600}{\text{ }}\color{#00FF00}{\text{t}}\color{#00FF00}{\text{ }}\color{#0000FF}{\text{h}}\color{#0000FF}{\text{ }}\color{#6600FF}{\text{m}}\color{#6600FF}{\text{ }}\color{#8B00FF}{\text{ }}\color{#8B00FF}{\text{ }}\color{#FF0000}{\text{:}}\color{#FF0000}{\text{ }}\color{#FF7F00}{\text{-}}\color{#FF7F00}{\text{ }}\color{#FFE600}{\text{D}}\color{#FFE600}{\text{ }}\end{array}

  7. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah which one? lol

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \begin{array}l\color{#FF0000}{\text{Y}}\color{#FF7F00}{\text{o}}\color{#FFE600}{\text{u}}\color{#00FF00}{\text{r}}\color{#0000FF}{\text{ }}\color{#0000FF}{\text{f}}\color{#6600FF}{\text{a}}\color{#8B00FF}{\text{v}}\color{#FF0000}{\text{o}}\color{#FF7F00}{\text{r}}\color{#FFE600}{\text{i}}\color{#00FF00}{\text{t}}\color{#0000FF}{\text{e}}\color{#6600FF}{\text{ }}\color{#6600FF}{\text{o}}\color{#8B00FF}{\text{n}}\color{#FF0000}{\text{e}}\color{#FF7F00}{\text{!}}\end{array}

  9. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    They are all interesting to me.

  10. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \begin{array}l\color{#FF0000}{\text{The}}\text{ }\color{#FF7F00}{\text{only}}\text{ }\color{#FFE600}{\text{algorithm}}\text{ }\color{#00FF00}{\text{I've}}\text{ }\color{#0000FF}{\text{ever}}\text{ }\color{#6600FF}{\text{written}}\text{ }\color{#8B00FF}{\text{is}}\text{ }\color{#FF0000}{\text{this}}\text{ }\color{#FF7F00}{\text{one}}\text{ }\color{#FFE600}{\text{I'm}}\text{ }\color{#00FF00}{\text{using}}\text{ }\color{#0000FF}{\text{to}}\text{ }\color{#6600FF}{\text{color}}\text{ }\color{#8B00FF}{\text{my}}\text{ }\color{#FF0000}{\text{words}}\text{ }\color{#FF7F00}{\text{:(}}\end{array}

  11. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Okay, in 1980 I designed and coded a game that was subsequently ripped off by a major arcade game producer. I was writing it one a Vic-20. It was a side-scroller with a vehicle that could jump. I had to come up with an algorithm that kept all of the sprites in sync while on the ground, but followed each other like a train when jumping. Later I added an algorithm to add a somewhat similar effect while it was on the ground to simulate bumpy terrain.

  12. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    compared to my text-coloring algorithm, that's much cooler. Is that major arcade game producer still in business today?

  13. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yes

  14. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    the algorithm was actually really simple, but I was 12 at the time so I thought it was pretty genius.

  15. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    when I was 12, I didn't even know what an algorithm was :-P

  16. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    lol - neither did I.

  17. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    More recently, on my first foray into Java, I wrote one that put the appropriate appendix to a number (1st, 2nd, 3rd, 4th, etc.). Before the haters start flaming me, I know that is really easy, trivial, and NO BIG DEAL, but since it was not a requirement of the assignment and I was the only one in the class that even thought to do it, I was pretty proud of myself.

  18. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so if I type in "42" it appends "nd" to the end?

  19. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm... let's try doing it in C!

  20. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes.

  21. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The trick is doing the check during your parse routine.

  22. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/aJRon So in C, this will be a parsing loop that will include a step checking the last character in the string

  23. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes.

  24. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i'm not too good with parsing though :(

  25. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I don't know enough C to help you there.

  26. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Right; although C syntax is very similar to Java, string handling in both languages is very very different anyway :(

  27. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah I figured. Seems that way with most languages that are direct derivatives of each other.

  28. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    that appendix algorithm isn't so trivial in C :(

  29. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Well it didn't seem trivial when I first came up with it, but looking back it really wasn't that hard, but isn't that always the way it is?

  30. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/FIUgO so that's it in C++. Time to try it in C :-D

  31. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think you can actually do it without parsing. It just happened that the numbers that I wanted to append were parsed strings. Let me look at my old code and see what I can come up with.

  32. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is an interesting exercise in C :)

  33. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What you have looks about right. Does it work?

  34. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it seems to work

  35. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yup.

  36. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    So now see if you can do it without parsing.

  37. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Using int variables.

  38. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Should be able to do it with math. I'm trying to figure out the formula now.

  39. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    lol

  40. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What's so funny. I wait. I know. I'm a geek. Tell me something I don't already know.

  41. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think we might be able to use the bitwise operations and stuff to do it... or maybe the modulo operator.

  42. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    mod 10!

  43. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/IuM5n there we go

  44. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah that's what I was thinking. If Number % 10 = 1 then sNumber = Number + "st" and so forth.

  45. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yep did you test?

  46. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I don't like '11st' or '12nd' or '13rd' though... how do we fix those cases?

  47. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes I believe i have a check in there for those numbers.

  48. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/0enJt fixed

  49. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yep. Exactly.

  50. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think the C version is easy to do now :-D

  51. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    See. Told you it was trivial. ;)

  52. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm.... but my code won't do it properly if you give it something like 111 or 112 or 113 :(

  53. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Actually my java version is all on one line except for the check. resultsArea.append(horRule + yearCount + (yearCount == 1 ? "st" : (yearCount == 2 ? "nd" : (yearCount == 3 ? "rd" : "th"))) + " year\n");

  54. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    because you are only checking 11-13.

  55. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    right.... how do I fix it?

  56. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Mod 100

  57. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    but it will break if I give it a bigger number like 1111 or 1112 :-D

  58. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm. good point.

  59. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    See I didn't even have to think that far because we were dealing with a program where all of my parsed numbers were < 100

  60. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so in order for me to make it work for arbitrary numbers, I must use strings?

  61. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No shouldn't. I know this is calculable.

  62. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/G1Ydb so the string version is now working correctly.

  63. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Nice. That's one solution. I still think it's calculable. But I'm going to have to ponder it when I'm in math mode. I've been in writing mode all morning.

  64. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I shall ask this one in the Math section :-D I'm sure someone will answer it

  65. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm going to try to figure it out, but post your solution on ideone when you have it.

  66. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No I think mod 100 will work. Show me how it breaks.

  67. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/lYxkE

  68. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you're right... it works!

  69. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    112 mod 100 = 12 1112 mod 100 = 12 11112 mod 100 = 12 ad infinitum

  70. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yea!

  71. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Who says you can't learn anything from trivial things?

  72. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    See no that we know this if we EVER encounter a similar situation we will already be a step toward the solution.

  73. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is why I believe there is no such thing as a 'stupid question'

  74. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nice conversation guys! most interesting algorithm? Hmmm I think my favorite one will be written in 2012 by myself :)

  75. jagatuba
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah this was one of the more enlightening conversations that I've had lately. It's nice that i was able to walk away with something from it. I nominated agdgdgdgwngo "Best Question Asker" at the OS party because he always asks good questions. Okay well not always (what is a computer?).

  76. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I've thinking of asking a question like this for a couple of days, i'm more interested in interesting data structures though =) some algorithms i've found interesting are A* Bellman-Ford max flow min cost max flow they have quite a few uses

  77. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    A* is interesting because it's relatively old algorithm (first described in 1968, but a simpler form of it was proposed by Dijkstra in 1959), but very long lived - it's still the gold standard for path finding. Pretty much any video game uses A* or a variant of it for AI pathfinding to this day!

  78. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i read only beginning but java is more similar to c++ than c :P thats why its hard to play with strings in c

  79. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.