Skip to content

Instantly share code, notes, and snippets.

Avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@CraigRodrigues
CraigRodrigues / caesar2.c
Last active Jun 2, 2016
My solution to CS50 pset2 - "Hail, Caesar!" (using function)
View caesar2.c
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
/**
* Caesar.c
* A program that encrypts messages using Caesar’s cipher. Your program must
* accept a single command-line argument: a non-negative integer. Let’s call it
* k for the sake of discussion. If your program is executed without any
@CraigRodrigues
CraigRodrigues / credit2.c
Created Jun 3, 2016
My solution to CS50 Hacker pset1 - "Bad Credit " (printf tests included)
View credit2.c
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
// calculates the number of digits in the card number
int getCardDigits(long long card_num)
{
int card_digits = (int)log10(card_num) + 1;
@CraigRodrigues
CraigRodrigues / helpers.c
Created Jun 8, 2016
CS50 pset3 - "Game of Fifteen" - Linear Search Algorithm
View helpers.c
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
@CraigRodrigues
CraigRodrigues / helpers2.c
Last active Jun 10, 2016
CS50 pset3 - "Game of Fifteen" - Helpers - Insertion Sort & Binary Search (Recursion)
View helpers2.c
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
@CraigRodrigues
CraigRodrigues / sum.c
Created Jun 13, 2016
Recursive Sum Function
View sum.c
//n is the last index of the array
int arr_sum(int arr[], int n )
{
//base case
if (n == 0)
{
return arr[0];
}
return (arr[n] + arr_sum(arr,n-1));
@CraigRodrigues
CraigRodrigues / max.c
Last active Jun 13, 2016
Finding Max Value with Recursion
View max.c
#include "stdio.h"
// find the max number in a list/array
// n is the last index of the array
int arr_max(int arr[], int max, int n)
{
//base case
if (n == 0)
{
@CraigRodrigues
CraigRodrigues / counting.c
Last active Jun 13, 2016
Recursive Counting Function
View counting.c
#include "stdio.h"
//n is the last index of the array
int arr_count(int count, int n)
{
//base case
if (n == 0)
{
return count;
@CraigRodrigues
CraigRodrigues / critical.c
Last active Jun 19, 2016
[2016-06-13] Challenge #271 [Easy] Critical Hit
View critical.c
#include <stdio.h>
#include <cs50.h>
#include <math.h>
/* [2016-06-13] Challenge #271 [Easy] Critical Hit
* http://bit.ly/1sLH0bn
*
* Critical hits work a bit differently in this RPG. If you roll the maximum value on a die, you
* get to roll the die again and add both dice rolls to get your final score. Critical hits can
* stack indefinitely -- a second max value means you get a third roll, and so on. With enough
@CraigRodrigues
CraigRodrigues / RPS.js
Last active Jun 22, 2016
Codecademy Javascript Unit 2 - Rock, Paper, Scissors
View RPS.js
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
@CraigRodrigues
CraigRodrigues / bag.c
Last active Jul 7, 2016
[2016-06-20] Challenge #272 [Easy] What's in the bag?
View bag.c
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
int tilecount[] = { 9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6,
4, 6, 4, 2, 2, 1, 2, 1, 0, 0, 0, 0, 2 };
You can’t perform that action at this time.