Skip to content

Instantly share code, notes, and snippets.

View CraigRodrigues's full-sized avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@CraigRodrigues
CraigRodrigues / reverse.c
Last active July 9, 2016 14:22
Reverse String - Write a function that takes a string as input and returns the string reversed.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char* reverseString(char* s) {
int length = 0, i = 0;
length = strlen(s);
char temp[1];
@CraigRodrigues
CraigRodrigues / greedy.c
Created August 3, 2016 02:40
CS50 Pset1 - Greedy
#include <stdio.h>
#include <cs50.h>
#include <math.h>
/** Write a program that first asks the user how much change is owed
and then spits out the minimum number of coins with which said change
can be made.*/
int main(void)
{
@CraigRodrigues
CraigRodrigues / triplets.c
Last active August 3, 2016 14:43
HackerRank - Algorithms - Warmup - Compare the Triplets
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int alice_score = 0;
@CraigRodrigues
CraigRodrigues / timeconversion.c
Created August 4, 2016 12:17
HackerRank - Algorithms - Warmup - Time Conversion
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(void)
{
@CraigRodrigues
CraigRodrigues / circular_array.c
Created August 4, 2016 12:48
HackerRank - Algorithms - Warmup - Circular Array Rotation
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
// https://www.hackerrank.com/challenges/circular-array-rotation
int main(void)
{
int n, k, q;
@CraigRodrigues
CraigRodrigues / palindrome.c
Created August 12, 2016 01:01
Project Euler 4 - Largest Palindrome Product
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
bool isPalindrome(int num);
int main(void)
{
@CraigRodrigues
CraigRodrigues / dictionary.c
Created September 8, 2016 00:10
CS50 Problem Set 5 - Mispellings
/**
* dictionary.c
*
* Computer Science 50
* Problem Set 5
*
* Implements a dictionary's functionality.
*/
#include <stdbool.h>
@CraigRodrigues
CraigRodrigues / server.c
Created September 21, 2016 22:04
CS50 Problem Set 6: Web Server
//
// server.c
//
// Computer Science 50
// Problem Set 6
//
// feature test macro requirements
#define _GNU_SOURCE
#define _XOPEN_SOURCE 700
@CraigRodrigues
CraigRodrigues / phone.js
Created October 6, 2016 12:19
YDKJS - Up & Going - Challenge #1
var bankAccount = prompt("How much money is in your bank account?");
var spendingLimit = prompt("What is the max amount mof money do you wish to spend?")
var phonePrice = 100, accessoryPrice = 20, taxRate = 0.06, cost = 0;
function finalCheckout(amt) {
amt = amt + (amt * taxRate);
if (amt < bankAccount)
console.log("You can afford this!");
else
@CraigRodrigues
CraigRodrigues / reduce.js
Created November 20, 2016 20:06
Simple reduce function
// array to reduce
// combine is a function that will do something to the current value and the current element
// current is either the start provided or 0 if nothing is provided?
function reduce(array, combine, start) {
var current = start || 0;
for (var i = 0; i < array.length; i++)
current = combine(current, array[i]);
return current;
}