Re: algorithms + data structures = programs



arnuld said:

<snip>

r := 10*r + d[i]
d[i] := r div 2
r := r-2*d[i]

more *shocking* is its implmentation in PASCAL.

Okay, let's take a look:

program power(output);
{ decimal representation of negative powers of 2 }
const n = 10;
type digit = 0..9;
var i,k,r: integer;
d: array[1..n] of digit;
begin
for k := 1 to n do
begin
write('.');
r := 0;
for i := 1 to k - 1 do
begin
r := 10 * r + d[i];
d[i] := r div 2;
r := r - 2 * d[i];
write(chr(d[i] + ord('0')))
end ;
d[k] := 5;
writeln('5');
end
end .

Yes, okay, I agree. I'm appalled. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: How to delete commas and spaces when not needed ... S&R way, or macro way?
    ... Just change the two Const assignments to the column letter and sheet name where your data is located at... ... Dim R As Range ... values show up in these three ways, the first one being okay, the ... need to get rid of comma and space _after_ the text). ...
    (microsoft.public.excel.programming)
  • Re: pc_sample.c revisited; n = 1, zero-garbage collector...
    ... Okay. ... I was just considering the caching of nodes in the per-thread list as ... pc_region* const region, ... writers use mutex for mutual exclusion with ...
    (comp.programming.threads)
  • Re: algorithms + data structures = programs
    ... more *shocking* is its implmentation in PASCAL. ... {decimal representation of negative powers of 2} ... Yes, okay, I agree. ...
    (comp.programming)
  • Re: push_back problem.
    ... therefore it must be okay". ... The number of casts is minimal ... Could Cl_InitFilebe altered so it takes a const char * as parameter (it ...
    (microsoft.public.vc.stl)
  • Re: Anders Hejlsberg comment on immutable objects
    ... > interfaces, not long ago that you may find enlightening: ... you compare using interfaces to the const keyword and conclude that ... const is more concise and thus more powerful. ... Const is okay ...
    (microsoft.public.dotnet.languages.csharp)