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
    
  
  
    
  | 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 | 
  
    
      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
    
  
  
    
  | require 'soundcloud' | |
| class StoriesController < ApplicationController | |
| def index | |
| @stories = Story.all | |
| end | |
| def new | |
| get_user | 
  
    
      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
    
  
  
    
  | # 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) | 
  
    
      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
    
  
  
    
  | # 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 | 
  
    
      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
    
  
  
    
  | # 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 | 
  
    
      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
    
  
  
    
  | 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] | 
  
    
      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
    
  
  
    
  | class BaseController | |
| def initialize(name) | |
| @name = name | |
| end | |
| def render | |
| puts "Hello my name is #{@name}" | |
| end | |
| end |