Skip to content

Instantly share code, notes, and snippets.

@vitalii-komenda
vitalii-komenda / init.lua
Created October 13, 2024 15:03
neovim init.lua
--[[
=====================================================================
==================== READ THIS BEFORE CONTINUING ====================
=====================================================================
======== .-----. ========
======== .----------------------. | === | ========
======== |.-""""""""""""""""""-.| |-----| ========
======== || || | === | ========
======== || KICKSTART.NVIM || |-----| ========
const main = () => {
findExchangeRate([['USD', 'JPY', 110],['USD', 'AUD', 1.45],['JPY', 'GBP', 0.0070]], ['GBP', 'AUD'], 1)
}
const findExchangeRate = (rates, toFrom, value) => {
const to = toFrom[1];
const from = toFrom[0];
// build rate graph record
const ratesGraph = {}
rates.map(rate => {
@vitalii-komenda
vitalii-komenda / convert-via-usd.js
Last active May 18, 2023 19:05
convert currency into another via USD currency
convert_currency = (rates, from, to) => {
const conversions = {};
// 1.45 / (0.0070 * 110)
for(let i=0; i<rates.length; i++) {
if (!conversions[rates[i][0]]) {
conversions[rates[i][0]] = {};
}
conversions[rates[i][0]][rates[i][1]] = rates[i][2];
function DisjoinedSets() {
this.parent = [];
this.rank = [];
this.find = (val) => {
if (this.parent[val] === val) {
return val;
} else {
return this.find(this.parent[val]);
}
const getMinimumMoves = (k, d, a) =>
{
let MAX = 100000;
let n = a.length
// Stores the number of moves
// required to obtain respective
// values from the given array
let v = Array(MAX).fill(0)
for(let i = 0; i < v.length; i++)
isDevisible = (s, t) => {
let l = 0;
let r = 0;
let repStart = 0;
while(l < s.length) {
if (s[l] === t[r]) {
l++;
r++;
} else if (t[r] === undefined) {
//C = 8;
//F = [1,3,2,1];
//V = [0,1,2,3];
//https://open.kattis.com/problems/magicalcows
const nf = (maxCowsOnFarm, farms, visits) => {
const dp = [];
const freq = {};
items=[{v: 5, w: 10}, {v: 1, w: 1}, {v: 3, w: 4}]
knp = (items, maxWeight)=>{
const dp = [];
for(let i=0; i<=items.length; i++) {
for(let w=0; w<=maxWeight; w++) {
if(!dp[i]) dp[i] = [];
dp[i][w] = 0;
}
items=[{v: 5, w: 10}, {v: 1, w: 1}, {v: 3, w: 4}]
knp = (items, selected, maxWeight, val)=>{
if (maxWeight === 0) return [val, selected];
if (maxWeight < 0) return [0, selected];
if (!items.length) return [val, selected];
let last = items[items.length-1];
let including = knp(items.slice(0, -1), selected.concat(last), maxWeight - last.w, val+last.v);
let notIncluding = knp(items.slice(0, -1), selected, maxWeight, val);
arr = [5, 2, 8, 6, 3, 6, 5, 5];
longestContinuesSubseq = (a) => {
let t = Array(a.length).fill(1);
for(let i=1; i<t.length; i++) {
let smalerUntilI = [];
for(let j=0; j<i; j++) {
if (a[j] < a[i]) {
smalerUntilI.push(t[j]);