#include
#include
int main(){
int ctDeal=0;
int deal[8][52];
int row, col;
// deal the cards
for(row = 0; row < 52; row++){
for(col = 0; col < 8; col++){
deal[col][row] = ctDeal;
ctDeal++;
if(ctDeal > 52){
col = 8;
row = 52;
}
}
}
// show the deal
ctDeal = 0;
for(row = 0; row < 52; row++){
for(col = 0; col < 8; col++){
printf("| %d |", deal[col][row]);
ctDeal++;
if(ctDeal > 52){
row = 52;
col = 8;
}
}
printf("\n");
}
}
Next, a short snippet that takes care of some random numbering and dealing out 13 cards from each suit:
#include
#include
#include
int main(){
int ctSpades = 0;
int ctClubs = 0;
int ctHearts = 0;
int ctDiamonds = 0;
int ctDeal = 0;
srand(time(NULL));
printf("time is %d \n", time(NULL));
int num, num2, row, col;
row = 0;
col = 0;
while(ctDeal < 52){
num = rand() % 4+1;
switch(num){
case 1:
if(ctClubs < 13){
printf("case is Clubs ctClubs = %d -- ctDeal = %d \n", ctClubs, ctDeal);
ctClubs++;
ctDeal++;
}
break;
case 2:
if(ctSpades < 13){
printf("case is Spades ctSpades = %d -- ctDeal = %d \n", ctSpades, ctDeal);
ctSpades++;
ctDeal++;
}
break;
case 3:
if(ctHearts < 13){
printf("case is Hearts ctHearts = %d -- ctDeal = %d \n", ctHearts, ctDeal);
ctHearts++;
ctDeal++;
}
break;
case 4:
if(ctDiamonds < 13){
printf("case is Diamonds ctDiamonds = %d -- ctDeal = %d \n", ctDiamonds, ctDeal);
ctDiamonds++;
ctDeal++;
}
break;
}
}
}
The process is as follows: Fist, generate a random number between 1 and 4 (I.E. the number of suits in a deck of cards); next, a switch statement is hinged upon this random number and a counter for each suit is incremented. If the suit's counter reaches 12 then that suit is empty (that is, it has been dealt out) and a random number is redrawn. However, note that this script outputs the cards in a highly predicable manner. more to come.
=====Data Structures=====
*[[http://lab46.corning-cc.edu/documentation/data|Data Structures (observations)]]
====Linked List Insert====
The linked list is a fairly complex idea that consists of a series of simple ideas. The general idea is to implement a system whereby each element has a reference to the next and/or previous elements in a list. The list could be ordered or unordered. The important part is that the list knows the end of one element and/or the beginning of the beginning of the next.
/*
* linkedlist4.c - singly linked list node insertion
*
*/
#include
#include
// The node
struct node {
int value;
struct node *next;
};
typedef struct node Node;
int main()
{
Node *start, *tmp, *devnull;
int i = 0, input = 0;
start = tmp = NULL;
do {
printf("Enter a value (-1 to quit): ");
scanf("%d", &input);
if ((start == NULL) && (input != -1))
{
start = (Node *) malloc (sizeof(Node));
tmp = start;
tmp -> value = input;
tmp -> next = NULL;
}
else if (input != -1)
{
tmp -> next = (Node *) malloc (sizeof(Node));
tmp = tmp -> next;
tmp -> value = input;
tmp -> next = NULL;
}
} while (input != -1);
tmp = start;
printf("Linked List DISPLAY: ");
while (tmp != NULL)
{
printf ("(%d) %d -> ", i, tmp -> value);
tmp = tmp -> next;
i++;
}
printf ("NULL\n");
tmp = start;
printf("Select Node # to insert before: ");
scanf("%d", &input);
for (i = 0; i < (input - 1); i++)
{
tmp = tmp -> next;
}
if ((i == 0) && (input == 1))
{
i++;
}
printf("Enter value for new node: ");
scanf("%d", &input);
// Create new node
devnull = (Node *) malloc (sizeof(Node));
devnull -> value = input;
if (i != 0) // anything but the first
{
devnull -> next = tmp -> next;
tmp -> next = devnull;
}
else // the first node
{
devnull -> next = start;
start = devnull;
}
tmp = start;
i = 0;
printf("Linked List DISPLAY: ");
while (tmp != NULL)
{
printf ("(%d) %d -> ", i, tmp -> value);
tmp = tmp -> next;
i++;
}
printf ("NULL\n");
return(0);
}
====Linked List Delete====
/*
* linkedlist3.c - singly linked list node deletion
*
*/
#include
#include
// The node
struct node {
int value;
struct node *next;
};
typedef struct node Node;
int main()
{
Node *start, *tmp, *devnull;
int i = 0, input = 0;
start = tmp = NULL;
do {
printf("Enter a value (-1 to quit): ");
scanf("%d", &input);
if ((start == NULL) && (input != -1))
{
start = (Node *) malloc (sizeof(Node));
tmp = start;
tmp -> value = input;
tmp -> next = NULL;
}
else if (input != -1)
{
tmp -> next = (Node *) malloc (sizeof(Node));
tmp = tmp -> next;
tmp -> value = input;
tmp -> next = NULL;
}
} while (input != -1);
tmp = start;
printf("Linked List DISPLAY: ");
while (tmp != NULL)
{
printf ("(%d) %d -> ", i, tmp -> value);
tmp = tmp -> next;
i++;
}
printf ("NULL\n");
tmp = start;
printf("Select Node # to delete: ");
scanf("%d", &input);
for (i = 0; i < (input - 1); i++)
{
tmp = tmp -> next;
}
if (i != 0) // anything but the first
{
devnull = tmp -> next;
tmp -> next = devnull -> next;
}
else // the first node
{
devnull = start;
start = devnull -> next;
}
devnull -> next = NULL;
free(devnull);
tmp = start;
i = 0;
printf("Linked List DISPLAY: ");
while (tmp != NULL)
{
printf ("(%d) %d -> ", i, tmp -> value);
tmp = tmp -> next;
i++;
}
printf ("NULL\n");
return(0);
}
=====Dell Latitude D531 Wifi=====
*[[http://lab46.corning-cc.edu/user/mcooper6/dell_latitude_d531_wifi|Dell Latitude D531 Wifi]]
=====Mac=====
*[[http://lab46.corning-cc.edu/user/mcooper6/rescue_mac|Rescue data from a Mac that won't boot]]
=====Mathy Stuff=====
====The Lab46 Math Pages====
*[[http://lab46.corning-cc.edu/math/start|Lab46 Math Pages]]
*[[http://lab46.corning-cc.edu/math/3x3numbersystems|3x3 Number Systems]]
*[[http://lab46.corning-cc.edu/math/specialproducts|Special Products in Algebra]]
====LaTeX on the Lab46 Wiki====
I asked for, and was awarded with the DokuWiki LaTeX plugin, with hopes that I would be able to find some extra time to explore some mathematic markup and ultimately find a digital den for my math notes. Before I could start, I needed to take a short side-trip through the LaTeX documentation.
Here's an example of a matrix:
D_z
= \left|
\begin{array}{ccc}
y_1 ... C_1\\
\vdots \ddots \vdots\\
y_2 ... C_2\end{array}
\right| -> z = \frac{D_z}{D} => y = \frac{(-4)(-55)-(14)(0)}{(-4)(-12)-(14)(5)} => z = -10
This is the output of the above LaTex:
\begin{array}{3}
-5(3x - 3y + 2z = 11)\\
\underline{+ 15x - y - 2z = 0}\\
14y - 12z = -55\\
.\end{array}\\
This is the output of the above LaTeX
1 Million Bits of Pi
ftell(END) ? ftell(END) - ($max_rows * $chunk * $page_num) : $max_rows * $chunk)
*
* number of pages == ftell(END) / ( $max_rows * $chunk )
* starting digit of page == $page_num * $max_rows * $chunk
*
* end digit of page ==
* ($max_rows * $chunk * $page_num + $max_rows * $chunk > ftell(END) ?
* $max_rows * $chunk * $page_num) + ftell(END) - ($max_rows * $chunk * $page_num)
* :$max_rows * $chunk * $page_num + $max_rows * $chunk);
*/
$i = 0; // iterator
$odd = 0; // number of odd digits per line
$max_odd = 0;
$even = 0;
$max_even = 0;
$sum = 0;
$max_sum = 0;
$primes = 0;
$zeros = 0;
$ones = 0;
$twos = 0;
$threes = 0;
$fours = 0;
$fives = 0;
$sixes = 0;
$sevens = 0;
$eights = 0;
$nines = 0;
$file_name = "pi.txt";
$f = fopen($file_name, "rb");
//ECHO TITLE
echo "1 Million Bits of Pi";
// BEGIN PAGINATION (minimal use of variables)
$p = (int)$_GET['p']; //page sought
echo "";
// go to the place sought
fseek($f, $chunk*$max_rows*$p);
echo ($p > 1 ? "" : "");
echo ($p > 0 ? "" : "");
// loop nearby previous page lines
$n = ($p < 1 ? 0 : ($p < $nearby ? 0 : $p-$nearby ));
$limit = $p;
for($n; $n < $limit; $n++){
echo "" . $n . "";
}
echo "Page : " . $p . "";
// go to end
fseek($f, -$chunk*$max_rows, SEEK_END);
// loop nearby next page lines
$n = $p+1;
$limit = ($p+$nearby < round(ftell($f)/($chunk*$max_rows)+0.5) ? $p + $nearby: round(ftell($f)/($chunk*$max_rows) + 0.5));
for($n; $n <= $limit; $n++){
echo "" . $n . "";
}
echo ($p < ftell($f)/($chunk*$max_rows) ? "" : "");
echo ($p != round(ftell($f)/($chunk*$max_rows)+0.5) ? "":"");
// back to the place sought
fseek($f, $chunk*$max_rows*$p);
echo "";
// END PAGINATION
echo "";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo "";
echo "";
echo "Showing digits " . ftell($f) . " thru " . (ftell($f) + $chunk*$max_rows -1) . "";
echo " Occurence of Each Digit ";
echo " ";
echo "i 64 Bits of Pi Even Odd Primes Sum ";
echo "Zeros Ones Twos Threes Fours ";
echo "Fives Sixes Sevens Eights Nines ";
echo " ";
echo "";
$i = $p*$max_rows;
while (!feof($f) && $i < ($p*$max_rows+$max_rows)) {
$d = fread($f, $chunk);
$a = str_split($d);
foreach($a as $v){
if($v % 2 == 0){
$even++;
}else{
$odd++;
}
$sum += $v;
switch($v){
case 0:
$zeros++;
break;
case 1:
$ones++;
$primes++;
break;
case 2:
$twos++;
break;
case 3:
$threes++;
$primes++;
break;
case 4:
$fours++;
break;
case 5:
$fives++;
$primes++;
break;
case 6:
$sixes++;
break;
case 7:
$sevens++;
$primes++;
break;
case 8:
$eights++;
break;
case 9:
$nines++;
break;
}
}
echo "";
echo "" . $i . " ";
echo "" . $d . " ";
echo "" . $even . " ";
echo "" . $odd . " ";
echo "" . $primes . " ";
echo "" . $sum . " ";
echo "" . $zeros . " ";
echo "" . $ones . " ";
echo "" . $twos . " ";
echo "" . $threes . " ";
echo "" . $fours . " ";
echo "" . $fives . " ";
echo "" . $sixes . " ";
echo "" . $sevens . " ";
echo "" . $eights . " ";
echo "" . $nines . " ";
echo " ";
$odd = 0;
$even = 0;
$sum = 0;
$zeros = 0;
$ones = 0;
$twos = 0;
$threes = 0;
$fours = 0;
$fives = 0;
$sixes = 0;
$sevens = 0;
$eights = 0;
$nines = 0;
$primes = 0;
$i++;
}
echo "
";
echo " ";
fclose($f);
?>
=====References & Resources=====
*[[/documentation/linkgarden|The Lab46 Link Garden]]
=====*NIX=====
====alias====
To get a list of all current alias's on the system:
#! /bin/bash
usr=`who | grep $USER`
echo $usr
This short script creates a variable (in this case, named ''who'') and assigns it the value of ''who | grep $USER''. Notice the ''$USER''? That's an environment variable that returns your user name. Also note, those aren't single quotes, they're back quotes (A.K.A. ''back ticks''). The next line echos the variable out to standard output. Save your file when you're finished.
while read LINE ; do
echo "$LINE"
done < fall2010-20100315.html
The above lines simply tell bash to read in another line from the file, as long as there are more lines to read. Once the file runs out of lines, the script is done.
In this case, the actual iterator is LINE, so we can output that by itself to get the actual line of text, however we can't count using this line as an iterator, and wouldn't it be handy to output some line numbers while coding the solution. To do this, add another variable inside the body of the while loop. This variable is incremented each time the loop executes.
while read LINE ; do
N=$(($N+1))
echo "$N : $LINE"
done < fall2010-20100315.html
Now the code outputs line numbers, which might or might not come in handy.
===numtest===
*Obtain 4 numbers from the user; in a variable called sum, store the sum of these 4 numbers. In a variable called product, store the product. Consider utilizing “bc” to assist you.
This script uses a ''for loop'' to gather some numbers from the user. However, you'll notice that I didn't use ''bc'', in fact I didn't do any multiplication at all. I'll be revisiting ''bc'' this in the coming days.
##
## automagically ls files after CD
##
cdl() {
cd "$@";
ls -Alh --color=auto;
}
alias cdl=cdl
##
## auto update in 3 chars ... remove the -y if you please
##
alias upd='sudo apt-get -y update && sudo apt-get -y upgrade'
##
## move around the file system a bit more swiftly
##
alias ..='cd ..'
alias .2='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
##
## get me home
##
alias home='cd ~/'
##
## edit those pesky priviliged files a bit faster
##
alias svi='sudo vi'
##
## give me more information ... but only when I want it
##
alias lls='ls -lAh --author --color=auto'
##
## show me what's open in a pinch
##
alias ports='netstat -tulanp'
##
## edit the hosts file
##
alias hosts='sudo vi /etc/hosts'
====IRC====
*[[rene|Rene the Lady Bot]]
====jobs====
List all running jobs: