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:

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)

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?

Date: 2009-03-12 02:55 pm (UTC)
From: [identity profile]
The symbol you use is arbitrary, but I agree using a "0" would just be asking for confusion. Using "1" makes intuitive sense -- base 1 is basically just tally marks.

You can't write a 0 in base 1. 0 in base 1 is just the absence of any marking.

Date: 2009-03-12 04:38 pm (UTC)
From: [identity profile]
There is no 10 in Base10, only 1 ten and 0 ones, there is no 2 in Base2 only 1 two and 0 ones...

In Base-n, the counting digits never reach n because it would mean taking advantage of the next numeric place...

So Base-1 should only be allowed to use the counting digit of 0.

Date: 2009-03-12 06:26 pm (UTC)
dwivian: (Default)
From: [personal profile] dwivian

The base, in base N, means the index number for which exponentiation is done to achieve a value for counting marks in a given position in a position-based numerical system prior to summation of those marks to determine a value for the number as recorded, in number systems where logarithms are defined. The base, or radix, is used to determine the potential values of numbers in that position thusly: the index in that position is multiplied by the value of the exponentiation of the base taken as base raised to the power of the quantity of the number of positions left of the radix point minus one.

In base 10, the first position is 10^0=1. The next is 10^1=10, and the next is 10^2=100. A number in position 2 can take on the values of 0 through 90 by tens, as the allowed indexes, 0-9, are multipled by 10 (10^1) to determine their value.

1, taken to ANY positive integer power, is itself. This will generate a tally system, as you indicate. 0 still works, as it indicates that there is no count in that position, but we need another character to indicate a mark. Tradition says you can't put the radix value in a position, but in this case it is the only alternative we have. The question remains: does this system allow for logarithms?

The answer is no -- since a given tally mark no longer gives any real referent to the position it is in, the logarithm of the number is immaterial. It is possible to create the number 11011 and 110000011 to mean the same thing, that is, four marks. The potential exponents involved are undefined.

So, base 1 fails to be meaningful. It's still fun to think about.


hugme: (Default)

April 2011

17 181920212223

Most Popular Tags

Style Credit

Expand Cut Tags

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