Skip to content

Instantly share code, notes, and snippets.

View KoStard's full-sized avatar
👾

Ruben Kostandyan KoStard

👾
View GitHub Profile
#include <iostream>
#include <vector>
using namespace std;
int calc(int temp, vector<int> &input, vector<int> &L, vector<vector<int>> &mem){
if(L.size()==0){
L.push_back(1);
mem.push_back(*new vector<int>(1,0));
return 1;
}
@KoStard
KoStard / Longest pallindrom length
Created August 18, 2017 14:19
Dynamic programming
#include <iostream>
#include <vector>
using namespace std;
int main(){
int q;
cout << "Type the queries number: ";
cin >> q;
while(q--){
string str;
squares = []
mx = 0
class Square:
def __init__(self, height, val = 0):
if val == 0:
self.val = height
else:
self.val = val
self.height = height
def cont(self):
def get_rel(arr, i, i1 = -1):
if i!=0 or i1!=-1:
if i1==-1:
i1 = i-1
if arr[i]>arr[i1]:
return +1
elif arr[i]<=arr[i1]:
return -1
else:
return 0
import math
def task81(n):
d = {}
last_prime = 2
if n == 2:
d = {2 : 1}
else:
while n > 1:
if n%last_prime == 0 and d.get(last_prime) == None:
@KoStard
KoStard / Task84.js
Created April 11, 2018 09:53
Task84 of UniLecs Telegram
function get_factorial(num){
res = 1;
for (i = 1; i <= num; i++){
res *= i;
}
return res;
}
function task84 (word){
res = get_factorial(word.length);
@KoStard
KoStard / Task 85.js
Created April 13, 2018 18:10
Task 85 of UniLecs Telegram
function task85(k){
console.log((-1+Math.sqrt(1+8*k))/2)
z = Math.ceil((-1+Math.sqrt(1+8*k))/2);
if (k%2==0){
while (z%4!=3 && z%4!=0){
z++;
}
}else{
while (z%4!=1 && z%4!=2){
z++;
@KoStard
KoStard / Task 86.js
Created April 17, 2018 17:42
Task 86 of UniLecs Telegram
function calculations(a, b){
if (a >= b*3) { // When a is so big, that a/3 don't fit into b, so we get one row of squares with width b
return b;
/*
* ###.
*/
}else if (a < b*3 && a > b*3/2) { // This is when a/3 is smaller than b, so it fit's into the b, but is bigger than b/2, so we still get one row with width a/3
return a/3;
/*
* ###
@KoStard
KoStard / Task 87.js
Created April 20, 2018 14:24
Task 87 by UniLecs Telegram
function task87(N){
let mem = [];
let sum = 0;
for (j = 0; j < N; j++ ){
sum += 1;
if (j>1){
sum+=mem[j-2];
}
mem.push(sum);
}
@KoStard
KoStard / Task 90.py
Created May 1, 2018 14:55
Task 90 of UniLecs in Telegram
def task90(M, N, A, B, cords):
massive = [["*" if any((cord[0]==x and cord[1]==y)
or (x in range(cord[0]-A+1, cord[0]+1) and y in range(cord[1]-B+1, cord[1]+1))
or (x in range(M-A+1, M+1))
or (y in range(N-B+1, N+1))
for cord in cords) else "_" for x in range(M)] for y in range(N)]
# print(*massive, sep = "\n") # Uncomment this for visualization
res = 0
for row in massive:
for elem in row: