This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_string(string) | |
split_string = string.split("") | |
split_string.reduce([]) { |a, b| a.unshift(b) }.join | |
#reversed = [] | |
#string.size.times { reversed << split_string.pop} | |
#reversed.join | |
end | |
puts reverse_string("codelabs") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_num_char_str(string) | |
split_string = string.split("") | |
count_hash = Hash.new(0) | |
split_string.each do |c| | |
count_hash[c] += 1 unless c == " " | |
end | |
count_hash.max_by { | c, n | n }.join | |
end | |
puts max_num_char_str("lots of sss to show") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(array) | |
return array.inject(:+) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array.each_with_object({odd:[], even:[]}) do |elem, memo| | |
memo[elem.odd? ? :odd : :even] << elem | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vigenere.c by Mark J. Rigdon | |
// CS50 | |
// 2018-12-16 | |
// Program encrypts messages using Vigenere's cipher. | |
// Includes | |
#include <cs50.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
#include <stdlib.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// caesar.c by Mark J. Rigdon | |
// CS50 | |
// 2018-12-16 | |
// Program encrypts messages using Caesar's cipher. | |
// Includes | |
#include <cs50.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
#include <stdlib.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mark J Rigdon | |
// 2018-12-11 | |
// Problem set 1 | |
// Creates a half right-aligned pyramid for Mario | |
#include <cs50.h> | |
#include <stdio.h> | |
int main(void) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mark J Rigdon | |
// 2018-12-11 | |
// Problem set 1 | |
// Creates a half right-aligned pyramid and a left-aligned pyramid for Mario | |
#include <cs50.h> | |
#include <stdio.h> | |
int main(void) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mark J Rigdon | |
// 2018-12-11 | |
// Problem set 1 | |
// Program calculates the minimum number of coins required to give a user change. | |
// Greedy algorithm example... | |
#include <cs50.h> | |
#include <math.h> | |
#include <stdio.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_string(string) | |
split_string = string.split("") | |
reversed = [] | |
string.size.times { reversed << split_string.pop } | |
reversed.join | |
end | |
puts reverse_string("codelabslone") |
OlderNewer