Add alt code to 1990/pjr

This alt code is recommended by the judges in the case the compiler
cannot compile main() due to lack of temporary stack space but it is
also recommended by the author as it does something else.

Format/typo check README.md file.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-03 09:09:31 -07:00
1 parent 90efe469e3
commit ab3cf49ff7
5 files changed
+76 -33

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
pjr
pjr.alt
pjr.orig
prog.orig
+2 -2
View File
@@ -112,8 +112,8 @@ OBJ= ${PROG}.o
DATA=
TARGET= ${PROG}
#
ALT_OBJ=
ALT_TARGET=
ALT_OBJ= ${PROG}.alt.o
ALT_TARGET= ${PROG}.alt
#################
+53 -31
View File
@@ -1,11 +1,6 @@
# Most Unusual Data Structure
Peter J Ruczynski\
Pyramid Technology Ltd.\
Pyramid House\
Solatron Road\
Farnborough\
Hants GU14 7PL\
England, U.K.
@@ -15,6 +10,10 @@ England, U.K.
make all
```
There is an [alternate version](#alternate-code) that does something different
that can be used if your compiler is incapable of compiling `X=g()...` in
`main()`. It can be used for another purpose too.
## To use:
@@ -23,23 +22,44 @@ make all
```
## Judges' remarks:
This program prints out a string. Can you figure out how
it is done?
By use of pointers to functions returning a struct of pointers\
to functions!
## Alternate code:
Note that some compilers will be unable to compile the expression `X=g()...` in
main() due to lack of temporary stack space. One might want to try replacing
main with:
`main()` due to lack of temporary stack space. One might want to try replacing
`main()` with:
```c
main(){X=s().v().o().o().l().S().d().l().i().o().w().N();}
```
if this is a problem.
if this is a problem, which is what this alternate code is.
NOTE: it prints something else and it is what the author suggested one try as
well.
### Alternate build:
```sh
make alt
```
### Alternate use:
```sh
./pjr.alt
```
## Judges' remarks:
This program prints out a string. Can you figure out how
it is done?
By use of pointers to functions returning a struct of pointers
to functions!
### Spoiler:
@@ -48,32 +68,34 @@ This program prints out the string:
> the quick brown fox jumped over the lazy dog
by use of pointers to functions returning a struct of pointers
to functions!
## Author's remarks:
Rot13:
Vg vf fvzcyr gb znxr gur cebtenz cevag bgure fgevatf. Rnpu
nycunorgvpny punenpgre sebz n gb m vf cevagrq bhg nf vgf
bccbfvgr:
It is simple to make the program print other strings. Each
alphabetical character from a to z is printed out as its
opposite:
n->m o->l p->k rgp
```c
a->z b->y c->x etc
```
Gb rapbqr n arj fgevat vachg gur fgevat nf vg vf zrnag gb pbzr bhg:
To encode a new string input the string as it is meant to come out:
K=f().i().b().b().y().F().q().y().v().b().j().A();
```c
X=s().v().o().o().l().S().d().l().i().o().w().N();
```
Abgr: F() ercerfragf n fcnpr naq A() n arjyvar. Guvf jvyy abj
cebqhpr...
Note: `S()` represents a space and `N()` a newline. This will now
produce...
uryyb jbeyq
```
hello world
```
By the way, there is actually a piece of code which is not used
in the original program! I leave it as an intellectual exercise
to the reader to find out what it is.
By the way, there is actually a piece of code which is not used
in the original program! I leave it as an intellectual exercise
to the reader to find out what it is.
## Copyright and CC BY-SA 4.0 License:
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
#define A(a) G a();
#define B(a) G (*a)();
#define C(a,b) G a() { printf(b); return X; }
typedef struct F G;A(a)A(b)A(c)A(d)A(e)A(f)A(g)A(h)A(i)A(j)A(k)A(l)A(m)A(n)A(
o)A(p)A(q)A(r)A(s)A(t)A(u)A(v)A(w)A(x)A(y)A(z)A(S)A(N)void Q();struct F{B(a)B
(b)B(c)B(d)B(e)B(f)B(g)B(h)B(i)B(j)B(k)B(l)B(m)B(n)B(o)B(p)B(q)B(r)B(s)B(t)B(
u)B(v)B(w)B(x)B(y)B(z)B(S)B(N)void(*Q)();}X={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,
q,r,s,t,u,v,w,x,y,z,S,N,Q};C(a,"z")C(b,"y")C(c,"x")C(d,"w")C(e,"v")C(f,"u")C(
g,"t")C(h,"s")C(i,"r")C(j,"q")C(k,"p")C(l,"o")C(m,"n")C(n,"m")C(o,"l")C(p,"k"
)C(q,"j")C(r,"i")C(s,"h")C(t,"g")C(u,"f")C(v,"e")C(w,"d")C(x,"c")C(y,"b")C(z,
"a")C(S," ")C(N,"\n") void Q(){}main(){X=s().v().o().o().l().S().d().l().i().
o().w().N();}
+7
View File
@@ -965,6 +965,13 @@ bugs.md](/bugs.md#1990-jaw) for details.
NOTE: as `btoa` is not common we used a ruby script from Yusuke.
## [1990/pjr](1990/pjr/pjr.c) ([README.md](1990/pjr/README.md]))
Cody added the [alt code](1990/pjr/pjr.alt.c) which was suggested by the judges
in the case that your compiler cannot compile `X=g()...` but it actually does
something else and is recommended by the author as well.
## [1990/scjones](1990/scjones/scjones.c) ([README.md](1990/scjones/README.md]))
Yusuke suggested `-ansi` to get the entry to compile due to trigraphs and Cody