This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Sorry Bear, I forgot about that rule . And yeah this is completely useless, but I'm curious about it....
The only thing I think of is making the entire thing 1 giant string(useless) or making a print statement after each line(useless).... The dude said the code doesn't have to work either, just code, so I figure the first selection but whyyyyyyyyyyyyyyy!!!
You should resist the temptation to follow the link Matthew posted, but instead try to do it yourself. The learning effect of doing it yourself far surpasses the knowledge gained by being told how to do it.
Ulf Dittmer wrote:You should resist the temptation to follow the link Matthew posted, but instead try to do it yourself. The learning effect of doing it yourself far surpasses the knowledge gained by being told how to do it.
this isn't for me, it's for someone else :P. I could care less, I was just stumped as how to do it, or WHY to do it :P.
It is a kind of measurement of the power of a programming language if such a quine can be written in it.
Joined: Mar 22, 2005
To take the challenge one step further (and make the resulting source code even more obscure), try to write the shortest source code that prints itself. I think I have seen a Java solution that does this in less than 200 characters.
George Herbert Leigh Mallory (18 June 1886 – 8 or 9 June 1924) was an English mountaineer who took part in the first three British expeditions to Mount Everest in the early 1920s.
Mallory is famously quoted as having replied to the question "Why do you want to climb Mount Everest?" with the retort "Because it's there", which has been called "the most famous three words in mountaineering".
Ulf Dittmer wrote:To take the challenge one step further (and make the resulting source code even more obscure), try to write the shortest source code that prints itself. I think I have seen a Java solution that does this in less than 200 characters.
Just came across a new language that lets you do it in seven:
I think you are missing the point. Will your program work, if you only have the binary? You need to compile your program, and then run it without access to the source code. The binary needs to be able to regenerate it's own source code.
If the OP was looking for your answer, it wouldn't be such a difficult problem to solve, would it?
Well...there would be three ways to do it. First, read the source file and print it. Second, read the source code stored as data in the executable and print it. Third, decompile or disassemble the executable and create source code and print it.
If the first way is cheating, the second is in principle the same thing.
Decompiling would give you something that would "print itself" but it would likely not be the actual source code that was entered. You could run it once, and then compile that output and see if the two matched the second time. I think they probably would.
Disassembling - this would work and would be easy. If you start with assembly language you can know where the opcodes begin and end, and every opcode translates directly to a statement in assembly language. So just read the executable and convert the opcodes back to mnemonics.