Code Quiz!

Ah, I was wondering - thought I was seeing things... but the clearing of my potential stupid questions and lack of many years of experience with a "noob" reference still has effect :D

I'm still curious about the whole "int main void()" reference... Maybe I missed something along the way, but where does void fit in? Perhaps someone could help me out of my misery

I think its meant to be

Code:
int main(void)

Slight typo...
 
To me this is a math question:
x = 1.0;
n = 1e308 = 10^308
d = x/n
= 1.0
----
10^308
= 10^-308.
= 10e-308

e = (1.0 + 10^-308)^(10^308)
= 1.0^(10^308) + (10^-308) ^(10^308)
= 1.0 + 10^(-3080^308)
= 1.0 + 10^(-948640)

Now 10^(-948640) << 1 so we can assume 0 for this application.

e = 1.0;

QED

correct, the problem wasnt the code it was the interest of the equation:)
 
Friday afternoon program.

H dftactgrp(*no)
H actgrp(*caller)
D DS
D idx 2 0 inz(99)
D idxAlpha 2A overlay(idx:1)
D F3 c x'33'
D sa_norm c x'20'
D sa_highlight c x'22'
D BeerLine1 s 30 inz(' Bottles of beer on the wall, ')
D BeerLine2 s 17 inz(' Bottles of beer ')
D BeerLine3 s 32 inz('Take one down and pass it +
D around')
D ExitStr s 43 inz('Press Enter to Continue or +
D Press F3 to Exit')
D txt s 128
D txtlen s 9b 0 inz(132)
D err s 8 inz(x'0000000000000000')
D aid s 1
D lines s 9b 0 inz(1)
D wf1 s 1
D wrtn s 9b 0
D ClrScr PR 9b 0 extproc('QsnClrScr')
D mode 1 options(*nopass) const
D cmdbuf 9b 0 options(*nopass) const
D env 9b 0 options(*nopass) const
D error 8 options(*nopass)
D WrtDta PR 9b 0 extproc('QsnWrtDta')
D data 128
D datalen 9b 0
D fldid 9b 0 options(*nopass) const
D row 9b 0 options(*nopass) const
D col 9b 0 options(*nopass) const
D strmatr 1 options(*nopass) const
D endmatr 1 options(*nopass) const
D strcatr 1 options(*nopass) const
D endcatr 1 options(*nopass) const
D cmdbuf 9b 0 options(*nopass) const
D env 9b 0 options(*nopass) const
D error 8 options(*nopass)
D GetAID PR 1 extproc('QsnGetAID')
D aid 1 options(*nopass)
D env 9b 0 options(*nopass) const
D error 8 options(*nopass)
D RollUp PR 9b 0 extproc('QsnRollUp')
D lines 9b 0 const
D top 9b 0 const
D bottom 9b 0 const
D cmdbuf 9b 0 options(*nopass) const
D env 9b 0 options(*nopass) const
D error 8 options(*nopass)
**************************************************************************************
* Mainline
**************************************************************************************
/FREE
wrtn = ClrScr('4' : 0 : 0 : err);
txt = ExitStr;
txtlen = %Len(txt);
wrtn = WrtDta (txt : txtlen : 0 : 1 : 2 :
sa_norm : sa_norm : sa_highlight : sa_highlight :
0 : 0 : err);
for idx = 99 Downto 1;
txt = idxAlpha + BeerLine1 + idxAlpha + BeerLine2 + BeerLine3;
txtlen = %Len(txt);
wrtn = WrtDta (txt : txtlen : 0 : 26 : 2 :
sa_norm : sa_norm : sa_norm : sa_norm :
0 : 0 : err);
wf1 = GetAID (aid : 0 : err);
If aid = F3;
Leave;
EndIf;
wrtn = RollUp (lines : 2 : 27 : 0 : 0: err);
endfor;
*INLR = *ON;
/END-FREE
 
That is 99 Bottel Of Beer in RPG, cool man :)

Unfortunately you didn't cater for the last case...

Press Enter to Continue or Press F3 to Exit
99 Bottles of beer on the wall, 99 Bottles of beer Take one down and pass it around
.
.
.
1 Bottles of beer on the wall, 1 Bottles of beer Take one down and pass it around

Assuming no one pressed F3 :p

Where do you work Myrrdin?
 
Last edited:
Here's an interesting on in c#:
[STAThread]
static void Main()
{
byte i = 255;
i = unchecked((byte)(i << 2));
System.Console.WriteLine(i);
}
 
Ah, I was wondering - thought I was seeing things... but the clearing of my potential stupid questions and lack of many years of experience with a "noob" reference still has effect :D

I'm still curious about the whole "int main void()" reference... Maybe I missed something along the way, but where does void fit in? Perhaps someone could help me out of my misery

It must be part of bidirectional C++ ()int main void()
 
Here's an interesting on in c#:
[STAThread]
static void Main()
{
byte i = 255;
i = unchecked((byte)(i << 2));
System.Console.WriteLine(i);
}

Overflowing the byte value is causing a a weird value? care to explain? I'm interested.
 
Sure:
255 in binary is 11111111, which is the max for type byte.

255 << 2 = 1111111100 which if you cast to byte would normally throw an overflow exception;
e.g using my code above (byte) (i << 2) would throw an exception.

However unchecked will truncate the value in the case of an overflow giving:
i = 11111100 = 252.
 
C#:
Code:
    public class Program
    {
        private void AddString(StringBuilder sb, string text)
        {
            sb.Append(text);
        } 

        public void DoIT()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 100; i++)
            {
                this.AddString(sb, i.ToString());
            }
            System.Console.WriteLine(sb.ToString());
        }

        static void Main(string[] args)
        {
            Program myProg = new Program();
            myProg.DoIT();
        }
    }

Found this bit of code quite interesting, so I thought I'd resurrect this thread.

What's the output and more importantly why?
 
Shouldn't you be passing the String Builder object by reference to keep adding text to it? I'm too lazy to copy, paste and compile the code, so my guess would be that the result is just "99"?
 
No one interested in this except FarligOpptreden?

So the answer is
Code:
0123456789...all the way to...9596949899

The reason is because StringBuilder is a reference type, when you pass a reference type by value to a method the reference gets passed by value but it still "points" to the same data in memory.

This means you can alter the data in a reference type even when it's passed by value, but you cannot alter the reference itself (e.g. make it null).

Check out this excellent explanation
 
Ah... My first guess would've been that that would happen, but because this is a code quiz, I thought there would be a catch to it and the object won't be passed by reference. :p
 
Ah... My first guess would've been that that would happen, but because this is a code quiz, I thought there would be a catch to it and the object won't be passed by reference. :p

Well the code quiz part was the fact that the object still gets updated even though it was passed by value.

The following gives the same output (even though it looks like it shouldn't)
Code:
public class Program
{
    public void Add(StringBuilder sb)
    {
        for (int i = 0; i < 100; i++)
        {
            sb.Append(i.ToString());
        }
        [b]sb = null;[/b]
    }

    public void DoIt()
    {
        StringBuilder sb = new StringBuilder();
        this.Add(sb);
        System.Console.WriteLine(sb.ToString());
    }

    static void Main(string[] args)
    {
        Program myProg = new Program();
        myProg.DoIt();        
    }
}
 
Hmmm, I didn't read throught the entire explanation (I suppose I should), but wouldn't the output be as such simply because you are appending multiple strings to each other? I get the point of passing by reference and value, but what I'm trying to get at (mainly after reading Farlig's first response of '99' ) is no where in the code are integers added, only strings are put together...

And please excuse any noobiness :D in the question...
 
Hmmm, I didn't read throught the entire explanation (I suppose I should), but wouldn't the output be as such simply because you are appending multiple strings to each other? I get the point of passing by reference and value, but what I'm trying to get at (mainly after reading Farlig's first response of '99' ) is no where in the code are integers added, only strings are put together...

And please excuse any noobiness :D in the question...

So surely this should give the same output
Code:
public class Program
{
    private void AddString(string text, string character)
    {
        text += character;            
    }

    public void DoIT()
    {
        string text = "";

        for (int i = 0; i < 100; i++)
        {
            this.AddString(text, i.ToString());
        }
        System.Console.WriteLine(text);
    }

    static void Main(string[] args)
    {
        Program myProg = new Program();
        myProg.DoIT();
    }
}

Yet it obviously doesn't.

The point of this code is not the "principle" of pass by reference or pass by value, it's how the CLR handles reference types passed by value, big difference...

So yes you should read the explanation, because it you don't understand how this works you could introduce a bug you'll never find...
 
Can we pass the Baton for an easy one please? I don't know C or it's derivatives yet !
Thanx !

This is a mIRC script using botserv.
What is it or what does it do ?

Code:
on *:TEXT:!Something*:#:{
  if (!$2) { .bs say $chan Syntax Error | halt }
  var %ini $remove($2-,$chr(44))
  var %concl $bytes($calc(%ini),b)
  .bs say $chan $2- = %concl 
}

Give up ? Ok ....
Solution:
The above 6 lines of script are a full functioning Calculator which uses botserv to relay the result.
/me goes back to learning with Visual C# 2008 Express Edition
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X