Archive for October 2009

Basket Ball Puzzle : One or 2 of 3

You have a basket ball hoop and someone says that you can play 1 of 2 games. You get $1000 and one shot to get the hoop. Or, you get three shots and you have to make 2 of 3 shots. Which one do you choose? If p is the probability of making a particular shot, what value of p makes you switch games?

Search for a class or a pattern in jar files under a folder

searchJars.sh :

-----------------------------------------------------
#!/bin/bash

while getopts "n:il" optionName; do
case "$optionName" in
i) case_sensitive_op=-i;;
l) long_format=Y;;
n) search_expr="$OPTARG";;
[?]) echo "Usage: searchJars [-i] [-l] -n  ";exit 1;;
esac
done

if [ -z $search_expr ]
then
  echo "Usage: searchJars [-i] [-l] -n ";
  exit 1;
fi

if [ $# -lt 1 ]
then
  echo "Usage: searchJars [-i] [-l] -n ";
  exit 1;
fi

REG_EXPR="$search_expr"
for i in `find . -name "*jar"`
do
  jar tvf $i 2> /dev/null | grep $case_sensitive_op $REG_EXPR > /dev/null
  if [ $? == 0 ]
  then
	echo $i
	if [ "$long_format"  = "Y" ]
	then
	   jar tvf $i | grep $case_sensitive_op $REG_EXPR | awk '{ print "		"$8}'
       echo "-----------------------------------------------------"
	fi
  fi
done
-----------------------------------------------------

Usage:
Usage: searchJars [-i] [-l] -n CLASS_NAME_OR_EXPRESSION

Find the two elements that sum to a particular value

You have an array of ints A[]. How would you find the two elements that sum to a particular value S?
Example:
let
A[] = {1,2,-40,4,20,53}
S=13.
Expected Answer:
53 and -40

Awk Online Books and Tutorials

Linux Shell Scripting Online Guides and Books

Free Perl Books and Tutorials

Here are some good perl links

Free Online Books

  1. Welcome to Perl 5 by Example

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!