Skip to content

Instantly share code, notes, and snippets.

View venelrene's full-sized avatar
✝️
Working

Venel venelrene

✝️
Working
  • remote
View GitHub Profile
@venelrene
venelrene / Create Phone Number.py
Last active June 29, 2025 09:24
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
def create_phone_number(n):
f = "".join(map(str, n[0:3]) )
s = "".join(map(str, n[3:6]) )
t = "".join(map(str, n[6:10]) )
return "("+f+") "+ s +"-"+t
######## Refactored #####
def create_phone_number(n):
@venelrene
venelrene / countingSheep.py
Created February 21, 2019 16:17
Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).
def count_sheeps(arrayOfSheeps):
return arrayOfSheeps.count(True)
@venelrene
venelrene / Dubstep.rb
Last active February 21, 2019 18:18
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this song, Polycarpus inserts a cer…
require 'active_support/all'
def song_decoder(song)
song.gsub(/WUB/, " ").squish!
end
@venelrene
venelrene / Dubstep.py
Created February 21, 2019 18:19
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this song, Polycarpus inserts a cer…
def song_decoder(song):
return " ".join(song.replace("WUB", " ").split())
def no_space(x):
return x.replace(' ' ,'')
@venelrene
venelrene / Take_a_ten_minute_walk.rb
Created February 21, 2019 19:52
You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter string…
def isValidWalk(walk)
walk.count == 10 && walk.count('n') == walk.count('s') && walk.count('e') == walk.count('w')
end
@venelrene
venelrene / ReversedStrings.py
Created February 21, 2019 19:59
Complete the solution so that it reverses the string value passed into it.
def solution(string):
return string[::-1]
@venelrene
venelrene / Count_the_Monkeys.ex
Created September 23, 2019 13:41
You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1. As a good parent, you will sit and count with him. Given the number (n), populate an array with all numbers up to and including that number, bu…
defmodule Codewars.Zoo do
def monkey_count(n) do
Enum.to_list(1..n)
end
end
@venelrene
venelrene / Consecutive strings.py
Created September 23, 2019 14:02
You are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.
def longest_consec(strarr, k):
n = len(strarr)
if n == 0 or k > n or k <= 0:
return ''
return sorted([''.join(strarr[i:i+k]) for i in range(0, n-k+1)], key=len, reverse=True)[0]
@venelrene
venelrene / consecutive_strings.ex
Created September 23, 2019 15:47
You are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.
defmodule Longestconsec do
def longest_consec(strarr, k)
when length(strarr) == 0
when k > length(strarr)
when k <= 0,
do: ""
def longest_consec(strarr, k) do
Enum.chunk_every(strarr, k, 1)