This file contains 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 fib_rec (number) | |
if number == 0 | |
return number | |
elsif (number == 1) || (number == 2) | |
return 1 | |
end | |
fib_rec(number - 1) + fib_rec(number - 2) | |
end | |
def fib_non_rec (number) |
This file contains 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
=begin | |
O(n + k) | |
=end | |
def countSort arr | |
countArr = [] | |
resultArr = Array.new(arr.length) | |
max = arr.max |
This file contains 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
package main | |
// worst n^2 | |
// best n | |
import ( | |
"fmt" | |
) | |
func main() { | |
arr := []int{2,5,4,-8,9,1} |
This file contains 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
/* | |
best time O(n log2 n) | |
worst time O(n log2 n) | |
*/ | |
package main | |
import ( | |
"fmt" | |
) |
This file contains 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
package main | |
import "fmt" | |
var mes = "test cypeher with digit 6" | |
func main() { | |
bs := ([]byte)(mes) | |
cyp := make([]byte, len(bs)) | |
j := 0 |
This file contains 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
a := 32 | |
b := -44 |
This file contains 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
digit = 543210 | |
# Reverse digit | |
def reverse_digit(digit) | |
str = digit.to_s.reverse.split('') | |
if str.first == '0' | |
str.shift | |
end | |
str.join('').to_i | |
end |
This file contains 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
years = 5 | |
a = 1000 | |
def bank(a, years) | |
i = 0 | |
while i != years | |
b = (a * 0.1) + a | |
a = b | |
i += 1 | |
end |
This file contains 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 is_simple(digit): | |
for i in range(2, digit - 1): | |
if ((digit % i) == 0): | |
return False | |
else: | |
return True | |
print(is_simple(72)) # False | |
print(is_simple(73)) # True |
This file contains 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
# O(n log(log n)) | |
arr = list(range(0, 300)) | |
def sieve(ar): | |
for i in ar: | |
if i > 1: | |
step = arr[i] | |
while (arr[i] + step) < len(arr): |