Archive for the ‘ Featured ’ Category

The Cube

You just watched the movie ’Cube’ before going to bed. Bad idea – you find yourself in a nightmare where you are also put in a huge cube which has 6 doors. But fortunately you remember an idea from the film about how each of the doors has a numeric code. If decoded correctly it tells you if there is a deadly trap behind it or not.

You read the first code 28733 13412 96476 – and remember that one had to add the digits of each group together (e.g. 2+8+7+3+3 = 23) and test if at least one of the 3 check sums is a prime number. If it is, there is a deadly trap!

Coding Kata

<!DOCTYPE html>
<html>
<head>
	<meta charset=utf-8 />
	<title></title>
	<link rel="stylesheet" type="text/css" media="screen" href="master.css" />
	<script type="text/javascript" src="jquery.min.js"></script>
	<!--[if IE]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<script type="text/javascript">
		function isPrime(text){
			var e = text.split(',');
			for (var i=0; i<text.length; i++){
				var num = 0;
				for (pos = 0; pos < text[i].length; pos++) {
					num = num + parseInt(text[i].charAt (pos))
				}

				console.info("Testing %i, the sum of digits %s.", num, text[i]);

				if (num == 1 || num == 2) {
					console.info("%i, the sum of digits %s, is prime!.", num, text[i]);
					return true;
				}
				for (var divisor = 3; divisor < num; divisor++) {
					if (num % divisor == 0) {
					console.info("%i, the sum of digits %s, is prime!.", num, text[i]);
						return true;
					}
					else {
						console.info(num + ", the sum of digits " + text[i] + ", is not prime.  It is divisible by " + divisor + ".");
						break;
					}
				}
			}
			return false;
		}

		function isTrap(text){
			if(isPrime(text)){
				trap.play();
				return "It's a Trap!";
			}
		    return  "It's safe!";
		}
	</script>
</head>
<body>
	<form>
		<div class="box">
			<h1>Add and Prime</h1>
            <label>
            	<span>Please enter first number</span>
               	<input type="text" class="input_text" id="number1"/>
			</label>
			<label>
               	<span>Tada</span>
               	<input type="text" class="input_text" id="result1"/>
            <label>
				<input type="button" value="Calculate" onclick="$('#result1').val(isTrap($('#number1').val()))">
            </label>
 		</div>
		<audio id="trap" src="itsatrap.mp3">
			Your browser does not support the audio element.
		</audio>
</body>
</html>

Caesar plays Lottery

Write a method to convert a number between 1 and 50 to its Roman numeral equivalent.
(for example: 2 = ’II’, 10 = ’X’, 25 = ’XXV’, 50 = ’L’)

Coding Kata

<html>
<body>
<script type="text/javascript">
	function deromanize( roman ) {
	  var roman = roman.toUpperCase(),
		  lookup = {I:1,V:5,X:10,L:50,C:100,D:500,M:1000},
		  arabic = 0,
		  i = roman.length;
	  while (i--) {
		if ( lookup[roman[i]] < lookup[roman[i+1]] )
		  arabic -= lookup[roman[i]];
		else
		  arabic += lookup[roman[i]];
	  }
	  return arabic;
	}

	document.write(deromanize("VIII"));
</script>
</script></body>
</html>

NASA Countdown

The NASA wants to shoot yet another rocket to the orbit. As this is your first day as a wannabe scientist at the ground control, you are very excited. So excited that when the guy responsible for the countdown asks you to bring him some coffee, you accidentally spill it all over his lap and the computer – both are not capable of doing their job now.

But the liftoff is only seconds away. Somebody has to do the countdown – or the rocket can’t start and millions of dollars are lost! In a moment of great bravery you remember you learnt how to count (a long time ago in High School). So you take the chance!

The ground control chief will tell you where to start – then count to 0.
(example for ’11’: 11 10 9 8 7 6 5 4 3 2 1 0)

Coding Kata

<html>
<body>
<script type="text/javascript">
	function countdown(start){
		for (i=start; i>=0; i++){
			document.write("T-MINUS " + i + "<br />");
		}
	}

	countdown(20);
</script>
</body>
</html>

Tea Party

Your task is to welcome your guests properly: Some are female and some were knighted by the queen. So greet them correctly – or this will be your last hosting.

For example:
-Jane Austen is a women, so say Hello Ms. Austen
-George Orwell is a man, so say Hello Mr. Orwell
-Isaac Newton was knighted, so say Hello Sir Newton

Good luck with your party!
Coding Kata

<html>
<body>
<script type="text/javascript">
	function welcome(lastName, isFemale, isSir){
		if (isSir)
			return "Hello Sir " + lastName + "<br />";
		else if (isFemale)
			return "Hello Ms. " + lastName + "<br />";
		else
			return "Hello Mr. " + lastName + "<br />";
	}

	document.write(welcome("Austen", true, false));
	document.write(welcome("Orwell", false, false));
	document.write(welcome("Newton", false, true));
</script>
</body>
</html>

Fibonacci Killer

Calculate the missing Fibonacci numbers in order to predict where that murderer is gonna strike next!

Coding Kata

<script type="text/javascript">
   var runlimit = 12;
   var num1=0, num2=1, ans;
   function getNextFib(){
      ans = (num1 + num2);
      num1 = num2;
      num2 = ans;
      return ans;
   }
   function isPrime(num){
      for(x = num-1; x > 1; x--){
         if(ans % i == 0)
            return false;
         }
         return true;
      }
      for(i = 0; i < runlimit; i++){
         var x = getNextFib();
         document.write(x);
         if(isPrime(x))
            document.write(" is prime!");
            document.write("<br>");
        }
   }
</script>

Fuzz Buzz

Any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizzbuzz. A player who makes a mistake has to take a drink.
Einstein will choose a random number to start with – for example: 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz…

Coding Kata

<script type="text/javascript">
   var i=0;
   for (i=0;i< =100;i++) {
      if (i%3 == 0 && i%5 == 0) {
         document.write("The number is Fuzz Buzz");
         document.write("<br />");
      } else
      if (i%3 == 0) {
         document.write("The number is Fuzz");
         document.write("<br />");
      } else if (i%5 == 0) {
         document.write("The number is Buzz");
         document.write("<br />");
      } else {
         document.write("The number is " + i);
         document.write("<br />");
      }
   }
</script>

Apple to Announce Earnings Next Week, May Have Sold 4 Million Macs

Apple will announce it’s FY 2011 First Quarter Earnings Results earnings on Tuesday, January 18 at 5:00 P.M. EST. Apple will provide live audio streaming of the call, and the stream will be available for two weeks after.The earnings call will reveal just how well Apple products sold during the holiday season. With the recent report that PC sales were not stellar during the same period, many analysts are speculating that consumers opted for iPads and Macs instead of buying a new PC.Another report from Fortune predicts that Apple may have sold as many as four million macs during this past quarter. Of the 31 analysts polled in the report, the average was 3.84 million macs. This was first quarter to feature the revamped Macbook Air at a much more consumer-friendly price, and new iMac models were released during the summer months.Although we’ll have to wait until Tuesday for the official numbers, unofficial results appear extremely high across the board, not just for the new Macs. Another report looked at 50 apple retail stores, and it seems evident that consumers flocked to the iPad during it’s first holiday season. Analyst Chris Whitmore pointed out that Apple benefited great because the iPad had

via Apple to Announce Earnings Next Week, May Have Sold 4 Million Macs.

Strait Power turbine is water-powered, shark-inspired (video) — Engadget

Strait Power turbine is water-powered, shark-inspired (video) — Engadget.

The basking shark, with its five foot jaw, is one of the most ferocious looking critters that ever swam the sea. However, it’s pretty much harmless, just filtering out tiny bits and leaving idle dippers and their water wings alone. This is what served as the inspiration for Anthony Reale, who turned that gaping maw into Strait Power. It’s effectively a double-nozzle that fits around a hydro turbine or two, turning the flow of water into electrical power, boosting the efficiency of the turbine by creating areas of high pressure ahead and low pressure behind, as visualized above. The result was a 40 percent boost in efficiency — and some soggy jeans, as you can see in the videos below. The first gives a quick overview, the second an uber-detailed discussion of the development from start to finish. Choose your path

Verizon iPhone in time For Valentines Day

Verizon iPhone
Verizon chief operating officer Lowell McAdam announced today that a version of the iPhone 4 compatible with its network would be available for pre-order to existing customers beginning February 3, with general availability February 10. The culmination of more than two years of rumors came as almost an anticlimax, as virtually every media outlet was reporting the Verizon iPhone as fact before it was announced. “If the press writes about something long enough and hard enough, eventually it comes true,” McAdam said, acknowledging the long wait for a second carrier in the United States. Apple COO Tim Cook, who joined McAdam on stage at New York’s Lincoln Center, hailed the step, saying Apple was “incredibly pleased to give Verizon’s customers the choice we’ve been waiting for.”

SmithDesign has gone Google

SmithDesign has gon Google

http://www.google.com/a/smithdesign.us