Anomalies of Code
By: Gamma Lt Ker Zerhash
When I proposed this section I intended it to be somewhat of a New York Times puzzle section. The focus here will be on code. Post your answers here or CMs to Zerhash. I have my own version of the answer however my opinion isn’t the only opinion. The following issue we will post the answer, as well as other good responses we have. So the game is simple. I provide a simple piece of code. I will specify a context to which it is to be interpreted. From here, you post your answers as to what the output of the code will be. You can use any language you choose. However provide source code for validity. No language sees eye to eye with any other so therefor use your own judgement to most accurately implement my intent.
This issue’s will be simple.
Given s""hello";y{hello}}world};s;(.);\U$1;g;print
Context: Perl style
I am interested to see how this turns out. Please provide as much explanation as you can for why and how you came to your answer.
Last Months Solution
In the previous month we had the following.
c = 0; c = c++; print c;
This is pretty standard and put into a regular C compiler it will be fairly predictable. If you guessed the output to be 1 then you are common with the C compiler.
The purpose of the post increment is to add one to the number following the operation. So from right to left you would be saying: c equals c, now c is to be increased by one.
Now those running older versions of c may have noticed that their results differ. The perl library behaves the same.
Rather than getting the typical ‘1′ as an answer you now get a ‘0′. This is where we notice a difference in operator precedence. In C it is special because the process is delayed right until the very last opportunity. However with operator overloading you will see that things aren’t treated exactly the same.
If i was to code the actual post increment it may look like the following:
int operator ++(int val){ int b=val; val=val+1; return b; }
So what we are saying is. Increase the value to post increment now. But return the old value. So if c started as 0, it is now 1. However we are sending 0 down the line for further processing. This is how perl thinks.
The code: $> perl -e '$c = 0; $c=$c++; print $c'
This is the best zine EVER!! lol
sered secrets inside!!
excellent work.
Great article!
I’m currently working on a cryptography algorithm aswell if anyone wants to have a look;
http://www.codeplex.com/Rexor