Re: adding numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

"Derek Parnell" wrote:

> That all depends on what the specification is. Some examples might help
> here...
>
> So far we know that
>   {1,6} ==> {16}
> must be true
>
> but we are assuming
>   {23,17} ==> {247}
>
> or this
>   {23, 17} = {2317}
>
> That is why clear specifications are so important for programming.

Here's a quick kluge that deals with some of the apparent problems, but
introduces a whole heap of others ;) ...:

-- Warning! No error or bounds checking in this code!
sequence in, outseq
integer out
in = {1, 23, 456}
outseq = ""
out    = 0  -- want this to be 123456

for i = 1 to length(in) do
    outseq &= sprintf("%d", in[i])-'0'
end for
for i = 1 to length(outseq) do
    out = out * 10 + outseq[i]
end for

? out

Carl

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu