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:
1 parent
90efe469e3
commit
ab3cf49ff7
5 files changed
+76
-33
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
pjr
|
pjr
|
||||||
|
pjr.alt
|
||||||
pjr.orig
|
pjr.orig
|
||||||
prog.orig
|
prog.orig
|
||||||
+2
-2
@@ -112,8 +112,8 @@ OBJ= ${PROG}.o
|
|||||||
DATA=
|
DATA=
|
||||||
TARGET= ${PROG}
|
TARGET= ${PROG}
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ= ${PROG}.alt.o
|
||||||
ALT_TARGET=
|
ALT_TARGET= ${PROG}.alt
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|||||||
+53
-31
@@ -1,11 +1,6 @@
|
|||||||
# Most Unusual Data Structure
|
# Most Unusual Data Structure
|
||||||
|
|
||||||
Peter J Ruczynski\
|
Peter J Ruczynski\
|
||||||
Pyramid Technology Ltd.\
|
|
||||||
Pyramid House\
|
|
||||||
Solatron Road\
|
|
||||||
Farnborough\
|
|
||||||
Hants GU14 7PL\
|
|
||||||
England, U.K.
|
England, U.K.
|
||||||
|
|
||||||
|
|
||||||
@@ -15,6 +10,10 @@ England, U.K.
|
|||||||
make all
|
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:
|
## To use:
|
||||||
|
|
||||||
@@ -23,23 +22,44 @@ make all
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Alternate code:
|
||||||
|
|
||||||
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!
|
|
||||||
|
|
||||||
Note that some compilers will be unable to compile the expression `X=g()...` in
|
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()` due to lack of temporary stack space. One might want to try replacing
|
||||||
main with:
|
`main()` with:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
main(){X=s().v().o().o().l().S().d().l().i().o().w().N();}
|
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:
|
### Spoiler:
|
||||||
@@ -48,32 +68,34 @@ This program prints out the string:
|
|||||||
|
|
||||||
> the quick brown fox jumped over the lazy dog
|
> 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:
|
## Author's remarks:
|
||||||
|
|
||||||
Rot13:
|
|
||||||
|
|
||||||
Vg vf fvzcyr gb znxr gur cebtenz cevag bgure fgevatf. Rnpu
|
It is simple to make the program print other strings. Each
|
||||||
nycunorgvpny punenpgre sebz n gb m vf cevagrq bhg nf vgf
|
alphabetical character from a to z is printed out as its
|
||||||
bccbfvgr:
|
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
|
Note: `S()` represents a space and `N()` a newline. This will now
|
||||||
cebqhpr...
|
produce...
|
||||||
|
|
||||||
uryyb jbeyq
|
```
|
||||||
|
hello world
|
||||||
|
```
|
||||||
|
|
||||||
By the way, there is actually a piece of code which is not used
|
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
|
in the original program! I leave it as an intellectual exercise
|
||||||
to the reader to find out what it is.
|
to the reader to find out what it is.
|
||||||
|
|
||||||
|
|
||||||
## Copyright and CC BY-SA 4.0 License:
|
## Copyright and CC BY-SA 4.0 License:
|
||||||
|
|||||||
@@ -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();}
|
||||||
@@ -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.
|
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]))
|
## [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
|
Yusuke suggested `-ansi` to get the entry to compile due to trigraphs and Cody
|
||||||
|
|||||||
Reference in new issue
Block a user