Computer Science Canada

Turing oddities contest

Author:  beard0 [ Tue Nov 29, 2005 5:30 pm ]
Post subject:  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.

Turing:
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.

Author:  Hikaru79 [ Tue Nov 29, 2005 6:30 pm ]
Post subject: 

Simple!
code:
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!

Wink

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 Razz

Author:  MysticVegeta [ Tue Nov 29, 2005 6:42 pm ]
Post subject: 

if life were like that, you wouldn't need a Visa card.

Author:  beard0 [ Tue Nov 29, 2005 6:54 pm ]
Post subject: 

MysticVegeta wrote:
if life were like that, you wouldn't need a Visa card.


What he said.

Author:  beard0 [ Tue Nov 29, 2005 8:28 pm ]
Post subject: 

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.

Author:  MysticVegeta [ Tue Nov 29, 2005 11:33 pm ]
Post subject: 

almost done, pretty nifty problem Wink

Author:  Paul [ Wed Nov 30, 2005 6:23 pm ]
Post subject: 

Wow, I'm betting its a really obscure error Razz
And hikaru remember its in the middle of the code, not at the end Razz

Author:  beard0 [ Wed Nov 30, 2005 11:55 pm ]
Post subject: 

Hint number two wrote:
at


N.B. The hint is in the quote box in white. Highlight to see, unless you'd like to be a purist.

Author:  beard0 [ Wed Nov 30, 2005 11:57 pm ]
Post subject: 

Paul wrote:
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.

Author:  MysticVegeta [ Thu Dec 01, 2005 9:06 am ]
Post subject: 

beard0 wrote:
Hint number two wrote:
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! Rolling Eyes

Author:  beard0 [ Thu Dec 01, 2005 9:18 am ]
Post subject: 

MysticVegeta wrote:
Wow, thats a good hint! Rolling Eyes


Oh damn, really? I meant it to be rather cryptic as it's only the first real hint. Rolling Eyes

Author:  MysticVegeta [ Thu Dec 01, 2005 2:37 pm ]
Post subject: 

beard0 wrote:

rather cryptic


oh, its cryptic enough for me to not understand it Laughing

Author:  beard0 [ Thu Dec 01, 2005 2:45 pm ]
Post subject: 

Hint Number Three wrote:
When I said at, I really meant @

Author:  [Gandalf] [ Thu Dec 01, 2005 4:50 pm ]
Post subject: 

Pah, if you wanted to make Turing crash there's much simpler ways Wink.

code wrote:
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!

Author:  Tony [ Thu Dec 01, 2005 5:09 pm ]
Post subject: 

[Gandalf] wrote:
Pah, if you wanted to make Turing crash there's much simpler ways Wink.

That just crashes the environment though.

The goal is to make put b cause an error

Author:  beard0 [ Thu Dec 01, 2005 5:36 pm ]
Post subject: 

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?

Author:  Dan [ Thu Dec 01, 2005 5:55 pm ]
Post subject: 

There i did not delete anything to his post, just made it so the user has a choice Wink

Author:  [Gandalf] [ Thu Dec 01, 2005 6:14 pm ]
Post subject: 

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).

Author:  MysticVegeta [ Fri Dec 02, 2005 12:03 pm ]
Post subject: 

Whens the fourth *useful* hint coming? Laughing

Author:  beard0 [ Fri Dec 02, 2005 12:09 pm ]
Post subject: 

Hint Number Four wrote:
addr

Author:  Tony [ Fri Dec 02, 2005 12:20 pm ]
Post subject: 

I just want to point out that hints 2,3 and 4 say the exact same thing, just in a different word

Author:  beard0 [ Fri Dec 02, 2005 12:26 pm ]
Post subject: 

Tony wrote:
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.

Author:  Tony [ Fri Dec 02, 2005 12:33 pm ]
Post subject: 

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 Smile

Author:  beard0 [ Fri Dec 02, 2005 12:36 pm ]
Post subject: 

Tony wrote:
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 :)


Tony's hint wrote:
Variable has no value

Author:  Cervantes [ Fri Dec 02, 2005 4:41 pm ]
Post subject: 

beard0 wrote:
Tony wrote:
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. Sad

On a topic related to the Tony's Hint, Cervantes wrote:

Well, I know the reason why b has no value. If anyone wants to collaborate with me...

Shifty

Author:  [Gandalf] [ Fri Dec 02, 2005 5:22 pm ]
Post subject: 

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 Confused It might be on the right track, but I have a feeling there is quite a bit more to it than that...

Author:  MysticVegeta [ Sat Dec 03, 2005 6:01 pm ]
Post subject: 

Hmm I get the logic of it, and what error it should give but i am having a hard time implementing it. Mad

Author:  beard0 [ Mon Dec 05, 2005 9:22 am ]
Post subject: 

Errr. [Gandalf], this is also still a contest - not so much on the unofficial hints eh? If you like, PM me your partial solutions, and I'll post at the end how things were going.
Hint Number whatever-this-is wrote:
put "" + chr(128)


Cervantes: Unless you happen to know these commands, this will be impossible without the reference manual:

Turing Manual wrote:
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) [ id . ] typeId
(b) int, int1, int2 or int4
(c) nat, nat1, nat2 or nat4
(d) boolean
(e) char [ ( numberOfCharacters ) ]
(f) string [ ( maximumLength ) ]
(g) addressint
In form (a) the beginning identifier id must be the name of a module, monitor or class that exports the typeId. Each of numberOfCharacters and maximumLength must be compile time integer expressions. These are the same target types as in type cheats.
The indirection operator @ takes an integer as an address. This value must fit in the range of addressint. See addressint. See also pointer types and the ^ operator (which accesses objects located by pointers).

Author:  Tony [ Mon Dec 05, 2005 9:41 am ]
Post subject: 

Quote:
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

Author:  beard0 [ Mon Dec 05, 2005 9:59 am ]
Post subject: 

We have a winner! Looking for a more simple version for a second place. (Winners are automatically disqualified from the running for second.)

Author:  beard0 [ Sat Dec 10, 2005 3:30 pm ]
Post subject: 

Entries being not forthcomming, here is the winning code, a Cervantes-Tony collaboration:
Turing:
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:
Turing:
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: Click for your cookie.

Author:  MysticVegeta [ Sun Dec 11, 2005 2:31 am ]
Post subject: 

Oh my god its 128!! I was setting it at different numbers, didnt work!

Author:  beard0 [ Sun Dec 11, 2005 12:03 pm ]
Post subject: 

Try running this code Very Happy:
code:
var a : string
put nat1@(addr (a))

Author:  Tony [ Sun Dec 11, 2005 4:31 pm ]
Post subject: 

umm... yeah, the code was work-in-progress, and I was trying different things in there... and haven't cleaned up the submission. Razz

Thx for the cookie


: