# This is an example of how these flags work with me having
# default umask of 077. See this file for more information:
#
# http://securemecca.com/public/ChmodTable.txt
#
# Everything starting with a "#" is a comment.
$ ./redyellow
red red red yellow yellow
red red yellow red yellow
red red yellow yellow red
red yellow red red yellow
red yellow red yellow red
red yellow yellow red red
yellow red red red yellow
yellow red red yellow red
yellow red yellow red red
yellow yellow red red red
$ ls -l redyellow
-rwx------ 1 ME ME 7310 2011-04-15 18:06 redyellow
# The first dash indicates it is a normal file. If it
# was a directory it would be a "d", a symbolic link
# is an "l", etcetera. The first three characters
# after that are for User, the next three Group, and
# the last three are for Other. Unix also has a hard
# link and the next number (in this case 1) indicates
# how many hard links there are to this file. It says
# that only ME can read, write, or execute the file.
# Okay, now lets change the file permission flags.
$ chmod 0600 redyellow
$ ls -l redyellow
-rw------- 1 ME ME 7310 2011-04-15 18:06 redyellow
$ ./redyellow
bash: ./redyellow: Permission denied
# Note that since none of User, Group, or Execute is
# set we can NOT execute the file. Do not think it is
# just a function of bash. It has been this way from
# the beginning with the old Bourne shell. Actually it
# is a function of the file system itself, not the
# shell you are using.
$ chmod 0111 redyellow
$ ls -l redyellow
---x--x--x 1 ME ME 7310 2011-04-15 18:06 redyellow
# User, Group, and Other can all run it now
$ ./redyellow
red red red yellow yellow
red red yellow red yellow
red red yellow yellow red
red yellow red red yellow
red yellow red yellow red
red yellow yellow red red
yellow red red red yellow
yellow red red yellow red
yellow red yellow red red
yellow yellow red red red
$ cp redyellow copy
cp: cannot open `redyellow' for reading: Permission denied
# But we cannot copy it
############ END OF INTERACTIVE TERMINAL INPUT ############
Here is the code that was written in a hurry to see if my ball
permutations came out the same way a math teacher did it. The
permutations did NOT come out the same but we both had the
same ones, just in a different order:
#include
#include
#define YELLOW 23
#define RED 3
int myColor[2] =
{
RED,
YELLOW
};
int fiveBalls[5];
void main()
{
int one, two, three, four, five;
int sum, loop, value;
fputs("\n", stdout);
for (one = 0; one < 2; one++)
{
fiveBalls[0] = myColor[one];
for (two = 0; two < 2; two++)
{
fiveBalls[1] = myColor[two];
for (three = 0; three < 2; three++)
{
fiveBalls[2] = myColor[three];
for (four = 0; four < 2; four++)
{
fiveBalls[3] = myColor[four];
for (five = 0; five < 2; five++)
{
fiveBalls[4] = myColor[five];
for (loop = sum = 0; loop < 5; loop++)
{
sum += fiveBalls[loop];
}
if (sum == 55)
{
for (loop = 0; loop < 5; loop++)
{
value = fiveBalls[loop];
switch( value )
{
case RED:
fputs(" red", stdout);
break;
case YELLOW:
fputs(" yellow", stdout);
break;
default:
fputs(" ERROR", stdout);
break;
}
}
fputs("\n", stdout);
}
}
}
}
}
}
fputs("\n", stdout);
exit(0);
}
############ PROGRAM ENDS HERE ############
You may ask why I know that this is the only way it can sum
up to 55. Well, I have a degree in Mathematics but to humor
you, here is a program that shows the sums:
#include
#include
#define YELLOW 23
#define RED 3
int main(void)
{
int yellow, red;
int sum;
fputs("\n", stdout);
for (red = 0; red < 6; red++)
{
yellow = (5 - red);
sum = ((yellow * YELLOW) + (red * RED));
printf("red = %d, yellow = %d, sum = %d\n\n",
red, yellow, sum);
}
exit(0);
}
And here are the sums:
red = 0, yellow = 5, sum = 115
red = 1, yellow = 4, sum = 95
red = 2, yellow = 3, sum = 75
red = 3, yellow = 2, sum = 55
red = 4, yellow = 1, sum = 35
red = 5, yellow = 0, sum = 15
Notice that they all end with 5 and that each are a
magnitude of 20 less / more for the previous / nextt
one.