anonymous
  • anonymous
What is the most interesting algorithm you know?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
jagatuba
  • jagatuba
Can you define what you mean by interesting?
anonymous
  • anonymous
No :(
jagatuba
  • jagatuba
Ok then the most interesting algorithm I know is one that I wrote. ;)

Looking for something else?

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

More answers

anonymous
  • anonymous
\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}
jagatuba
  • jagatuba
Which one lol.
anonymous
  • anonymous
\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}
jagatuba
  • jagatuba
Yeah which one? lol
anonymous
  • anonymous
\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}
jagatuba
  • jagatuba
They are all interesting to me.
anonymous
  • anonymous
\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}
jagatuba
  • jagatuba
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.
anonymous
  • anonymous
compared to my text-coloring algorithm, that's much cooler. Is that major arcade game producer still in business today?
jagatuba
  • jagatuba
yes
jagatuba
  • jagatuba
the algorithm was actually really simple, but I was 12 at the time so I thought it was pretty genius.
anonymous
  • anonymous
when I was 12, I didn't even know what an algorithm was :-P
jagatuba
  • jagatuba
lol - neither did I.
jagatuba
  • jagatuba
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.
anonymous
  • anonymous
so if I type in "42" it appends "nd" to the end?
anonymous
  • anonymous
hmm... let's try doing it in C!
jagatuba
  • jagatuba
Yes.
jagatuba
  • jagatuba
The trick is doing the check during your parse routine.
anonymous
  • anonymous
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
jagatuba
  • jagatuba
Yes.
anonymous
  • anonymous
i'm not too good with parsing though :(
jagatuba
  • jagatuba
I don't know enough C to help you there.
anonymous
  • anonymous
Right; although C syntax is very similar to Java, string handling in both languages is very very different anyway :(
jagatuba
  • jagatuba
Yeah I figured. Seems that way with most languages that are direct derivatives of each other.
anonymous
  • anonymous
that appendix algorithm isn't so trivial in C :(
jagatuba
  • jagatuba
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?
anonymous
  • anonymous
http://ideone.com/FIUgO so that's it in C++. Time to try it in C :-D
jagatuba
  • jagatuba
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.
anonymous
  • anonymous
This is an interesting exercise in C :)
jagatuba
  • jagatuba
What you have looks about right. Does it work?
anonymous
  • anonymous
it seems to work
jagatuba
  • jagatuba
Yup.
jagatuba
  • jagatuba
So now see if you can do it without parsing.
jagatuba
  • jagatuba
Using int variables.
jagatuba
  • jagatuba
Should be able to do it with math. I'm trying to figure out the formula now.
anonymous
  • anonymous
lol
jagatuba
  • jagatuba
What's so funny. I wait. I know. I'm a geek. Tell me something I don't already know.
anonymous
  • anonymous
I think we might be able to use the bitwise operations and stuff to do it... or maybe the modulo operator.
anonymous
  • anonymous
mod 10!
anonymous
  • anonymous
http://ideone.com/IuM5n there we go
jagatuba
  • jagatuba
Yeah that's what I was thinking. If Number % 10 = 1 then sNumber = Number + "st" and so forth.
jagatuba
  • jagatuba
Yep did you test?
anonymous
  • anonymous
I don't like '11st' or '12nd' or '13rd' though... how do we fix those cases?
jagatuba
  • jagatuba
Yes I believe i have a check in there for those numbers.
anonymous
  • anonymous
http://ideone.com/0enJt fixed
jagatuba
  • jagatuba
Yep. Exactly.
anonymous
  • anonymous
I think the C version is easy to do now :-D
jagatuba
  • jagatuba
See. Told you it was trivial. ;)
anonymous
  • anonymous
hmm.... but my code won't do it properly if you give it something like 111 or 112 or 113 :(
jagatuba
  • jagatuba
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");
jagatuba
  • jagatuba
because you are only checking 11-13.
anonymous
  • anonymous
right.... how do I fix it?
jagatuba
  • jagatuba
Mod 100
anonymous
  • anonymous
but it will break if I give it a bigger number like 1111 or 1112 :-D
jagatuba
  • jagatuba
hmm. good point.
jagatuba
  • jagatuba
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
anonymous
  • anonymous
so in order for me to make it work for arbitrary numbers, I must use strings?
jagatuba
  • jagatuba
No shouldn't. I know this is calculable.
anonymous
  • anonymous
http://ideone.com/G1Ydb so the string version is now working correctly.
jagatuba
  • jagatuba
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.
anonymous
  • anonymous
I shall ask this one in the Math section :-D I'm sure someone will answer it
jagatuba
  • jagatuba
I'm going to try to figure it out, but post your solution on ideone when you have it.
jagatuba
  • jagatuba
No I think mod 100 will work. Show me how it breaks.
anonymous
  • anonymous
http://ideone.com/lYxkE
anonymous
  • anonymous
you're right... it works!
jagatuba
  • jagatuba
112 mod 100 = 12 1112 mod 100 = 12 11112 mod 100 = 12 ad infinitum
jagatuba
  • jagatuba
Yea!
jagatuba
  • jagatuba
Who says you can't learn anything from trivial things?
jagatuba
  • jagatuba
See no that we know this if we EVER encounter a similar situation we will already be a step toward the solution.
anonymous
  • anonymous
This is why I believe there is no such thing as a 'stupid question'
anonymous
  • anonymous
nice conversation guys! most interesting algorithm? Hmmm I think my favorite one will be written in 2012 by myself :)
jagatuba
  • jagatuba
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?).
anonymous
  • anonymous
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
anonymous
  • anonymous
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!
anonymous
  • anonymous
i read only beginning but java is more similar to c++ than c :P thats why its hard to play with strings in c

Looking for something else?

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