Archive for June, 2005

An odd question

There are always surprises when marking. But one thing caught both Clintons and my eyes. The number of different ways to determine an odd number. One of the exam question involved printign only the odd numbers in an array of integers. We just assumed people would use the remainder operator in a simple one line operation. Instead we got some very strange answers. We talked about it and agreed that many of the answers were in fact not correct since the students should have known about the remainder operator, but we would give them the points anyway for being able to come up with such creative solutions (on the condition that they actualy worked).

What follows is our collection of the top 8 interesting way to calculate odd nnumbers in Java. The order is simply the order we found them in, not an indication of how good we thought !
they were. Some code has been altered, and names have been removed to protect the innocent ;)

(Sorry about some of the funny formatting. The damn blog engine is striping all the square brackets from the array references, so I had to put extra spaces in. Note to self: work on code formatting module SOON!)

<pre>
<br />class TestForOdd
<br />{
<br /> public static void main(String [] args)
<br /> {
<br /> /*
<br /> * from a question to determine the presence
<br /> * of odd numbers in an array of ints...
<br /> */
<br /> int[] odds = {1,2,3,4,5,6};//setup some numbers to test
<br />
<br /> /*
<br /> * first, the answer we were looking for...
<br /> */
<br /> System.out.println("ideal answer");
<br /> for(int i=0; i {
<br /> if(odds[ i ]%2==1)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * One interesting solution...
!
<br /> * Exploiting integer divisions
<br /> * truncating effect.

<br /> */
<br /> System.out.println("Interesting solution MkI");
<br /> for(int i=0; i {
<br /> double first = (double)odds[ i ]/2;
<br /> int second = odds[ i ]/2;
<br /> if(first-second &gt; 0.001)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * Another solution...
<br /> * Counting in 2&#39;s
<br /> */
<br /> System.out.println("Interesting solution MkII");
<br /> for(int i=0; i {
<br /> int num = 1;
<br /> while(num {
<br /> if(num == odds[ i ])
<br /> System.out.println(odds[ i ]);
<br /> num+=2;
<br /> }
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * A variation on MkI...
<br /> */
<br /> System.out.println("Interesting solution MkIII");
<br /> for(int i=0; i {
<br /> if(odds[ i ] - 2*(odds[ i ]/2)&amp;gt!
;0)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * Don&#39;t know what to say about this one.
<br /> * But it&#39;s cute.
<br /> */
<br /> System.out.println("Interesting solution mkIV");
<br /> for(int i=0; i {
<br /> int x = 1;
<br /> for(int j=0; j x = x*-1;
<br />
<br /> if(x System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * Similar to MkII, but counting backwards in 2&#39;s
<br /> */
<br /> System.out.println("Interesting solution mkV");
<br /> for(int i=0; i {
<br /> int val = odds[ i ];
<br /> while(val&gt;2) val-=2;
<br /> if(val==1)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * Variation on MkI
<br /> */
<br /> System.out.println(&amp;qu!
ot;Interesting solution mkVI");
<br /> for(int i=0; i {
<br /> double one = odds[ i ]/2.0;
<br /> int two = (int)one;
<br /> if(one!=two)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * All odd numbers have least significant bit set
<br /> * This uses the bitwise AND (&amp;) to mask value with 1.
<br /> * Nice :)
<br /> */
<br /> System.out.println("Interesting solution mkVII");
<br /> for(int i=0; i {
<br /> if((odds[ i ] &amp; 1)==1)
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br />
<br /> /*
<br /> * And for those who like a more mathmatical approach...
<br /> */
<br /> System.out.println("Interesting solution mkVIII");
<br /> for(int i=0; i {
<br /> if((1 - Math.pow(-1, odds[ i ]) != 0))
<br /> System.out.println(odds[ i ]);
<br /> }
<br /> System.out.println();
<br /> }
<br />}
<br /></pre>


There were some others, but they were just variations on one of the above themes.]]>

Comments

Time passes slowly when marking exams

I've been so busy with exam marking that I can barley think straight. I'm dreaming the answers to the exam question now. Not nice.

And the one night of the week I look forward to some half decent TV and StarGate's not on?]]>

Comments

Turtle walking on freeway

It's so easy to get spoiled with fast downloads, but now I find myself thinking about usability. Just last night I was looking at some sites and they were comming down so bloody slowly, it was painfull. And consider that broadband still only has about 20% penetration into the home internet market. So while most of us, as developers, probably have fast connection, and when developing on a local machine speed certainly isn't an issue, how easy is it to forget about the other 80% of the market (our clients and customers) who use dialup.]]>

Comments

Tiger crawling from cave

The other issue was that I have been unable to get the laptop to connect to the uni network due to Tiger not playing nice with the Cisco VPN client. I did just down load the newer version and it seems to work. I love the cryptic message on the ITS web site that says “Single proc”. Apparently this means that the new OS X VPN client only works on single processor macs. That's what I've got, so no problems, right?

Well, it kinda sorta works. I'm posting with the laptop now, so I have a connection. And I can reach the outside world through the browser (Firefox for Mac), but when I try to update the software, the connection times out. I don't und!
erstand that one. But I do like the nice new network diagnostic utility in Tiger.

So the tiger is slowly crawling out of it's cave, but I can't quite roam free yet.

I was hoping that the Eduroam network would save me, but apparently it's not configured properly yet, or at least that what the person on the ITS helpdesk is telling me. And we always believe those guys ;)

In other news, I have finaly given up on Outlook. Since buying my PDA almost a year ago, I switched back to Outlook from Thunderbird. Almost everyday I regret it. But I kept telling myself that being able to sync the PDA made it worth while. I am no longer convinced. It's the end of semester, so time to make some changes, and the first of those is that Outlook is going down!

It also looks like Thunderbird has improved it ability to import the address book and mail from Outllook. I remember it being a big issue last time, but now it's !
all fairly straight forward.

Oops, spoke too soon. It&#0
39;s taken ages to import (but I do have a lot of old mail), and now it's telling me “Unable to save message as draft” while importing. But everytime I click the OK button, the dialog just pops right back up. Interestingly, it happens righht about the same time the anti virus software finds an infected file in mail messages being imported. Not sure what's going on there.

So after about 200 clicks of the OK button, we seem to have successfully imported all the old mail.

Now I just have to noodle out how I'm going to use the PDA…

]]>

Comments

If you don't have a dream…

Learning and Doing blog has an interesting article on Entrepreneurship.

It references another article from which I take the following quote:

“…Or more precisely, I think few realize the huge spread in the value of 20 year olds. Some, it's true, are not very capable. But others are more capable than all but a handful of 30 year olds.”

I often get asked by students about job prospects etc (”What's the use of studying Java?” being a common one). I guess what the above articles articulate, and what is central to Swinburnes own philosophy, is that opportunities are where, and what, you make th!
em to be.

Opportunities are out there. But they are not always in the job ads. Create your own opportunities. We are fortunate enough to be in an industry with room for innovators. I guess this comes back to one of the things that I feel is essential to all comp sci students, a strong imagination. (Actually I think most people should have an imagination. Except accountant. I don't want imaginative accounting with my tax return.)

My only crit of the Learning and Doing article is the implication that self starters should aspire to be like Bill Gates. The socialist in me just wants to scream at the attitude that suggests a person is only successful if they are a multi millionaire. I for one would be, and currently am, perfectly happy to just be managing to make ends meet while doing something that I love doing.

Would I be content to run a business doing something I didn’t believe in if I was making truck loads of money? I don’t k!
now. Give me truck loads of money and I’ll tell you how I feel about
it. Until then, I’d like to think that the idealist in me is strong enough to want to do things that I feel are right, and forgo the fortune.

]]>

Comments

drag support?



Improved Drag Gesture in Swing

Which leads me to ask what gesture do drag queens need help with, and what's that got to do with how they swing?

]]>

Comments

Summer of Code

Knowing and Doing blog is picking up on it and has some words of wisdom.

My only gripe? Northern summer imperialists! Just because it's summer in North America. Are they just trying to run our noses in it. Well the jokes on them I guess since we haven't actualy seen winter down here yet ;)

But check out .Googles Summer of Code ]]>

Comments

The Force?

Java 1.5 Concurrency?

Following some of the links in the comments for that blog is also interesting.

Like the link to jarwars

]]>

Comments