Skip to content

Instantly share code, notes, and snippets.

View carolvisoto's full-sized avatar

Caroline Visoto Nunes carolvisoto

View GitHub Profile
@carolvisoto
carolvisoto / CyclicRotation.txt
Last active December 21, 2016 17:52
CyclicRotation explanation
CyclicRotation (https://codility.com/programmers/lessons/2-arrays/cyclic_rotation/)
// // k = 1 (nunmer os rotations)
// tmp = array[array.length - 1]
// // 1 2 3 4 5
// array[j] = array[j - 1]
// j--
// // 1 2 3 4 4
// array[j] = array[j - 1]
// j--;
// // 1 2 3 3 4
require 'soundcloud'
class StoriesController < ApplicationController
def index
@stories = Story.all
end
def new
get_user
@carolvisoto
carolvisoto / blocks.rb
Last active August 29, 2015 14:15 — forked from jkischkel/blocks.rb
# a simple block:
p [1,2,3].map { |i| i.to_s }
# a block with do/end
p [1,2,3].map do |i|
i.to_s
end
# even fancier, with a function reference
p [1,2,3].map(&:to_s)
# Iterator methods without blocks are called Enumerators
[1,2,3].each_index # => #<Enumerator: [1, 2, 3]:each_index>
0.upto(10) # => #<Enumerator: 0:upto(10)>
# You can call any Enumerable method on Enumerators
[1,2,3].each_index.map {|i| i + 10 } # => [10, 11, 12]
0.upto(10).map {|i| i + 10 } # => [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
# See documentation about Enumerables
# Returns all permutations of string s
def permutations(s)
# For single characters just return one solution, the character
if s.size <= 1
[s]
else
# calculate all permutations without the first character
# and then iterate over each
permutations(s[1..-1]).flat_map do |x|
# for each position in permutation x
module SelectionSort
def self.selection_sort_algorithm(array)
if array.class != Array
throw "tried to sort nonarray"
else
array_size = array.size-1
array_size.times do |i|
min = i
(i + 1).upto(array_size) do |j|
if array[j] < array[min]
class BaseController
def initialize(name)
@name = name
end
def render
puts "Hello my name is #{@name}"
end
end