Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Zadachka... bratyam-programmistam.

1 view
Skip to first unread message

Slava BORISOV

unread,
Feb 23, 1995, 11:03:09 AM2/23/95
to
> : ZAPEHUT' TEKST V SAM TEKST NE VOZMOZHNO !!!! TAK KAK ETO INFINITE
> : REKURSIYA !! BLOW ME !

> Vo-pervyh, zapIhnut'. A vo-vtoryh, ya mogu postanut' otvet na C.
> V detststve ya napisal na Pascale, a vot davecha sam vspomnil
> zadachu i ot nechego delat', pod pivo, napisal na C.

> A poka dayu podskazku: v C est' operator cikla!

Esche podskazka : krome operatora cikla tam est' vozmozhnost'
zapihnut' ljubuju strochku v pamjat' i napechatat' ee bez
prjamogo citirovanija.

Slava


Kisa

unread,
Feb 23, 1995, 4:01:03 PM2/23/95
to
Michael B. Cherkassoff (mi...@einstein.math.ubc.ca) wrote:

: A poka dayu podskazku: v C est' operator cikla!

Kakoj?

Kisa vse reshaet v ume, computers are for wimps...
--
| \_/ |
| o.o |
==( _ )==
-U-----U-

Dima Volodin

unread,
Feb 23, 1995, 4:21:12 PM2/23/95
to
Igor Chudov (ich...@iii1.iii.net) wrote:

> Let's choose a language, say, xyuscal, and call the set of all valid
> programs in xyuscal P.

[dal'neishaya huynia snesena]

Vo, bliad', a escho - VMK. Uchil, nebos', pro mahinu Turinga-to.

> HU XEPA CE6E!!!

Ni hera sebe studenty poshli...

> - Igor. Check SCS Yellow Pages: http://www.iii.net/users/ichudov

Dima
--
"Wine is an unsophisticated drink. They just
stomp on grapes in their bare feet."
MJ

Dmitrii Manin

unread,
Feb 24, 1995, 11:44:12 AM2/24/95
to

In article <3ih1ef$5...@cutter.clas.ufl.edu> ale...@phys.ufl.edu (Alex Kuznetsov) writes:

o
o Guys, do you mind really posting the solution, at least schematically?

The simplest possible solution, in an appropriate pseudo-language:

p "p "

where `p' is the operator that prints the argument string, then a
double quote, then string again and double quote again.

Or, in UNIX shell:

echo2 echo2

where `echo2' is a script or program that prints all its arguments
twice.

You got the idea. Here's a C implementation, which is more difficult
due to syntax requirements. (It's a rather long string, to avoid
dealing with newlines). Try it.

extern char s[];main(){int i=0;for(;i<2;i++){printf(s);putchar(34);if(i==1)putchar(';');}}char s[]="extern char s[];main(){int i=0;for(;i<2;i++){printf(s);putchar(34);if(i==1)putchar(';');}}char s[]=";
--
Burime No. 73

Peterburgskaya Blagochinnaya
Baron Petrov, ot revnosti ustav, natyagivaet chyornye perchatki,
K zhene v al`kov kradyotsya, kak udav, i dushit, ostavlyaya otpechatki.
``Ba-bahh!''--na Petropavlovskoj byot pushka--
Uzh polden`... Net, zhenit'ba--ne igrushka.

Play at http://camelot.rockefeller.edu/~manin/br.cgi

Simon Hawkin

unread,
Feb 24, 1995, 7:17:00 PM2/24/95
to
Hi,

On 24 Feb 1995 17:00:17 -0500,
ich...@iii.net (Igor Chudov) wrote:

*> : Vy, ctho sovsem tam okhueli v vashikh universitetakh ? Eto classicheskaya
*> : zadacha, est' neskol'ko stol' zhe classicheskikh reshenii.
*>
*> A v chem problema? Ja ne ponimaju, kak iz togo chto eto klassicheskaja
*> zadacha, sleduet, chto ja sovsem ohuel?

Ne sleduet. Potomu chto ty ne v svoem universitete. Znachit, ne
sovsem oxuel.

CEMA

Igor Chudov

unread,
Feb 25, 1995, 2:18:39 PM2/25/95
to
Paul L. Klark (pa...@CS.Arizona.EDU) wrote:

: In article <3iglge$3...@iii1.iii.net>, Igor Chudov <ich...@iii.net> wrote:
: >Let's choose a language, say, xyuscal, and call the set of all valid
: >programs in xyuscal P.

: I like this name !

: >Dalee pojdet nabor teorem i dok-v.

: Kotorye, k sozhaleniyu, neverny. Pomimo tehnicheskih detalej,
: osnovnaya teorema prosto lozhna. Hotya sdelana s chustvom.

: >Jazyk xyuscal dostatochno moschnyj: my mozhem napisat' interpretator
: >xyuscala na xyuscale.

: Kstati, mysli po povodu: kto-nibud' znaet "nedostatochno" moshnyj yazyk ?
: U menya takoe vpechatlenie, chto lyuboj yazyk s uslovnymi
: operatorami, ciklami i (potencial'no) neogranichennoj
: pamyat'yu - dostatochno moshnyj v lyubom smysle.
: V konce koncov, na vseh izvestnyh yazykah mozhno
: smodelirovat' mashinu T'yuringa.

Ny konechno, vse jazyki kotorymi pol'zyjutsa programmisty, moschnye - a
inache kto by stal imi pol'zovatsa?


: >Vvedem funktsiju output( c ) - to, chto napechataet programma c esli ee
: >zapustit'.

: S kakim inputom ?

My rassmatrivaem programmy s nulevym inputom - dlia nas eto dostatochno.
No v tselom my s uspehom mogli by vvesti funktsiju output( c, i ) - vyvod o
programmy p s vvodom i.

: >(*)Teorema 1: Dlia lyubogo convertora c belonging to C suschestvuet
: >programma p takaja, chto output(c(p)) = output(c)

: Naverno, hotel napisat' output(c(p)) = output(p) ?

Da, pardon.

: Potomu kak dlya c nuzhen input.
: Teorema, ochevidno, neverna. Kontrprimer: napishem konverter C
: kotoryj perevodit programmu P v NEekvivalentnuyu programmu:
: C(x) {
: print "Ogo!!!"
: execute x
: }

: Ochevidno, chto C(P) vsegda napechataet BOL'SHE, chem P.
: Takim obrazom C(P) != P dlya vseh P, kotorye zavershayutsya.

Kontrprimer (kotoryj pokazyvaet, chto ja prav): Let x be

x() {
while( true ) {
print( "Ogo!!!" );
}
}

Ochevidno, chto convertor C NE IZMENIT vyvoda programmy x :
output(C(x))=output(x)

: >Napomnimm, chto P1 - eto tozhe programma na xyuscale. Zametim takzhe,
: >chto neravenstvo togo, chto pechatajut dve programmy VSEGDA mozhet
: >byt' ustanovleno za konechnoe vremia.

: Neravenstvo - da. Ravenstvo - net. A u tebya ispol'zuetsya,
: po vidimomu, i to, i drugoe.

Ne-a. U menia ispol'zuetsa tol'ko neravenstvo.

: >P2(x) {
: > execute x > /dev/null # ignore output, just wait until x ends
: > print "Q"
: >}

: Esli x ne zavershaetsya, to P2(x) ne zavershaetsya tozhe. Horosho.


: >P3(x) {
: > execute P2(x) > file1 & # zapuskaem v parallel'
: > execute P1(P2(x)) > file2 & # P2(x) i P1(P2(x))
: >
: > while( true ) {
: > if( not_empty( file2 ) ) {
: > print "X does not hang";
: > exit;
: > }
: >
: > if( not_empty( file1 ) and file1 != "Q" ) {
: > print "X hangs!";
: > exit;
: > }
: > }
: >}
: >Legko videt', chto algoritm P3

: Legko videt', chto P3 ne yavlyaetsya algorithmom, kotoryj, po opredeleniyu,
: zavershaetsya dlya lyubogo inputa.

Zavershaetsa, zavershaetsa.

: >po lyuboj programme x za KONECHNOE vremia
: >opredeliajet, zavisnet x ili net.

: Esli x visnet, to P2, i vsya tvoya P3 visnet. I nichego ne napechataet.
: Tak chto NE DLYA LYUBOGO x.

Pardon - ja pereputal v P3 file1 i file2:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
P3(x) {
execute P2(x) > file1 & # zapuskaem v parallel'
execute P1(P2(x)) > file2 & # P2(x) i P1(P2(x))

while( true ) {
if( not_empty( file1 ) ) {
print "X does not hang";
exit;
}

if( not_empty( file2 ) and file2 != "Q" ) {
print "X hangs!";
exit;
}
}
}


===============================


: >Takim obrazom, p0 = output(p0). My pokazali suschestvovanie programmy p0
: >na jazyke xyuscal, kotoraja pechataet svoj sobstvennyj text.

: Yours was a nice try. It seems to me that VALID proof
: should consider specific output statement syntax of xyuscal.

Oh well, it really is a valid proof. When I write all those prints I of
course do not mean a specific syntax, but rather that at a certain moment
P3 should print a certain value.


: >Etot sposob stavit tochku na voprose Kostina.

: Etot sposob dokazyvaet, chto tochki ne tak legko rasstavlyat',
: kak kazhetsya :)

: >Zamechanie 3(liricheskoe): Dlia menia eta teorema - dokazatel'stvo
: >suschestvovanija Computer Science kak Science.

: I dokazatel'stvo neobhodimosti bolee tshatel'nogo izucheniya onoj. :)

Da, ty prav. Akkuratnee mne nado byt'. Izvinite... No v tselom vsyo ravno
poluchilos' - posle zameny file1 na file2 i naoborot. :)
--
- Igor. SCS Yellow Pages: http://www.iii.net/users/ichudov/index.html

43rd Law of Computing: Anything that can go wrT&^*#
Segmentation violation -- core dumped
--
- Igor. SCS Yellow Pages: http://www.iii.net/users/ichudov/index.html

43rd Law of Computing: Anything that can go wrT&^*#
Segmentation violation -- core dumped

Andrew Prihodko

unread,
Feb 26, 1995, 3:05:47 PM2/26/95
to
In article <3im78o$8...@iii1.iii.net>, ich...@iii1.iii.net (Igor Chudov) says:
>
>Andrew Prihodko (prih...@fas.harvard.edu) wrote:
>: In article <3ie2b6$7...@iii1.iii.net>, ich...@iii1.iii.net (Igor Chudov) says:
>: >
>: >A vot vam takaja prostaja zadacha:
>: >
>: >Napisat' na C (Pascale, Fortrane) programmu, kotoraja pechataet V TOCHNOSTI
>: >svoj sobstvennyj tekst - ot pervogo i do poslednego byta. Razumeetsa,
>: >zapreschaetsa ispol'zovat' gryaznye tryuki tipa chtenija teksta programmy
>: >s diska i t.p.
>
>: GW-BASIC podhodit?
>
>: 10 REM Etoi zadache 132 goda.
>: 20 LLIST
>
>: I vse. Nebos', griaznym triukom nazovesh'.
>
>Ugadal, gryaznyj tryuk. Ochen' dazhe gryaznyj tryuk.

Rebiata, vy chto, humor bez znachkov tipa :-) opredeliat'
ne mozhete?

ETO SHUTKA BYLA!!!

Andrew Prihodko
prih...@fas.harvard.edu http://fas-www.harvard.edu/~prihodko

Andrew Prihodko

unread,
Feb 26, 1995, 3:21:38 PM2/26/95
to
In article <3im85r$8...@iii1.iii.net>, ich...@iii1.iii.net (Igor Chudov) says:
>
>Andrew Prihodko (prih...@fas.harvard.edu) wrote:
>: In article <3ie2b6$7...@iii1.iii.net>, ich...@iii1.iii.net (Igor Chudov) says:
>: >
>: >A vot vam takaja prostaja zadacha:
>: >
>: >Napisat' na C (Pascale, Fortrane) programmu, kotoraja pechataet V TOCHNOSTI
>: >svoj sobstvennyj tekst - ot pervogo i do poslednego byta. Razumeetsa,
>: >zapreschaetsa ispol'zovat' gryaznye tryuki tipa chtenija teksta programmy
>: >s diska i t.p.
>
>: Here is another one:
>
>: Write a program that would swap values of two variables, A and B. The goal
>: is to avoid compiler-specific commands or operators (like SWAP in GW-BASIC)
>: and make the simplest code possible. Assume that we are using an ideal
>: computer. By the way, the solution works on most computers.
>
>integer a, b;
>a := 3245;
>b := 367254; { Preparation - does not count. }
>
> a := a xor b; { Swap Operation itself }
> b := b xor a; { Note that it does not use a temporary variable }
> a := a xor b; { to keep swapped value - otherwise it
> would be simple as shit, but not so much fun }
> { Isn't that cool? }
>
>Do you like it? Let me know. Andrew, sorry if you wanted us to send it to
>you instead of posting, but I thought it is simple enough to be posted right
>away.

Correct. Here is a bit simpler one.

A = A + B;
B = A - B;
A = A - B;

Igor Chudov

unread,
Feb 26, 1995, 3:25:40 PM2/26/95
to
Paul L. Klark (pa...@CS.Arizona.EDU) wrote:
: In article <mmg.342....@interaccess.com>,
: Michael G. Minkovski <m...@interaccess.com> wrote:
: >In article <3iip51$3...@baskerville.CS.Arizona.EDU>
: >pa...@CS.Arizona.EDU (Paul L. Klark) writes:
: >Vot imenno. Delo v tom, chto Igor' rassmatrivaet i te programmy, kotorye ne
: >zavershaiutsia.

: Horosho. Zamechatel'no. Tol'ko togda (esli my ne ogranichimsya
: programmami, kotorye ostanavlivayutsya, dlya nahozhzhdeniya fiksirovannyh
: tochek konvertera), vse ego postroenie programmy, kotoraya
: pechataet svoj sobstvennyj tekst, ne rabotaet.
: Eta fiksirovannaya tochka mozhet visnut'.

: Odno delo - ispol'zovat' visnushie programmy dlya dokazatel'stva
: teoremy. Eto - sovershenno zakonnyj tryuk. Drugoe delo,
: chto ego konechnyj rezul'tat - programma, pechatayushaya samu sebya -
: po ego postroeniyu sama vpolne mozhet visnut'.

Neverno. Ja tak i ne postroil samopechatajuschujusa programmu. Ja dokazal,
chto ona suschestvuet.

: >>>P3(x) {
: >>> execute P2(x) > file1 & # zapuskaem v parallel'
: >>> execute P1(P2(x)) > file2 & # P2(x) i P1(P2(x))
: >>>
: >>> while( true ) {
: >>> if( not_empty( file2 ) ) {
: >>> print "X does not hang";
: >>> exit;
: >>> }
: >>>
: >>> if( not_empty( file1 ) and file1 != "Q" ) {
: >>> print "X hangs!";
: >>> exit;
: >>> }
: >>> }
: >>>}

: >>Legko videt', chto P3 ne yavlyaetsya algorithmom, kotoryj, po opredeleniyu,
: >>zavershaetsya dlya lyubogo inputa.

: >V Igorevom formalizme P3 vsegda zavershaetsia (sm. nizhe)


: >>Esli x visnet, to P2, i vsya tvoya P3 visnet. I nichego ne napechataet.
: >>Tak chto NE DLYA LYUBOGO x.

: >Esli x visnet, to P2 visnet i, sootvetstvenno, output(P2(x)) nulevoi.
: >Togda po opredeleniiu P1 ego output nenulevoi, i P3 zakanchivaet rabotu.
: >Vopros - kogda.

: Vot chto znachit - kto yasno myslit, tot yasno izlagaet.
: Teper'-to ya ponyal, chto Igor hotel zapuskat' ne P2(x)
: i P1(P2(x)) v parallel', a P2(x) i P1(P2)(x) (to est'
: propustit' P2 cherez konverter P1, a zatem napustit' resul'tat
: ego na input x). No iz original'nogo teksta ponyat' eto bylo neprosto.
: Vozrazhenie protiv teoremy snimayutsya. Tol'ko (sm. vyshe)
: togda etu teoremu nikak ne primenit' pri postroenii programmy,
: kotoraya pechataet samu sebya.

Eto _pochti_ verno, no ne sovsem. Eta teorema dejstvitel'no ne daet nam
teksta samopechatajuschejsa programmy, no garantiruet ee existence.

Vot vam sposob postroit' takuju programmy, kotoryj opiraetsa na dokazannuju
teoremu.

Poskol'ku mnozhestvo vseh programm schetno (programmy - eto simvol'nye
stroki), budem perebirat' vse programmy odna za drugoj, poka ne
natknemsa na samopechatajuschujusa programmu. A my na nee natknemsa (sm.
vyshe). Eto, konechno, chisto teoreticheskij podhod, no absolutno
korrektnyj i kontruktivnuj, hotia i ne realistichnyj.

Greg Landsberg

unread,
Feb 26, 1995, 4:16:12 PM2/26/95
to
In <3iqoee$a...@iii1.iii.net> ich...@iii1.iii.net writes:

> Dmitri Zaykin (zay...@stat.ncsu.edu) wrote:
>
> : // (swap x1 and x2)
>
> : x1 = x1 + x2;
> : x2 = x1 - x2;
> : x1 = x1 - x2;
>
> : am I right? (Chudov would know, he's a king ;))
>
> I am not a king, I am just a poor consultant:) Actually, it is _nearly_
> right. As soon as x1+x2 > MAXINT, it is wrong on a real computer. xor
> is a bit better because it does not have this problem.

...saying nothing about the fact that xor is much faster than addition or
subtraction! Also, with xor it's possible to write one subroutine which
swaps both real and int variables, although it's a violation of K&R. On
FORTRAN, however, it is perfectly OK and works for INTEGER, REAL and
LOGICAL.

(Just having a dull afternoon in preparation for the evening...)

Geg

Simon Streltsov

unread,
Feb 26, 1995, 4:17:25 PM2/26/95
to
Another spin on the same topic:
it seems that we have 10^n gurus here who can solve the problem.
Unfort. many of us are so full of the fact that they can do something,
that the next stage - how to give ot the reader/listener -
kindly and gently - does not even enters the mind.

Probably, many of you noticed the same problem of many of Russian
prof-s who talk in the Western universities or conferences.

So, how about a "problem":
write a one-page solution and explanation that will
be very easy to understand.

Simcha, who increases in Adar
and decreases in Av
and speaks
Russian with Jewish accent
English with Russian accent
Hebrew with English accent
all year long
( and writes also)

Greg Landsberg

unread,
Feb 27, 1995, 2:46:26 AM2/27/95
to
In <3irfm0$p...@taco.cc.ncsu.edu> zay...@stat.ncsu.edu writes:

>
> In article <3iqr2s$k...@fnnews.fnal.gov>, LAND...@D0GS05.FNAL.GOV (Greg Landsberg) writes:
>
>
> |> ...saying nothing about the fact that xor is much faster than addition or
> |> subtraction!
>

> Even though it is not a C-newsgroup, (I promise not to post anymore)
> the following code (with all optimizations disabled)
> produces subsequent output:
>
> 7 <- sec elapsed for XOR
> 6 <- sec elapsed for +

> Now how about "much faster" ?
>

Well, that I call a misuse of an education. Right, modern computers do xor
and +/-/*/etc with the same speed. Nevertheless from the point of view of
complication, or from Turing machine's point of view any bitwise logical
operation is simpler than addition. And subtraction is one operation more
complicated than addition. That's why in good old times programmers wrote
code with + and * instead of - and /.

Ciao,

Greg

Igor Chudov

unread,
Feb 27, 1995, 11:20:02 AM2/27/95
to
Dmitri Zaykin (zay...@stat.ncsu.edu) wrote:

: LAND...@D0GS05.FNAL.GOV (Greg Landsberg) writes:
: |> ...saying nothing about the fact that xor is much faster than addition or
: |> subtraction!

: Even though it is not a C-newsgroup, (I promise not to post anymore)


: the following code (with all optimizations disabled)
: produces subsequent output:

: 7 <- sec elapsed for XOR
: 6 <- sec elapsed for +

: Now how about "much faster" ?

<program deleted>

Well, the data that you posted is totally insufficient to prove anything.
I can explain why if you want. If it was 70 and 60, I would buy it,
but 6 and 7 can be just related to discreteness of the Unix timer (second
by second). But it is interesting. Can you increase tesing time 10-50 times?

Dmitri Zaykin

unread,
Feb 27, 1995, 2:32:53 PM2/27/95
to

Turing machine? I thought you were talking about "subroutines in C"
and xor-ing real-s in Fortran (in good old times), weren't you?


--

Dima

FORTRAN is not dead, it just smells that way

Simon Streltsov

unread,
Feb 27, 1995, 2:40:11 PM2/27/95
to
Alex S. Katz (a...@netcom.com) wrote:

: >So, how about a "problem":

: >write a one-page solution and explanation that will
: >be very easy to understand.

: I believe Dima Manin already did. In a one-liner, I think.

No, not one-line solution, but one-page _easy explanation_.

Check yourself - catch an average fresh-[wo]man - and give him/her
the explanation. If he/she can repeat it after 10 minutes of
reading - than it is OK.


Simcha Streltsov, _Former_ Adar Rabbi of S.C.Soviet
-------------------------
please, only Kosher lePesach homentashen
all others will be returned unopened.

p.s. This sig expired, but nobody have sent me real
homentashen anyway

Matt Nemenman

unread,
Feb 27, 1995, 5:10:53 PM2/27/95
to
> *> Tak naveyalo: would an empty program produce an empty
> *> output?
> No. There is a difference between no output and an empty output.
>
> CEMA

What difference?

Matvey


Dima Volodin

unread,
Feb 27, 1995, 6:35:16 PM2/27/95
to
Simon Hawkin (ce...@cs.umd.edu) wrote:
> Hi,

> On 23 Feb 1995 21:21:12 GMT,
> d...@sprintlink.net (Dima Volodin) wrote:

> *> Vo, bliad', a escho - VMK. Uchil, nebos', pro mahinu Turinga-to.

> Nu, odnoj TM nedostatochno. Interesno, chemu vse zhe uchili na
> VMK.

A? To est' - kak nedostatochno? Ty chego?

> *> Ni hera sebe studenty poshli...

> Eto verno. A ran'she-to kakie byli ?

Kruche. A trava - zelenee.

> CEMA

Igor Chudov

unread,
Feb 27, 1995, 6:47:53 PM2/27/95
to
Dima Volodin (d...@sprintlink.net) wrote:
: Andrew Prihodko (prih...@fas.harvard.edu) wrote:

: > A = A + B;


: > B = A - B;
: > A = A - B;

: Doesn't necessarily work for all bit patterns on all computers. There
: is such thing as integer overflow on some machines.

Just wondering which ones. Never seen any, although they possibly exist.

Simon Hawkin

unread,
Feb 27, 1995, 8:51:39 PM2/27/95
to
Hi,

On 26 Feb 1995 00:53:29 GMT,
sim...@bu.edu (Simon Streltsov) wrote:

*> Simon Hawkin (ce...@cs.umd.edu) wrote:
*>
*> : *> Tak naveyalo: would an empty program produce an empty
*> : *> output?
*>
*> : No. There is a difference between no output and an empty output.
*>
*> Vam bez siropa? Bez kakogo?

Not, it's like the difference between "No file" and "Empty
file".

CEMA

Paul L. Klark

unread,
Feb 28, 1995, 12:13:09 AM2/28/95
to
In article <3ilm8b$e...@taco.cc.ncsu.edu>,

Dmitri Zaykin <zay...@stat.ncsu.edu> wrote:
> // (swap x1 and x2)
> x1 = x1 + x2;
> x2 = x1 - x2;
> x1 = x1 - x2;

Now imagine that swap(x1,x2) is a procedure in Pascal program,
and parameters x1 and x2 are passed by reference:
swap(var x1,x2:integer)
begin


x1 = x1 + x2;
x2 = x1 - x2;
x1 = x1 - x2;

end

(Or you even do your favorite tricks with XOR to avoid overflow
problems)

The punchline: wouldn't it be fun if you call it like
swap(a[i],a[j]) when i=j ?
You would expect it to be a NO-OP, right ? (At least
while reading the code)
But the above code will set a[i] to 0.
I think that would lead to a really cool program.
You never know if you get a core dump.

-paul,
non-deterministic programs adept.

Simon Hawkin

unread,
Feb 28, 1995, 11:07:05 AM2/28/95
to
Hi,

On 27 Feb 1995 22:10:53 GMT,
Matt Nemenman <ma...@informix.com> wrote:

*> > *> Tak naveyalo: would an empty program produce an empty
*> > *> output?
*> > No. There is a difference between no output and an empty output.
*>
*> What difference?

It's like between "no file abcde" and "empty file abcde".

CEMA

Dima Volodin

unread,
Feb 28, 1995, 1:13:20 PM2/28/95
to

Oh bliad'... I eto - VMK... O tempora...

Greg Landsberg

unread,
Feb 28, 1995, 2:01:32 PM2/28/95
to
In <3ivqro$1...@huron.eel.ufl.edu> ich...@iii1.iii.net writes:

> Dima Volodin (d...@sprintlink.net) wrote:


> : Igor Chudov (ich...@iii1.iii.net) wrote:
> : > Dima Volodin (d...@sprintlink.net) wrote:
> : >

> : > : Doesn't necessarily work for all bit patterns on all computers. There


> : > : is such thing as integer overflow on some machines.
>
> : > Just wondering which ones. Never seen any, although they possibly exist.
>
> : Oh bliad'... I eto - VMK... O tempora...
>

> Dima, ne mog by ty upomyanut' paru primerov mashin s integer overflow?

Hot' ya i ne Dima, no vpolne s nim soglasen :-) A mashin takih do figa:
SGI, VAXes, DEC Alpha, ... Kazhetsya, vse eto bylo dazhe na CM-4 i uzh
navernyaka na IBM or EC.

Greg

Igor Chudov

unread,
Feb 28, 1995, 2:19:28 PM2/28/95
to
Greg Landsberg (LAND...@D0GS05.FNAL.GOV) wrote:
: In <3ivqro$1...@huron.eel.ufl.edu> ich...@iii1.iii.net writes:
: > Dima, ne mog by ty upomyanut' paru primerov mashin s integer overflow?
: Hot' ya i ne Dima, no vpolne s nim soglasen :-) A mashin takih do figa:
: SGI, VAXes, DEC Alpha, ... Kazhetsya, vse eto bylo dazhe na CM-4 i uzh
: navernyaka na IBM or EC.

Thanks! I actually worked on VAXes and CM-4 for a while, but did not know
about the integer overflow thing.

George Chesakov

unread,
Mar 2, 1995, 2:50:55 AM3/2/95
to
Andrew Prihodko writes:

|> Dmitri Zaykin says:
|> >
|> > // (swap x1 and x2)
|> >
|> > x1 = x1 + x2;
|> > x2 = x1 - x2;
|> > x1 = x1 - x2;
|> >
|> >
|> > am I right? (Chudov would know, he's a king ;))

|> Absolutely! There are some more ways to do it (without temporary
|> variables), but this is the one I like the best.

what about reals and overflow?

--
naive

Stupidity is a choice.

Leo Kaushansky

unread,
Mar 2, 1995, 12:26:15 PM3/2/95
to
In article <3iubd5$c...@baskerville.CS.Arizona.EDU>,

Paul L. Klark <pa...@CS.Arizona.EDU> wrote:
>Now imagine that swap(x1,x2) is a procedure in Pascal program,
>and parameters x1 and x2 are passed by reference:
>swap(var x1,x2:integer)
>begin
> x1 = x1 + x2;
> x2 = x1 - x2;
> x1 = x1 - x2;
>end
>
>(Or you even do your favorite tricks with XOR to avoid overflow
>problems)
>
>The punchline: wouldn't it be fun if you call it like
>swap(a[i],a[j]) when i=j ?
>You would expect it to be a NO-OP, right ? (At least
>while reading the code)
>But the above code will set a[i] to 0.
>I think that would lead to a really cool program.
>You never know if you get a core dump.
>
>-paul,
>non-deterministic programs adept.

If I may butt in:

To avoid this problem, you can put a simple if statement that makes sure
the above operations are performed only when x1 != x2.
Makes this procedure foolproof...:)


--
_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_
| Leo Kaushansky l...@mks.com |
| QA/Testing Mortice Kern Systems |
|_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_|

Paul L. Klark

unread,
Mar 2, 1995, 8:25:39 PM3/2/95
to
In article <3j4v3o$r...@ia.mks.com>, Leo Kaushansky <l...@mks.com> wrote:
>To avoid this problem, you can put a simple if statement that makes sure
>the above operations are performed only when x1 != x2.
>Makes this procedure foolproof...:)

Yes, that's right. (Even if the two variables are actually different,
it still doesn't make sense to swap them if they have equal values).
But. In this case the procedure will have
three arithmetic operations, three assignments and one
conditional. Which is probably more trouble than
allocating a temporary and doing just a classical swap.

Same argument go for the solution which uses Ada-style
copy-in/copy-out as opposed to standard Pascal call by reference.
It's just more trouble copying parameters back and forth than
using a temporary.

-paul

Alexy V. Khrabrov

unread,
Mar 3, 1995, 7:28:27 AM3/3/95
to
In article <3j5r6j$k...@baskerville.CS.Arizona.EDU> pa...@CS.Arizona.EDU (Paul L. Klark) writes:
>Same argument go for the solution which uses Ada-style
>copy-in/copy-out as opposed to standard Pascal call by reference.
>It's just more trouble copying parameters back and forth than
>using a temporary.
>
>-paul

Ada 83 explicitly leaves the "in out" parameters implementation
unspecified. It can be copy-in/copy-out, or FORTRAN/Pascal
"dereferencing", or any mix, or whatever else. Since the
semantic effect of using "in", "out" and "in out" parameters is
defined in high-level Ada terms, programs whose behaviour
depends on the actual underlying parameters implementation
mechanism are stated erroneous. AFAIK, Ada 95 adheres to it.
BTW, Ada 95 is the first ISO/ANSI standardized OOP language.
That CPLUSPLUS didn't manage to make it yet! ;-) And when
I've found Stroustrup reading comp.lang.ada and accused him of
blatant stealing from Ada--starting with exceptions
and finishing with overloading, or vice versa (he adds to the
"loaned" list regularly :)--it was _the_ discussion!.....
He didn't mention a single book in the ARM (which lacks
bibliography at all), scarcely nodding only to the unavoidable
C. (Thank God!) In the textbook, he suggests C++ was made
to avoid programming in other modern languages. (But using
their features, after they've been robbed of them finally!)
He couldn't withstand it, or produce anything slightly
resembling the perfect Ada Rationale/Standard/Rapporteur
processes, etc., and retracted with his CPLUSPLUS.
Just glad to see my prof. language here! :-)

--
Alexy V. Khrabrov <khra...@cccc.com>
``Age Quod Agis'' (Do what you're doing.)


George Chesakov

unread,
Mar 2, 1995, 3:31:58 PM3/2/95
to
Andrew Prihodko writes:
|> Igor Chudov says:

|> >integer a, b;
|> >a := 3245;
|> >b := 367254; { Preparation - does not count. }
|> >
|> > a := a xor b; { Swap Operation itself }
|> > b := b xor a; { Note that it does not use a temporary variable }
|> > a := a xor b; { to keep swapped value - otherwise it
|> > would be simple as shit, but not so much fun }
|> > { Isn't that cool? }
|> >
|> >Do you like it? Let me know. Andrew, sorry if you wanted us to send it to
|> >you instead of posting, but I thought it is simple enough to be posted right
|> >away.
|>
|> Correct. Here is a bit simpler one.
|>
|> A = A + B;
|> B = A - B;
|> A = A - B;

BTW, xor never overflows and works with reals (use casts if needed),
what cannot be said of +, -.

Igor Chudov

unread,
Mar 3, 1995, 1:14:10 PM3/3/95
to
George Chesakov (ches...@tucson.princeton.edu) wrote:

Ok, after reading all that I came to the conclusion that this

#define swap( type, x, y ) \
{ \
type tmp; \
tmp = (x); \
(x) = (y); \
(y) = tmp; \
}

Is the best way around. Good old way is better than all our dirty tricks.

Dima Volodin

unread,
Mar 3, 1995, 2:38:34 PM3/3/95
to

Reals and integers are not necessarily of the same size. Some machines
have tagged architecture. etc.

> naive

Michael G. Minkovski

unread,
Mar 3, 1995, 8:24:32 AM3/3/95
to
In article <3j721b$d...@dartvax.dartmouth.edu> al...@belknap.dartmouth.edu (Alexy V. Khrabrov) writes:

>Ada 83 explicitly leaves the "in out" parameters implementation
>unspecified. It can be copy-in/copy-out, or FORTRAN/Pascal
>"dereferencing", or any mix, or whatever else. Since the
>semantic effect of using "in", "out" and "in out" parameters is
>defined in high-level Ada terms, programs whose behaviour
>depends on the actual underlying parameters implementation
>mechanism are stated erroneous. AFAIK, Ada 95 adheres to it.
>BTW, Ada 95 is the first ISO/ANSI standardized OOP language.
>That CPLUSPLUS didn't manage to make it yet! ;-) And when
>I've found Stroustrup reading comp.lang.ada and accused him of
>blatant stealing from Ada--starting with exceptions
>and finishing with overloading, or vice versa (he adds to the
>"loaned" list regularly :)--it was _the_ discussion!.....
>He didn't mention a single book in the ARM (which lacks
>bibliography at all), scarcely nodding only to the unavoidable
>C. (Thank God!) In the textbook, he suggests C++ was made
>to avoid programming in other modern languages. (But using
>their features, after they've been robbed of them finally!)
>He couldn't withstand it, or produce anything slightly
>resembling the perfect Ada Rationale/Standard/Rapporteur
>processes, etc., and retracted with his CPLUSPLUS.
> Just glad to see my prof. language here! :-)

Great! At last I've found the guy who claims Ada to be The Perfect Langugage
:-)

In _my_ _humble_ opinion, Ada is the same type of ugly hybrid as the C++.
What can you expect from the military project, btw? More seriously, Ada is
_too comlex_. It's not a tool, it's an ideology and the whole lifestyle.
And C++ came to the point when it's not a solid concept anymore but rather a
set of heterogeneous parts (however it always was). Still it's simplier, or
better to say, smaller.

As for what came first, I don't want to sound like prof. voronka. But, again
IMHO, neither Ada nor C++ ever introduced new ideas but rather both of
them used the existing ones (except maybe handshaking in Ada, but I don't want
to discuss parallelism, it's the different matter). And even if it's not so,
the word "robbery" is still not appropriate in this case.

Koroche govoria, junk eto vse. Pishu na C++, potomu chto na Ade pisat'
nevozmozhno - vse-ravno kak u Strugatskih, kurs upravleniia umklaidetom
kvantovogo urovnia zanimaet 8 semestrov i trebuet osnovatel'nogo znaniia
kvantovoi alhimii. I na hrena, sprashivaetsia, tratit' uimu vremeni i sil,
chtoby nauchit'sia v sovershenstve risovat' Wirtoobraznye bukvochki?
Vyrazitel'naia moschnost' vseh sovremennyh gibridnyh (protsedurno - OOP)
iazykov primerno odinakova, kachestvo koda na vyhode horoshih C++
compiliatorov ochen' horoshee, sintaksis vezde strashnyi (ne nado pro etot
Adov sintaksis tol'ko), esteticheskogo udovol'stviia pri napisanii
kommercheskih programm nemonogo tak ili inache. Nakonets nadezhnost'
(liubimaia tema poklonnikov Ady) - krupnovata i slozhnovata Adushka, dlia togo
chtoby byt' nadezhnoi. Est' klass zadach, dlia kotoryh Ada podhodit luchshe,
konechno. No kak universal'nyi iazyk povsednevnogo programmirovaniia... Beda
ee razrabotchikov - stremleniie k sovershenstvu. A straus nash, trup ego mat',
konformist i pleval na sovershenstvo, lish' by rabotalo. Vot poetomu polmira
na C++ i pishet, chto natura cheloveka takaia - haltura :-)

A perfektsionisty pust' na Oberone pishut. Tozhe vesch' porazitel'naia, nu
chem Wirtu neschastnyi scrollbar tak dosadil, chto on svoim udolbischem ego
zameenil? Zachem vse perevorachivat' s nog na golovu, bez iavnyh preimuschestv
v 90% sluchaev, nikogda ne ponimal. Perfektsiuonisty, a ne evrei i ne
intelligenty - vot prokliatie roda chelovecheskogo!

A voobsche: Smalltalk rules!

...The Wind that blows between the Worlds it cut him like a knife...
R.K.

Alex Semenyaka

unread,
Mar 4, 1995, 11:16:16 PM3/4/95
to
In article <D4vuH...@mv.mv.com>, Michael Furman <EN...@GSSI.MV.COM> wrote:
>In article <1995Mar2.2...@Princeton.EDU>,
>ches...@tucson.princeton.edu says...

>>Andrew Prihodko writes:
>>|> Igor Chudov says:

<you know what was here>

>You are right about overflow. But you don't about real - you cat also
>cast them to integers and all will be fine.
> Micahel Furman

Pardon me? What do you mean??
He IS right saying of real numbers. At least I know no one computer
where two real numbers have different sizes. And, of course, there is
bit representation of reals - always. So, you CAN use XOR for this
operation without any casting IF language gives you access to bit
representation of data. Sure, intermediate results will depend on the
computer type but it cannot be a problem.

>>--
>>naive
>>
>> Stupidity is a choice.
>

SY, Alex.


Michael G. Minkovski

unread,
Mar 10, 1995, 5:33:15 PM3/10/95
to
In article <3jogn8$a...@baskerville.CS.Arizona.EDU> pa...@CS.Arizona.EDU (Paul L. Klark) writes:


In article <mmg.114....@interaccess.com>,


>Michael G. Minkovski <m...@interaccess.com> wrote:

>>inline void swap(int &a, int &b)
>>{
>> a = a+b;
>> b = a-b;
>> a = a-b;
>>}
>>
>>// ...
>> float a = 1.23456, b = 6.54321;
>> swap((int&)a, (int&)b);

>It's all wonderful and all that.
>Now can you see what the following program does ?
>(using YOUR swap function).

>int i=1, j=2;
>i++;
>swap(a[i],a[j]);

>-paul

Ne, Paul, ty ne ponial. Ia ne zaschischaiu vse etu hitrozadost' s xor ili +/-,
moia swap byla tol'ko illiustratsiei bolee pravil'nogo ispol'zovaiia ssylok v
C++, chem predlozhil Igor'. Eto kak by iz toi zhe serii, chto i zadachka
pro nagrevaniie dvuh sharikov pri otsutstvii teploperedachi. Ia zh napisal,
chto v real'noi programme ia prosto ne polenilsia by soorudit' stol'ko inline,
skol'ko nado (ispol'zuia dop. peremennuiu, konechno), i bol'she ne dumat' ob
etom.Ser'ezno, vse eti dela stoiat chego-libo tol'ko v illiustrativnyh ili
uchebnyh primerah - ochen' redko v real'noi programme udaetsia ispol'zovat'
triuk iz uchebnika. Hotia est' i iskliucheniia. Naprimer, moi liubimyi
algoritm Patricia - odin sploshnoi triuk. A moi priiatel' zafighachil na ego
baze indeksator bazy dannyh geneticheskih posledovatel'nostei v real'noi
kommercheskoi sisteme (pravda, v N-noi versii, snachala index byl sovsem
dubovyi, potom na balansirovannyh derev'iah, a uzh potom...).

No v ramkah moei bezuspeshnoi bor'by s perfektsionizmom podobnye triuki -
suschii opium. Kaif.


...The Wind that blows between the Worlds, it cut him like a knife...
R.K.

Dima Volodin

unread,
Mar 13, 1995, 7:29:29 PM3/13/95
to
George Chesakov (ches...@tucson.princeton.edu) wrote:
> Simon Hawkin writes:
> |> naive wrote:
> |>
> |> *> empty file abcde is not really empty: it takes some disk space (name, attributes),
> |> *>
> |> *> but what do you mean by empty output?
> |>
> |> An output stream is created, but nothing is sent there. It's a
> |> subtle point, though; standard streams are open initially, in
> |> most languages.

> viewing a program as a black box, how one does know whether it produced
> empty or no output?

Get back to basics (not Basic): your dispute is absolutely meaningless.
See Turing&Markoff.

0 new messages