----------------------------------- beard0 Tue Nov 29, 2005 5:30 pm Turing oddities contest ----------------------------------- Your job is to take the following bit of code, and insert code in the middle without changing the portion I have written such that the last line (put b), and the last line only causes an error. The first person to PM me working code wins. Please PM only so as to give others a chance to work it out for themselves. Over the course of the next little while, I will post hints as to how this can be done. var a : string %This part is your job! var b : string b := a (5 .. *) put a (5 .. *) put b %This line should produce an error, and be the only one to do so! EDIT:Corrected my commenting pour utuliser une langue consistent. ----------------------------------- Hikaru79 Tue Nov 29, 2005 6:30 pm ----------------------------------- Simple! var a : string a := "hello world!" var b : string b := a (5 .. *) put a (5 .. *) put b //This line should produce an error, and be the only one to do so! Any code at all in place of that comment generates an error on the last line -- because "//" is Java commenting, not Turing ^__^ I win! ;) EDIT: I know you said PM, but since this is sort of a typo on your part and not a real solution, I figured it was okay :P ----------------------------------- MysticVegeta Tue Nov 29, 2005 6:42 pm ----------------------------------- if life were like that, you wouldn't need a Visa card. ----------------------------------- beard0 Tue Nov 29, 2005 6:54 pm ----------------------------------- if life were like that, you wouldn't need a Visa card. What he said. ----------------------------------- beard0 Tue Nov 29, 2005 8:28 pm ----------------------------------- Hint number one: I have received some entries (which incidentally do not work) that attempted to take advantage of user input. No user input is required, and I'm stating now as additional criteria that you may not use input. ----------------------------------- MysticVegeta Tue Nov 29, 2005 11:33 pm ----------------------------------- almost done, pretty nifty problem :wink: ----------------------------------- Paul Wed Nov 30, 2005 6:23 pm ----------------------------------- Wow, I'm betting its a really obscure error :P And hikaru remember its in the middle of the code, not at the end :P ----------------------------------- beard0 Wed Nov 30, 2005 11:55 pm ----------------------------------- at N.B. The hint is in the quote box in white. Highlight to see, unless you'd like to be a purist. ----------------------------------- beard0 Wed Nov 30, 2005 11:57 pm ----------------------------------- And hikaru remember its in the middle of the code, not at the end :P It was my error; my code originally had the "//" in the last line (I've been doing more in java of late.) and I changed it after Hikaru79 pointed it out. ----------------------------------- MysticVegeta Thu Dec 01, 2005 9:06 am ----------------------------------- at N.B. The hint is in the quote box in white. Highlight to see, unless you'd like to be a purist. Wow, thats a good hint! :roll: ----------------------------------- beard0 Thu Dec 01, 2005 9:18 am ----------------------------------- Wow, thats a good hint! :roll: Oh damn, really? I meant it to be rather cryptic as it's only the first real hint. :roll: ----------------------------------- MysticVegeta Thu Dec 01, 2005 2:37 pm ----------------------------------- rather cryptic oh, its cryptic enough for me to not understand it :lol: ----------------------------------- beard0 Thu Dec 01, 2005 2:45 pm ----------------------------------- When I said at, I really meant @ ----------------------------------- [Gandalf] Thu Dec 01, 2005 4:50 pm ----------------------------------- Pah, if you wanted to make Turing crash there's much simpler ways ;). var a : string := string @ (241) var b : string b := a (5 .. *) put a (5 .. *) put b %This line should produce an error, and be the only one to do so! ----------------------------------- Tony Thu Dec 01, 2005 5:09 pm ----------------------------------- "]Pah, if you wanted to make Turing crash there's much simpler ways ;). That just crashes the environment though. The goal is to make put b cause an error ----------------------------------- beard0 Thu Dec 01, 2005 5:36 pm ----------------------------------- Gandalf: Did you not maybe think that there was a reason I had my hint in white on a white background? Could a mod please remove Gandalf's post to allow those who haven't yet seen it to choose whether to use the hint? ----------------------------------- Dan Thu Dec 01, 2005 5:55 pm ----------------------------------- There i did not delete anything to his post, just made it so the user has a choice ;) ----------------------------------- [Gandalf] Thu Dec 01, 2005 6:14 pm ----------------------------------- Sorry, I didn't think of making a quote white, or even of the spoiler aspect. I realized that it doesn't do the objective, but it does show how to use his example, and the instability it (which I guess causes the error). ----------------------------------- MysticVegeta Fri Dec 02, 2005 12:03 pm ----------------------------------- Whens the fourth *useful* hint coming? :lol: ----------------------------------- beard0 Fri Dec 02, 2005 12:09 pm ----------------------------------- addr ----------------------------------- Tony Fri Dec 02, 2005 12:20 pm ----------------------------------- I just want to point out that hints 2,3 and 4 say the exact same thing, just in a different word ----------------------------------- beard0 Fri Dec 02, 2005 12:26 pm ----------------------------------- I just want to point out that hints 2,3 and 4 say the exact same thing, just in a different word Each makes it eaiser and easier to find the relevant information in the turing help manual. The next hint will be a completely new one. ----------------------------------- Tony Fri Dec 02, 2005 12:33 pm ----------------------------------- I think a good hint to consider, is letting us know what the error generated is.. unless it gives away too much. It's your call :) ----------------------------------- beard0 Fri Dec 02, 2005 12:36 pm ----------------------------------- I think a good hint to consider, is letting us know what the error generated is.. unless it gives away too much. It's your call :) Variable has no value ----------------------------------- Cervantes Fri Dec 02, 2005 4:41 pm ----------------------------------- I just want to point out that hints 2,3 and 4 say the exact same thing, just in a different word Each makes it eaiser and easier to find the relevant information in the turing help manual. The next hint will be a completely new one. Yeah, too bad wine won't load the Turing Help Manual. Can't research these hints. :( Well, I know the reason why b has no value. If anyone wants to collaborate with me... :shifty: ----------------------------------- [Gandalf] Fri Dec 02, 2005 5:22 pm ----------------------------------- Thanks beard0, that last hint was just what I was looking for. Now if only I can remember what I was going to do with it... I think from now on, I will just white out my whole post relating to this... What I have so far: ... var a : string var ab : string := "abcde" a := string @ (addr(ab)) var b : string b := a (5 .. *) put a (5 .. *) put b %This line should produce an error, and be the only one to do so! ... Not much :? It might be on the right track, but I have a feeling there is quite a bit more to it than that... ----------------------------------- MysticVegeta Sat Dec 03, 2005 6:01 pm ----------------------------------- Hmm I get the logic of it, and what error it should give but i am having a hard time implementing it. :x ----------------------------------- beard0 Mon Dec 05, 2005 9:22 am ----------------------------------- Errr. put "" + chr(128) Cervantes: Unless you happen to know these commands, this will be impossible without the reference manual: Syntax addr (reference) Description The addr attribute is used to find the integer address of a variable or non scalar constant. This is implementation-dependent. This address may be used in an indirection operation @. Example Set a to be the address of x. var x : real var a : addressint := addr (x) Details The value of the address produced by addr is of type addressint, an integer type whose range is that of the underlying memory addresses. The concept of an address is implementation-dependent. For example, an optimizing compiler could determine that a variable does not require space because the program could be computed without the variable with no change in output. However, in most implementations, types have a predictable size and variables of that type occupy that number of bytes in memory. --------- Syntax targetType @ ( expn ) Description The indirection operator @ is used to access values that lie at absolute machine addresses in the computer's memory. This is dangerous and implementation-dependent and can cause arbitrary corruption of data and programs. Example Copy the byte value at memory location 246 into b and then set that memory byte to zero. var b : nat1 % One byte natural number b := nat1 @ (246) nat1 @ (246) := 0 Details The form of targetType must be one of: (a) ----------------------------------- Tony Mon Dec 05, 2005 9:41 am ----------------------------------- In such case Cervantes and I have came up with a solution back when he posted.. we were just off on the character to use. Tried with a different EOS character chr(0) instead of chr(128). I'll PM you the code ----------------------------------- beard0 Mon Dec 05, 2005 9:59 am ----------------------------------- We have a winner! Looking for a more simple version for a second place. (Winners are automatically disqualified from the running for second.) ----------------------------------- beard0 Sat Dec 10, 2005 3:30 pm ----------------------------------- Entries being not forthcomming, here is the winning code, a Cervantes-Tony collaboration:var a : string var hack : string := "tony*hack" % just a string char@(addr (hack) + 4) := chr (128) % splice EOS as 5th (*) character a := string@(addr (hack)) % assign manipulated string to a var b : string b := a (5 .. *) put a (5 .. *) put b And this is the slightly simpler version:var a : string a := " " nat1@(addr (a) + 4) := 128 var b : string b := a (5 .. *) put a (5 .. *) put b I don't know why the third variable was introduced, nor why the last line of their portion of the code is done as it is - a:=hack would have sufficed. Due to the nature of the winners (that is, mod & admin) no bits will be given for winning. Another prize therefore is neaded, and so, I give you a cookie: [url=http://ugray.be/compsci/cookie.php]Click for your cookie. ----------------------------------- MysticVegeta Sun Dec 11, 2005 2:31 am ----------------------------------- Oh my god its 128!! I was setting it at different numbers, didnt work! ----------------------------------- beard0 Sun Dec 11, 2005 12:03 pm ----------------------------------- Try running this code :D: var a : string put nat1@(addr (a)) ----------------------------------- Tony Sun Dec 11, 2005 4:31 pm ----------------------------------- umm... yeah, the code was work-in-progress, and I was trying different things in there... and haven't cleaned up the submission. :P Thx for the cookie