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
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 } |
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
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++) { |
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 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 |