fun script

Mar. 12th, 2009 10:36 am
hugme: (Default)
[personal profile] hugme
a friend who is working on learning shell script asked me to do this. Write a script which generates all the letters then reports back whether they are capital or lowercase. It took me a little bit of thinking to come up with one I must admit, but this is what I wrote:

X=101
until [ "$X" -ge 173 ] ; do
printf "\\$X" | grep [A-Z] > /dev/null && printf "\\$X is a capital letter \n" || printf "\\$X is a lowercase letter \n"
[ "$X" = "132" ] && X=140
X=$(echo "ibase=8;obase=8;$X+1"|bc)
done

I had to convert the numbers into octal for printf to display them and had to look up variables to get bc to use base 8. I thought it was just "base" but it uses input base and output base so ibase and obase.

this got me thinking.... What about base 1? every base starts with 0... so base 10 is 0-9, base 16 is 0-F base 2 is 0 and 1... but base 1? Using 0 wouldn't make any sense. for example... in base 1 the number 5 would be: 11111 not 00000 as a 0 would be the absence of a number.

What do you think and why?
From:
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

 
Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

Profile

hugme: (Default)
hugme

April 2011

S M T W T F S
     12
3456789
10111213141516
17 181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 25th, 2017 10:17 pm
Powered by Dreamwidth Studios