Skip to content

Instantly share code, notes, and snippets.

View CraigRodrigues's full-sized avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@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 / max.c
Last active December 26, 2023 06:34
Finding Max Value with Recursion
#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 / 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 / resize.c
Last active January 19, 2021 00:08
CS50 pset4 - "Resize"
/**
* resize.c
*
* Computer Science 50
* Problem Set 4
*
* Copies a BMP piece by piece, but also resizes it, just because.
*/
#include <stdio.h>
@CraigRodrigues
CraigRodrigues / recover.c
Created July 7, 2016 16:50
CS50 pset4 - "Recover"
/**
* recover.c
*
* Computer Science 50
* Problem Set 4
*
* Recovers JPEGs from a forensic image.
*/
#include <cs50.h>
@CraigRodrigues
CraigRodrigues / whodunit.c
Created July 7, 2016 16:51
CS50 pset4 - "Whodunit"
/**
* whodunit.c
*
* Computer Science 50
* Problem Set 4
*
* Copies a BMP piece by piece, with slight variation.
*/
#include <stdio.h>
@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/
*
*/