Skip to content

Instantly share code, notes, and snippets.

View CraigRodrigues's full-sized avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@CraigRodrigues
CraigRodrigues / water1.c
Created June 2, 2016 17:38
My solution to CS50 pset1 - "Smart Water" (modified)
#include <stdio.h>
#include <cs50.h>
// function that returns the number of 16oz bottles used
int getBottles(int time, int showerflow)
{
return (time * showerflow)/16;
}
int main(void)
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
@CraigRodrigues
CraigRodrigues / fifteen.c
Created June 10, 2016 21:01
CS50 pset3 - "Game of Fifteen"
/**
* fifteen.c
*
* Computer Science 50
* Problem Set 3
*
* Implements Game of Fifteen (generalized to d x d).
*
* Usage: fifteen d
*
@CraigRodrigues
CraigRodrigues / practiceSpec.js
Last active October 15, 2019 08:28
Function Practice Assertions
// Setup
mocha.setup('bdd');
chai.should();
chai.config.includeStack = false;
const assert = chai.assert;
describe('addTwoNumbers', () => {
it('Adds two positive numbers', function() {
assert.equal(addTwoNumbers(10, 2), 12);
@CraigRodrigues
CraigRodrigues / bubbleSort.js
Last active October 17, 2019 11:28
Bubble Sort in Javascript
// Normal
const bubbleSort = function(array) {
let swaps;
do {
swaps = false;
for (let i = 0; i < array.length - 1; i++) {
if (array[i] > array[i + 1]) {
let temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
@CraigRodrigues
CraigRodrigues / vigenere.c
Created June 1, 2016 02:45
My solution to CS50 pset2 - "Parlez-vous français?"
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
/**
* Vigenere.c
*
* A program that encrypts messages using Vigenère’s cipher. This program
* must accept a single command-line argument: a keyword, k, composed entirely
@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 / initials.c
Created May 31, 2016 19:38
My solution to CS50 pset2 - "Initializing"
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
/**
*
* Write, in a file called initials.c, a program that prompts a user for
* their name (using GetString to obtain their name as a string) and then
* outputs their initials in uppercase with no spaces or periods,
@CraigRodrigues
CraigRodrigues / convert.js
Created November 18, 2016 22:15
Converting cm to inches to nearest 1/16th inch
// The company I work for creates custom acrylic cases based on customer's inputted dimensions.
// For fabrication our dimensions go down to the nearest 1/16th inch.
// International customers may use cm (or mm) and this is a program that will attempt to convert cm to inches
// down to the nearest 16th of an inch and display the result as a reduced fraction.
// 1 cm is equivalent to 0.39370 inches.
// EXAMPLE: 16.4 cm = 6 7/16 inches
// EXAMPLE: 10.5 cm = 4 2/16 or 4 1/8 inches