Skip to content

Instantly share code, notes, and snippets.

@h3llborn
h3llborn / lastarg.sh
Last active August 29, 2015 14:07
assignment #2-q1
#!/bin/sh
# Author: Chris Niesel
# Class: Computer Science 2211A
# output the last argument passed to the script
# check if there are more than 0 argument
while [ $# -gt 0 ];do
# if current argument is the last one output it
if [ "$#" -eq 1 ]; then
@h3llborn
h3llborn / odd_prn.sh
Last active August 29, 2015 14:07
assignment #2-q2
#!/bin/sh
# Author: Chris Niesel
# Class: Computer Science 2211A
echo "Number of arguments passed: $#"
X=0 # var used for while loop that increments every run
while [ $# -gt 0 ];do # check if we have more arguments
# check if $X number is even if so, print it
if [ `expr $X % 2` -eq 0 ]; then
@h3llborn
h3llborn / q4 output
Last active August 29, 2015 14:07
question 4 output
obelix[279]% sh nums.sh ; echo $?
Usage: nums option input-file
1
obelix[280]% sh nums.sh 0; echo $?
Usage: nums option input-file
1
obelix[281]% sh nums.sh 5; echo $?
Usage: nums option input-file
1
obelix[282]% sh nums.sh 0 numbersfile; echo $?
@h3llborn
h3llborn / nums.sh
Last active August 29, 2015 14:07
assignment #2-q4
#!/bin/sh
# Author: Chris Niesel
# Class: Computer Science 2211A
# check if there are 2 arguments
if [ "$#" -eq "2" ]
then
# check if file doesn't exist
if [ ! -f "$2" ]; then
echo "input-file not found"
exit 2
@h3llborn
h3llborn / question3.sh
Last active August 29, 2015 14:07
assignment #2-q3
#!/bin/sh
# Author: Chris Niesel
# Class: Computer Science 2211A
# get number from user
echo "Enter a number: "
read i
x=0 # loop iterator value
@h3llborn
h3llborn / greedy_change
Created November 13, 2014 00:33
create change for an amount
#Author: Chris niesel
#include <stdio.h>
int main(void) {
int currency[] = {20,10,5,2,1};
int amount = 59;
int num;
int i =0;
for(i;i<5;i++){
if(currency[i]<=amount)
@h3llborn
h3llborn / greedy.c
Last active August 29, 2015 14:09
greedy change algorithm for assignment 4
// Author: Chris Niesel
// Class: 2211A
#include <stdio.h>
/*
Method: pay_amount
input: int dollars, int *twenties, int *tens, int *fives, int *toonies, int *loonie
purpose: determine the best way to change an amount into bills / coins
returns: nothing.
*/
// author: chris niesel
// class: 2211
#include <stdio.h>
#define SIZE 99 // maximum size of magic square
void genSquare(int size, int square[SIZE][SIZE]){
// set starting coordinates
int row = 0;
// author chris niesel
// class compsci 2211
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void initrandom(){
srand((float) time(NULL));
}
float genRandom(){
// author chris niesel
// class compsci 2211
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
/*
Method: initrandom
input: nothin