Skip to content

Instantly share code, notes, and snippets.

View CraigRodrigues's full-sized avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@CraigRodrigues
CraigRodrigues / caesar2.c
Last active June 2, 2016 20:03
My solution to CS50 pset2 - "Hail, Caesar!" (using function)
#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 June 3, 2016 16:30
My solution to CS50 Hacker pset1 - "Bad Credit " (printf tests included)
#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 June 8, 2016 19:09
CS50 pset3 - "Game of Fifteen" - Linear Search Algorithm
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
@CraigRodrigues
CraigRodrigues / helpers2.c
Last active June 10, 2016 20:48
CS50 pset3 - "Game of Fifteen" - Helpers - Insertion Sort & Binary Search (Recursion)
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
@CraigRodrigues
CraigRodrigues / sum.c
Created June 13, 2016 12:48
Recursive Sum Function
//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 / counting.c
Last active June 13, 2016 13:21
Recursive Counting Function
#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 June 19, 2016 01:15
[2016-06-13] Challenge #271 [Easy] Critical Hit
#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 June 22, 2016 20:55
Codecademy Javascript Unit 2 - Rock, Paper, Scissors
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 July 7, 2016 17:01
[2016-06-20] Challenge #272 [Easy] What's in the bag?
#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 };
@CraigRodrigues
CraigRodrigues / degree.c
Last active July 8, 2016 21:01
[2016-06-27] Challenge #273 [Easy] Getting a degree (with bonus)
/**
* degree.c
*
* Reddit Daily Programmer Challenge #273 [EASY]
* Getting a degree
*
* https://www.reddit.com/r/dailyprogrammer/comments/4q35ip/20160627_challenge_273_easy_getting_a_degree/
*
*/