Re: Algorithms



Chris Smith wrote:

String[] syms = { "C", "L", "X","V","I"}
int[] vals = { 100, 50, 10, 5, 1 }

ans = "";

for (int i = 0; i < syms.length; i++)
{
while (value > vals[i])
{
ans += syms[i];
value -= vals[i];
}
}

return ans;


Where did you come up with that? See, that's what I mean, some people can just pull code like that out of the air and have it be elegant and work, whereas I sit and puzzle over how to approach a problem for hours before I give up and google for an algorithm. Patricia's points are correct, I assume but that method is still better than any I could come up with.
.



Relevant Pages

  • Re: Shortage of qualified Java programmers
    ... Chris Smith wrote: ... > Hmmm. ... I imagine if I had to use a system that didn't have a link to a ... > local copy of the standard library API documentation, I would use Google ...
    (comp.lang.java.programmer)
  • Re: still urgent help: functions
    ... EDU>> syms x t ... optimization toolbox use the function in that form. ... I'm trying to implement an algorithm and i need to derive ...
    (comp.soft-sys.matlab)
  • Re: jMusic
    ... Chris Smith wrote: ... >> get an URL, when I thought, naahh.. ... > into Google isn't really too awfully hard at all. ... Andrew Thompson ...
    (comp.lang.java.programmer)
  • Re: Need answers to .NET Interview questions
    ... Why not google the ans yourself? ... Egghead ... > needed answers to the below question link ...
    (microsoft.public.cert.exam.mcsd)
  • ANN : Software Algorithms in ANS Forth.
    ... I have started a collection of ANS Forth algorithms on my website: ... tean.f is a New version of TEA the Tiny Encryption Algorithm. ...
    (comp.lang.forth)