Dark Bit Factory & Gravity
GENERAL => General chat => Topic started by: Pixel_Outlaw on August 05, 2011
-
Longing for more minimalism and nonsensical restriction in programming, I wonder how far somebody could take making a program with a single variable?
I suppose you could use a large variable like a double and then divide it into smaller memory sections. It would be really fun to look at a code and only see a single variable declaired and lots of shifting bits around to maintain such a low memory state.
Any thoughts? I might try this should I built up enough interest.
Might be an interesting challange to demo coding as we tend to applaud clever restrictions and ingenuity.
Again just making a conversation point here. I'd be interested to hear your thoughts.
-
Sounds like you should look into Brainfuck (http://www.muppetlabs.com/~breadbox/bf/) :) . Very similar concept (though the one "variable" is a pointer into a table of 30000 or so slots depending on implementation). Been thinking about seeing how small an interpreter could be for, say, C64, where there's ROM routines available to print a char to the screen.
-
I certainly wonder how you do things like nester for loops. With a single variable. ;)
-
Some questions are - Can you access RAM? Or a screen? If so you can poke the the variable into memory, or plot it as a colour. Can you use a stack, with push and pop?
There are 'languages' that only use only a few instructions. My lecturer in Computer Science at university, Mike P Stannett, came up with a 3 instruction language called MPS which has M,P,S as instructions...(can you see a pattern forming here?)...
Jim
-
AH PMS!
I'm sure working with such an instruction set would make it feel as through the language caused PMS.
I'm not sure about restrictions Jim, you make some good points.
I suppose that it would just be a single variable with no way to store the data in memory the variable becomes your RAM.
I guess depending on the OS a double could give you 8 ascii characters (or 16 if you toss out the extended character set). Two floats (depending on the OS), or two ints (depending on os and sign).
Interesting thoughts so far.
-
Duckers/Outracks and I at one point designed an imaginary 8-bit machine with some odd limitations, including a single branching instruction, SAP, which Swaps Accumulator with Program counter. We have yet to actually code the emulator for the thing...
But I think you can get very very far if you have access to any kind of framebuffer/char buffer; it can be used for temp storage as well as output. Stack would also be your best friend here. I don't know; I think I'm just rambling now :)
-
int *data = (int*)malloc(65536*sizeof(int)); // allocate memory
memset(data,0,65536); // zero the data
data[65535] = 0xDEADF00D; // place an end of data marker
while (*data != 0xDEADF00D) { // continue until we reach that marker
// do you effect and place it in memory through the pointer
data++;
}
Would I be allowed to use registers...
register counter = 65536;
while (counter) {
counter--;
}
-
Would declaring a single object with multiple properties be classed as cheating?