Skip to content

Instantly share code, notes, and snippets.

@eugene0707
eugene0707 / anagram_benchmarks.rb
Created April 7, 2017 18:04
Anagram check benchmarks
require 'benchmark'
string1 = 'старорежимность'
string2 = 'нерасторжимость'
N = 100000
Benchmark.bm(30) do | x |
x.report('Sorted array equality') do
N.times { string1.chars.sort == string2.chars.sort }
var total_elements=11; // Всего элементов в массиве
var initial_array=Array.apply(null, {length: total_elements}).map(Function.call, Math.random).map(Math.round); // Изначальный массив для контроля. Массив в сортировке не участвует
var sorted_array=initial_array.slice(); // Массив, который сортируем
// Вспомогательные переменные
var count_0=0, count_1=0;
var half=Math.trunc(total_elements/2);
var is_odd=(total_elements % 2==1) ? true : false;
for (var i=0;i<total_elements;i++) {
@eugene0707
eugene0707 / codility_equilibrium.rb
Created February 7, 2017 18:37
Codility equilibrium index ruby 100 X 100
def solution(a)
l=0
r=a.reduce(0, :+)
a.each_with_index do |e, i|
r-= e
return i if l==r
l+=e
end
-1
end