Add Scroogle to your search area in Firefox 2.0 Install the 'Scroogle Scraper' search plugin.

and no, I’m not talking about the Utah Summer Games Arm Wrestling competition.

I’m talking about Python, the programming language. And to encourage adoption of that language some clever people created a little Python programming game (back in 2005.) You’re presented with a riddle of sorts and you’re supposed to code up a python script to solve it. Only, I don’t like people telling me what to do, so I intentionally did NOT code up python to solve them. I used PHP mostly. Here are my notes:

QUESTION 1: what’s 2^38?
ANSWER: I asked google: http://www.google.com/search?hl=en&q=2%5E38&btnG=Google+Search
and then I used the answer to get to the next step: 274877906944.html

QUESTION 2: given: K->M, O->Q, E->G, decode: g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr’q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.
ANSWER: I used an online cryptogram solver (though i could have written a simple script to shift up two letters…)
“map” then, shifts to “ocr”, which leads to http://www.pythonchallenge.com/pc/def/ocr.html

QUESTION 3: Find rare characters in the mess below (mess omitted)
ANSWER: php:

$challenge=file_get_contents(‘phychall2.txt’);
echo(ereg_replace("[^a-z]","",$challenge));

which produces: http://www.pythonchallenge.com/pc/def/equality.html

QUESTION 4: “One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.”
ANSWER: I used textpad’s regex ([a-z][A-Z][A-Z][A-Z][a-z][A-Z][A-Z][A-Z][a-z]) and found “linkedlist”, which means: http://www.pythonchallenge.com/pc/def/linkedlist.html

QUESTION 5: “urllib may help. DON’T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough”
ANSWER:

$linked="12345";
for($x=0;$x<400;$x++)
{
$page=file_get_contents("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=$linked");
echo($page."n");
 $previouslinked=$linked;
 $linked=‘’;
list($blank,$linked)=@split(‘and the next nothing is ‘,$page);
 $pos = strpos($page, "Divide");
if ($pos === false)
{
  if ($linked==‘’) die();
}
 else
{
   $linked=$previouslinked/2;
   echo("divide found!!");
 }
echo($linked."n");
}

which produces: http://www.pythonchallenge.com/pc/def/peak.html

QUESTION 6: peak hell
ANSWER:
arghh. have to use python…need to load the pickle dump:

import pickle
unpicklefile = open(‘banner.p’, ‘r’)
unpickledlist = pickle.load(unpicklefile)
unpicklefile.close()
for item in unpickledlist:
        print item
 
python unpickle.py > nextstep.txt

lines look like: [(’ ‘, 14), (’#', 5), (’ ‘, 70), (’#', 5), (’ ‘, 1)]

parse them with:

$problem=file("nextstep.txt");
$parseout=array(‘(’,‘]’,‘)’,‘[’,"’");
function printit($value,$times)
{
  for($loop=0;$loop<$times;$loop++)
    echo($value);
}
foreach($problem as $line)
{
  $tuples=split(‘),’,$line);
  foreach($tuples as $tuple)
    {
      list($first,$second)=split(‘,’,$tuple);
      $first=trim(str_replace($parseout,‘’,$first));
      if ($first==‘’) $first=‘ ‘;
      $second=trim(str_replace($parseout,‘’,$second));
      printit($first, $second);
    }
  echo("n");
}

which produces a nifty ascii art version of: http://www.pythonchallenge.com/pc/def/channel.html

QUESTION 7: : now there are pairs (in http://www.pythonchallenge.com/pc/def/channel.zip)
ANSWER:

$linked="90052";
for($x=0;$x<909;$x++)
{
  $bigArray[]=system("zipinfo -v channel.zip {$linked}.txt|tail -3|head -1",$retval);
  $page=file_get_contents("{$linked}.txt");
  $previouslinked=$linked;
  $linked=‘’;
  list($blank,$linked)=@split(‘Next nothing is ‘,$page);
  $pos = strpos($page, "Collect");
  if ($pos === false);
  else
    {
      $x=10000;
    }
}
$counter=2;
foreach($bigArray as $dot)
{
  if ($dot==‘’) $dot=‘ ‘;
  echo($dot);
  if ($counter++%65==1) echo("n");
 }

Which produces more ASCII art and leads to: http://www.pythonchallenge.com/pc/def/oxygen.html

QUESTION 8: the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
ANSWER:

$im = imagecreatefrompng("oxygen.png");
for($x=3;$x<629;$x+=7)
{
$rgb = imagecolorat($im, $x, 46);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
 echo(chr($r));
}

more code:

$thelist=array(105, 110, 116, 101, 103, 114, 105, 116, 121);
foreach($thelist as $entry)
{
  echo(chr($entry));
}

http://www.pythonchallenge.com/pc/def/integrity.html

QUESTION 9:
un: ‘BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
pw: 'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'
ANSWER: missing link : bee
use commandline python, arghh…

s = "BZh91AY&SYAxafx82rx00x00x01x01x80x02xc0x02x00 x00!x9ah3Mx07<]xc9x14xe1BAx06xbex084"
import bz2
bz2.decompress(s)
‘huge’
t = "BZh91AY&SYx94$|x0ex00x00x00x81x00x03$ x00!x9ah3Mx13<]xc9x14xe1BBPx91xf08"
bz2.decompress(t)
‘file’
<code></p>
<p><strong>QUESTION 10: </strong>first+second=?<br>
<strong>ANSWER: </strong>
connect the dots
<code>[php]
$image = imagecreatefromjpeg("good.jpg");
$col_poly = imagecolorallocate($image, 255, 0, 0);
$firstArray=array(146,399,163,…);
$secondArray=array(156,141,165,…);
imagepolygon($image, $firstArray,count($firstArray)/2, $col_poly);
imagepolygon($image,$secondArray,count($secondArray)/2,$colpoly);
header("Content-Type: image/jpeg");
imagejpeg($image);

http://www.pythonchallenge.com/pc/return/cow.html
http://www.pythonchallenge.com/pc/return/bull.html

QUESTION 10: a = [1, 11, 21, 1211, 111221, len(a[30]) = ?
ANSWER:
googled for code:

#!/usr/bin/perl
$str="1"; for (1 .. shift(@ARGV)) { print($str, ", "); @a = split(//, $str); $str=""; $nd=shift(@a); while (defined($nd)) { $d=$nd; $cnt=0; while (defined($nd) && ($nd eq $d)) { $cnt++; $nd = shift(@a); } $str .= $cnt.$d; } } print($str);

paste into textpad for character count
http://www.pythonchallenge.com/pc/return/5808.html

QUESTION 11: odd even
ANSWER:
PBM (Portable BitMap) file (PBM stores single bit pixel image as a series of ascii “0″ or “1″’s. The magic identifier for PBM is “P1″.)

32 0s and 1s (separated by spaces) on 20 rows makes 640
then switch to 1s and 0s and do this 240 times


print "P1\n", "640 480\n";
my $odd = ( "0 1 " x 16 . "\n" ) x 20;
my $even = ( "1 0 " x 16 . "\n" ) x 20;
for ( 1 .. 240 ) { print $odd, $even }

gimp:
load image
load mask.txt as a layer
select that layer
layer->color to alpha
white->alpha

produces: evil

Maybe you, too, are forced to use a web app that doesn’t support Firefox? At my work, we use Salesnet.com. Says salesnet.com’s login help screen “The application supports Internet Explorer 5.0, 5.5, 6.x, and 7.x. You cannot login with any other browser.”

That’s pretty inconvenient, particularly because it doesn’t even do a very good job in IE 7.0. It keeps complaining about the pop-up blocker being on, when the pop-up blocker is clearly off. Annoying.

Enough of this silliness! I installed the User Agent Switcher Firefox extension, restarted firefox, instructed the extension to identify my browser as IE 6.0 and HUZZAH! I could log into salesnet.com and do my work.

Nice job dumb Salesnet.com people.

As you probably know, Microsoft released its long awaited XP successor, Vista. Some have asked what I think of it. I’ve played around with Vista a bit at work and my firm recommendation is to NOT UPGRADE TO VISTA. There is no compelling advantage. Indeed, I’m aware of many negative effects of upgrading: programs not running, device drivers not working etc.

As well, Microsoft recently released Office 2007, which contains new versions of Excel and Word. Here’s the catch: the default file format .xlsx and .docx ARE NOT BACKWARD COMPATIBLE! That is the epitome of stupidity. Purely retarded. Why would they do that?!?!?

My next desktop operating system will surely not be Vista. It will be a version of Linux. Linux has not, in my opinion, been ready for the desktop for some time, but it’s becoming better and better all the time. Stay tuned!

In my last blog entry on GPS and Google Maps, I gave the PHP source to a file that queries the USB attached GPS device, parsed the XML and returns a JSON encoded array with values containing the latitude and longitude and timestamp and if the current position has moved significantly. Now we need a webpage to call that php code and display a google map:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <script language="JavaScript" type="text/javascript" src="/js/prototype.js"></script>
  <script>
  function GetXmlHttpObject()
  {
     return Try.these(
           function() {return new XMLHttpRequest()},
           function() {return new ActiveXObject(‘Msxml2.XMLHTTP’)},
           function() {return new ActiveXObject(‘Microsoft.XMLHTTP’)}
      ) || false;
}
function queryGPSunit()
{
	document.getElementById("status").innerHTML="querying GPS…"
	var url="queryGPSunit.php"
	xmlHttp=GetXmlHttpObject()
   	if (xmlHttp==null)
   	{
   	  alert ("Browser does not support HTTP Request")
   	  return
	}
         xmlHttp.onreadystatechange=GPSreturned
         xmlHttp.open("GET",url,true)
         xmlHttp.send(null)
}
var first=1;
var long=0;
var lat=0;
var timeStamp =0;
function GPSreturned()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    //alert(xmlHttp.responseText)
    eval("var decoded_data = "+xmlHttp.responseText);
    lat = decoded_data[0]
    long = decoded_data[1]
    timeStamp = decoded_data[2]
    moved = decoded_data[3]
 
    if (moved==1||first==1)
    {
     document.getElementById("currentGPS").innerHTML=lat+" "+long+" "+timeStamp
     document.getElementById("status").innerHTML="moving"
     first=0
     load(lat,long)
    }
    else
    {
    document.getElementById("status").innerHTML="paused"
    setTimeout(‘queryGPSunit()’, 4000);
    }
    }
}
  </script>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=[insert your key here]"
      type="text/javascript"></script>
    <script type="text/javascript">
 
    //<![CDATA[
 
    function load(lat,long) {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(lat,long), 16,G_HYBRID_MAP);
        var point = new GLatLng(lat,long);
        map.addOverlay(new GMarker(point));
        setTimeout(‘queryGPSunit()’, 4000);
      }
    }
 
    //]]>
    </script>
  </head>
  <body onload="queryGPSunit()" onunload="GUnload()">
  <table><tr><td>
    <div id="map" style="width: 700px; height: 500px"></div>
    </td><td>
    <b>GPS and timestamp: </b><div id="currentGPS"></div><br />
    <b>Status:</b> <div id="status"></div>
    </td>
    </tr>
    </table>
  </body>
</html>

In my other blog I just wrote about my GPS + Google Maps Mashup.

Here are some details I left out of that entry:

Here is my PHP file for querying the Garmin GPS unit:

class GPSblob
{
	var $lat;
	var $long;
	var $timeStamp;
 
	function GPSblob($lat,$long,$timeStamp)
	{
	$this->lat=$lat;
	$this->long=$long;
	$this->timeStamp=$timeStamp;
	}
	function deltalat($lat)
	{
		return (abs($lat-$this-&gt;lat));
	}
	function deltalong($long)
	{
		return (abs($long-$this-&gt;long));
	}
}
session_start();
include_once("xmlparser.php");
$threshold=.005;
 
$cmd="c:\gpsrun.bat.lnk";
//this is the command I’m running: 
//"gpsbabel.exe -i garmin,get_posn -f usb: -o kml -F myposition.kml"
$cmdline = "cmd /C $cmd";
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmdline, 0, true);
sleep(1);
$data=file_get_contents("myposition.kml");
 
$xml = new XML_Array($data);
$xmlarray = $xml-&gt;_data;
$parsed = split(‘Created ‘,$xmlarray[0][kml][Document][Snippet]);
$timeStamp=$parsed[1];
list($long,$lat,$delete)=
split(",",$xmlarray[0][kml][Document][Folder][Placemark][Point][coordinates]);
 
$blob=new GPSblob($lat,$long,$timeStamp);
 
if (empty($_SESSION[‘blob’]))
{
   $_SESSION[‘blob’] = $blob;
}
else
{
   $previousBlob=$_SESSION[‘blob’];
   $deltalat = $blob-&gt;deltalat($previousBlob-&gt;lat);
   $deltalong = $blob-&gt;deltalong($previousBlob-&gt;long);
   $moved=0;
   if (($deltalat&gt;=$threshold)||($deltalong&gt;=$threshold))
   {
   	$moved=1;
   }
   $_SESSION[‘blob’] = $blob;
}
require_once(‘json.php’);
$json = new Services_JSON();
 
$value = array($lat,$long,$timeStamp,$moved);
$output = $json-&gt;encode($value);
print($output);

eggdrop.jpgThe puzzle “You have two hard eggs. But the question is ‘how hard are they?’ You have a 100 story building and only the two eggs, how would you find out which is the highest floor of the building you can drop the eggs from, before they break? It could be the 1st floor but it could also be the 99th floor—you must try dropping the eggs from different floors and see what happens. Your goal is to find the answer with the least number of egg drops.”

50th floor, worst case: egg 1: floor 50, 100 (break), then Egg 2: 51-99 : 2 + 49
25th floor, worst case: egg 1: floor 25, 50, 75, 100 (break), then Egg 2: 76-99: 4 + 24
10th floor: Egg 1: floor 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (break), Egg 2: floor 91, 92, 93, 94, 95, 96, 97, 98, 99: 10 + 9 drops

a function which models this is:

f(x) = 100/x + (x-1), where x is a positive integer less than or equal to 100

to find the local minima of function f(x), take the derivative of f(x) and set it equal to zero

f’(x) = -100/x^2 + 1 = 0

x = 10

So f(x) has a minimum at 10, which is the optimal solution

reference

Over on my other site I just posted a blog entry about a Dominos pizza ad campaign where each day they release a word puzzle and if you solve the puzzle you get a link to an eBay auction where the first ten people that day (for only $9.99) can buy pretty cool stuff, like an iPod or a year’s worth of pizza.

The puzzles are one of three forms: Word Jumbles, CryptoQuips or Domino’s Trivia. The Word Jumble is just as it sounds; they scramble the letters of some Domino’s themed sentence around and you get to unscramble it. For example: MOIODSN HITNNYGA SOGE ALED

Here’s the link to my Word Jumble solver Domino’s Pizza Anything Goes Deal Helper Script

And here is the code:

if (isset($_REQUEST["word_jumble"])&&$_REQUEST["word_jumble"]!=‘’)
{
 
$vocabArray=array(‘2-liter’,‘a’,…,‘Vine-Ripened’,‘wings’);
 
$lookuptable=array();
foreach($vocabArray as $vocab)
{
  $str=strtoupper($vocab);
  $tempArray= array();
  for($i=0; $<strlen($str); $i++)
    {
      $tempArray[]=$str[$i];
    }
  sort($tempArray);
  $tempStr=implode(‘’,$tempArray);
  $lookuptable[$tempStr]=$vocab;
}
$wordArray=explode(‘ ‘,$word_jumble);
foreach ($wordArray as $word)
{
  $str=strtoupper($word);
  $tempArray= array();
  for($i=0; $<strlen($str); $i++)
    {
      $tempArray[]=$str[$i];
    }
  sort($tempArray);
  $tempStr=implode(‘’,$tempArray);
  $unscrambled = ($lookuptable[$tempStr]==‘’)?‘?????’:$lookuptable[$tempStr];
  echo($word." = ".$unscrambled."n ");
}

Over in the other blog, I posted three more bot posts. Here are the links:

The other day Beau Scott accused me of neglecting my tech blog, so I thought I’d better post something here. Yes, I know, it’s just a repost from my regular blog. Sorry. :(

Just about every week I get an email/text/IM/comment from someone who stumbles across my blog and then finds my talking robot. Many describe the feature as one of the best on the site. If you haven’t yet discovered the talking bot, (or if you want to have some more fun) now is as good a time as any to click on over and begin your chats. If the conversation is particularly funny, post it here in the comments for us all to enjoy. Happy Talking!

Did I write the bot myself? No, it’s just an AliceBot PHP app. When i get some time, I’ll modify it. I think that AIML has promise. Do you? Discuss.

The people over at Drivl.com created a pretty funny list of things that Code Doesn’t Do In Real Life. Among the list:

  • Code is not green text on a black background
  • Code isn’t just 0100110 010101 10100 011
  • Code does not make blip noises as it appears on the screen

In my list of unreal computer portrayals :

1- the infinite zoom: where a computer can “enhance” a very low-res, grainy picture and “zoom” way in to see all the hidden stuff
2- the fingerprint/face match program which displays EACH fingerprint/face as the program searches through them. That would take forever and is stupid.
3- when “hackers” can sit down at a computer without the use of other programs, guess secret passwords in a limited number of tries
4- the “take control of the traffic lights” hack. maybe in GIGANTIC cities, they have automatic control of lights, but everywhere else, the lights are so retarded, they routinely stop traffic for “phantom cars” crossing the other way.

« Previous PageNext Page »

Send to a friend * Print this page * Join the club * Talk with my robot * Advertise here * Search this Site * Donate * Link to me


Web hosting by Utah Hub *  Powered by CreativeTap *  In association with Segomo
Unless otherwise noted, Copyright 2004-2006, Ryan Byrd. All Rights Reserved.
Ryan Byrd dot net -- probably the coolest site in Utah