Skip to content

Instantly share code, notes, and snippets.

View matugm's full-sized avatar

Jesus Castello matugm

View GitHub Profile
class ListNode
attr_accessor :val, :next
def initialize(val)
@val = val
@next = nil
end
end
@carry = false
@matugm
matugm / max_subarray.rb
Created June 10, 2015 02:03
Max SubArray
#######################
# Version 1 - O(n^2)
#######################
def max_seq(chars, x = 0, y = 0)
return chars if chars.size < 2
combinations = {}
(0...chars.size).each do |x|
@matugm
matugm / dp-change.rb
Created June 8, 2015 18:02
Change problem solution
COINS = [1,3,6,10,15,20,30,50]
@cache = []
def min_change(amount)
return 0 if amount == 0
min = 9999999999
possible_coins = COINS.select { |n| n <= amount }
@matugm
matugm / caesar.rb
Last active September 16, 2023 05:23
Caesar cipher using Ruby
ALPHABET_SIZE = 26
def caesar_cipher(string)
shiftyArray = []
charLine = string.chars.map(&:ord)
shift = 1
ALPHABET_SIZE.times do |shift|
shiftyArray << charLine.map do |c|
((c + shift) < 123 ? (c + shift) : (c + shift) - 26).chr
@matugm
matugm / array.c
Last active May 11, 2021 04:30
dynamic arrays in c
#include "array.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
struct ArrayData *initArray() {
struct ArrayData *newArray = malloc(sizeof(struct ArrayData));
newArray->pointer = calloc(1000, sizeof(int));
newArray->size = 1000;
<pre>
<?php
// Creating an array
$chars = array();
array_push($chars,'a','b','c');