Skip to content

Instantly share code, notes, and snippets.

View venelrene's full-sized avatar
✝️
Working

Venel venelrene

✝️
Working
  • remote
View GitHub Profile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
@venelrene
venelrene / Opposite_number.rb
Created February 5, 2019 21:01
Very simple, given a number, find its opposite.
def opposite(n)
n * -1
end
@venelrene
venelrene / Stop_gninnipS_My_sdroW!.rb
Created February 5, 2019 21:30
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
def spinWords(string)
string.split.map! {|s| s.length >= 5 ? s.reverse : s}.join(" ")
end
@venelrene
venelrene / Who likes it.rb
Created February 12, 2019 20:04
You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item. Implement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the d…
def likes(names)
case names.size
when 0 then "no one likes this"
when 1 then "#{names[0]} likes this"
when 2 then "#{names[0]} and #{names[1]} like this"
when 3 then "#{names[0]}, #{names[1]} and #{names[2]} like this"
else "#{names[0]}, #{names[1]} and #{names.length - 2} others like this"
end
end
@venelrene
venelrene / Array_diff.rb
Created February 13, 2019 18:35
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result. It should remove all values from list a, which are present in list b.
def array_diff(a, b)
a.delete_if {|a| b.include?(a)}
end
@venelrene
venelrene / Bit_Counting.rb
Created February 13, 2019 19:50
Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative. Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case
def count_bits(n)
n.to_s(2).scan("1").count
end
@venelrene
venelrene / Even_or_Odd.py
Created February 14, 2019 01:59
Create a function (or write a script in Shell) that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.
def even_or_odd(number):
return "Odd" if number % 2 != 0 else "Even"
@venelrene
venelrene / Number_to_a_String.py
Created February 15, 2019 14:05
Convert a Number to a String!
def number_to_string(num):
return str(num)
@venelrene
venelrene / Persistent_Bugger.py
Created February 15, 2019 15:23
Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.
######### Refactored #########
def persistence(n):
if n < 10: return 0
multiplier = 1
while(n > 0):
multiplier = (n % 10) * multiplier
n = n // 10
@venelrene
venelrene / Remove First and Last Character.py
Created February 15, 2019 16:24
Remove First and Last Character
def remove_char(s):
return s[1:-1]