Thursday, March 14, 2013

Programming Challenge

So, the other day I was writing a script to generate some macros, when I realized how meta that whole thin is. I guess that is the right word. Well, its the word the kids love, and we are all about making money off of children. Except I don't make money off of this thing. Anyway, feeling the need to make superfluous code, I wrote this.

#!/bin/bash
echo "#include <stdio.h>" > hello.cpp
echo "#include <stdlib.h>" >> hello.cpp
echo "#include <string>" >> hello.cpp
echo "#include <fstream>" >> hello.cpp
echo "#include <iostream>" >> hello.cpp
echo "//This program generates an output fiel containing the source code for a 'Hello World!' program!" >> hello.cpp
echo "int main(void)" >> hello.cpp
echo "{" >> hello.cpp
echo "      FILE  * output1;" >> hello.cpp
echo "      output1 = fopen(\"hello.f\",\"w\");" >> hello.cpp
echo "      fprintf(output1,\"      PROGRAM CASE\\n\");" >> hello.cpp
echo "      fprintf(output1,\"c This is a \'Hello World!\' Program!\\n\");" >> hello.cpp
echo "      fprintf(output1,\"      PRINT *,'Hello World!'\\n\");" >> hello.cpp
echo "      fprintf(output1,\"      STOP\\n\");" >> hello.cpp
echo "      fprintf(output1,\"      END\n\");" >> hello.cpp
echo "      fclose(output1);" >> hello.cpp
echo "}" >> hello.cpp
g++ hello.cpp -lm -O2 -g -o hello1
./hello1
gfortran hello.f -lm -O2 -g -o hello2
./hello2

It was pretty straightforward except I had to learn how to triple nest printed strings.
I hereby present you with a challenge:
First: Figure out what I did did there.
Second: get this to run on your machine.
Third: Create something even more convoluted to do the same task.

There are some stipulations.
1: What you send me must be a single: self contained BASH scrip file. I should only type one command to run the entire thing. No support files allowed!
2: It may employ any standard libraries, compilers, software, and commands that you would expect to find on an academic engineering network. However, assume that I have not customized them at all.
3: The output must be recognizable English. (I am the judge of "recognizable.")
4: Assume that the network connection is turned off for the run.
5: There is no way in hell I am granting that thing root access.
6: I am not obligated to try an run any of these. If I do, then I will grant some leeway if you have a reference that requires an filepath.

You can send the responses to crowbar563@mildlymiffed.com or you can just paste them into the comments.

If anyone actually, responds I will be pleased.
Hopefully, I learn something.

No comments:

Post a Comment