Skip to content

Instantly share code, notes, and snippets.

View spirinvladimir's full-sized avatar
💭
💯

Spirin Vladimir spirinvladimir

💭
💯
View GitHub Profile
@spirinvladimir
spirinvladimir / index.js
Created October 3, 2018 10:24
Skiing in Singapore - a coding diversion by Redmart
var fs = require('fs');
var AVLTree = require('avl');
var tree = new AVLTree();
var map = fs.readFileSync('map.txt', 'utf-8').split('\n').map(l => l.split(' ').map(c => Number(c)));
var [I, J] = map.shift();
var result = {
path: 0,
drop: 0
};
@spirinvladimir
spirinvladimir / follow-the-white-rabbit.js
Last active September 17, 2018 05:32
Solution for "Follow The White Rabbit" by TrustPilot
var
fetch = require('node-fetch'),
md5 = require('md5'),
md5s = ["e4820b45d2277f3844eac66c903e84be", "23170acc097c24edb98fc5488ab033fe", "665e5bcb0c20062fe8abaaf4628bb154"],
match_md5 = frase => md5s.indexOf(md5(frase)) !== -1,
word2map = word => word.split('').reduce((acc, c) => {acc[c] = acc[c] || 0; acc[c]++; return acc}, {}),
match = rm => word => {
var char, i = 0, wm = {};
while (i < word.length) {
char = word[i];
(let [n_ (Integer/parseInt (read-line))
i (fn [] (map #(Integer/parseInt %) (clojure.string/split (read-line) #" ")))
[x0 y0] (i)]
(loop [n n_
min_x x0
min_y y0]
(if (= n 1)
(println (* min_x min_y))
(let [[x y] (i)]
(recur
@spirinvladimir
spirinvladimir / calculate-business-hours.clj
Last active March 16, 2018 07:31
Date and time calculations
(require '[clj-time.core :as t])
(require '[clj-time.predicates :as pr])
(require '[clj-time.coerce :as c])
(defn add_hours_for_day_in_week [week weekday hours]
"Update day in a week by adding new business hours."
(assoc
week
(dec weekday)
VladimisMacBook:flat_json a$ mix hex.publish
Publishing flat_json 0.1.0
App: flat_json
Name: flat_json
Files:
lib/flat_json.ex
mix.exs
README.md
Description: Decode string with flat JSON to Map
Version: 0.1.0
test.cb('PUT /api/stocks/1 (update the price of a single stock)', t => {
const
app = webserver(createList(), port());
request(app)
.post('/api/stocks')
.send({name: 'EUR', currentPrice: 1})
.expect(200)
.then(res => res.body.id)
.then(id => request(app)
(def s (Integer/parseInt (read-line)))
(def stdin (read-line))
(def nums (vec (map #(Integer/parseInt %) (clojure.string/split stdin #" "))))
(defn insertOne [position collection size]
(let [v (nth collection position)]
(loop [a collection
p (dec position)]
(if (= p -1)
var
toAdd = true,
notToAdd = false,
events = [
{start: 1, end: 5},
{start: 2, end: 3},
{start: 4, end: 6},
{start: 7, end: 8},
{start: 9, end: 10},
{start: 10, end: 11},
(defn doubleBooked [events]
(let [sortedEvents (sort-by :start events)
toAdd true
notToAdd false]
(loop [head (first sortedEvents)
isAdd notToAdd
events (rest sortedEvents)
intersect []]
(let [neck (first events)
tail (rest events)]
@spirinvladimir
spirinvladimir / array2string.clj
Created November 2, 2016 23:30
Array to string with separator for hackerrank
(defn a2s [a]
(reduce
(fn [s n]
(str s (str " " n)))
(str (first a))
(rest a)))