Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
Type Initializers
When you define a derived data type in GNU Fortran, you are automatically given a type initializer which allows you to initialize an instance of your derived data type in one go. One can think of a type initializer as a primitive type of constructor. However, custom-defined constructors weren't available until Fortran 2003 so it may not be available in GNU Fortran (which is an extension of the Fortran 95 standard).
module Solution
implicit none
type Vec3D ! A three-dimensional vector
integer :: x, y, z
end type Vec3D
type(Vec3D) :: v = Vec3D(1, 2, 3) ! Using the type initializer provided by Fortran
end module Solution
program TestCases
use CW2
use Solution
implicit none
print "(A20, I0, A2, I0, A2, I0, A1)", "Our 3D vector: v = (", v%x, ", ", v%y, ", ", v%z, ")"
call assertEquals(.true., .true.)
end program TestCases
Alternative Function Syntax
Just discovered this by looking at a few Fortran code examples online, but it seems that in as early as Fortran 95 (perhaps even earlier!), functions can be defined in at least two ways.
The traditional way:
function FUNCTION_NAME(PARAMETER) ! or parameters
PARAMETER_TYPE :: PARAMETER
RETURN_TYPE :: FUNCTION_NAME ! or explicit result variable
! Function body
end function FUNCTION_NAME
And the second (perhaps more C-like) way:
RETURN_TYPE function FUNCTION_NAME(PARAMETER)
PARAMETER_TYPE :: PARAMETER
! Function body
end function FUNCTION_NAME
Of course, with either syntax, it is possible to add modifiers such as pure
, recursive
or result(RESULT_VAR)
.
module Solution
implicit none
contains
integer pure function add(a, b) result(c)
integer, intent(in) :: a, b
c = a + b
end function add
end module Solution
program TestCases
use CW2
use Solution
implicit none
call describe("add")
call it("adds integers")
call assertEquals(2, add(1, 1))
call assertEquals(8, add(5, 3))
call assertEquals(69, add(33, 36))
call assertEquals(1079, add(826, 253))
call endContext()
call endContext()
end program TestCases
heres the instruction:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
Note: If the number is a multiple of both 3 and 5, only count it once.
I got the output of 23 by adding all multiple of 3 and 5 but it saying, I'm wrong.
I'm new here plss help
function test() {
var a = [];
for (i=1; i<10; i++){
if ((i%3==0) || (i%5==0)){
a.push(i);
}
}
return a;
}
function sum(number){
var sum= 0;
for(i=0; i<number.length; i++){
sum += number[i];
}
return sum;
}
var ab = test();
var abc = sum(ab);
console.log(abc);
function test() {
var a = [];
for (i=1; i<10; i++){
if ((i%3==0) || (i%5==0)){
a.push(i);
}
}
return a;
}
function sum(number){
var sum= 0;
for(i=0; i<number.length; i++){
sum += number[i];
}
return sum;
}
var ab = test();
var abc = sum(ab);
console.log(abc);
Objective: given 1 <= K <= 26, 0 <= N count the number of different strings of length N that contain exactly K different characters from the alphabet.
Ideas: for small values of N it should be bruteforce-able.
For large values of N?
Clarifications:
-> "The alphabet" is the 26 lowercase letters of the English alphabet
alphabet = 'abcdefghijklmnopqrstuvwxyz'
import itertools
def counter(N, K):
return counterNaive(N, K)
def counterNaive(N, K):
# print(f"counterNaive({K}, {N})")
allCombs = [x for x in itertools.product(alphabet, repeat=N)]
# print(f"All combinations of length {N}: 26^N = {26**N}")
return sum( len(set(x)) == K for x in allCombs )
def counterSmart(N, K):
# Idea:
# Find all ways of splitting N in K parts
# For each such way, once we know the lenght of the parts K1, ..., Kn
# (And they must be such that K1+...+Kn = N)
# Calculate the possible combinations: they are N!/(N-K)! options for the choice of K letters
# divided by the product of:
# L! where L = count(Kn == j) for j in range(N)
# to compensate the fact that if letters 'a' and 'b' appear in the same amount,
# then doing (a, b) = (b, a) does not give a different sequenec
# times the permutations of N elements with K1, ..., Kn repetitions
# Then add these up
pass
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
# test.assert_equals(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
Test.describe('Small values of N')
test.assert_equals(counter(1, 1), 26, "There are 26 one-length strings.")
test.assert_equals(counter(3, 1), 26, "If you can only choose one letter, there are always 26 possibilities.")
test.assert_equals(counter(3, 3), 26*25*24, "If K = N, the answer is easy to calculate")
test.assert_equals(counter(3, 2), 26*25*3, "This is the first test with non-trivial N and K")
test.assert_equals(counter(5, 3), 26*25*24*25)
Test.describe('Medium values of N')
#This makes the naive code time out.
#test.assert_equals(counter(20, 8), -1, "Obviously unfinished test")
Map/Dictionary/Associative Array as a linked list of entries
Related article: Associative Array - Wikipedia
Many modern and/or popular programming languages such as Python, Java and C++ (and even some not-so-modern and/or popular languages such as Objective-C) provide a built-in datatype (either natively or in a built-in library) which maintains association between keys and values, commonly known as a map/dictionary and sometimes less known as an associative array (in languages such as PHP). However, for simpler and/or older languages such as C, such convenient data types do not exist. So, is it possible to define your own map/dictionary/assoc-array datatype in such languages? Of course - it all just boils down to data structures and algorithms (and perhaps some simple wrappers to hide your implementation from the user). Perhaps the easiest way to implement your own map data type is by using a linked list of key-value entries which will be demonstrated in this Kumite but the downside is that pretty much every operation you perform on your map (be it insertion, query or deletion) will have O(n)
time complexity, i.e. the time taken to execute the operation varies directly with the number of entries in the map. The related Wikipedia article (link posted above) says that insertion should be an O(1)
operation (since you could insert the key-value pair at the head of the list) but only if it is assumed that the key does not already exist in the map; otherwise, problems may arise if one attempts to iterate through the map.
This map implementation is seldomly used in real-world applications (and not even provided in built-in libraries of languages such as Java) due to its inefficiency and is only considered if the map is expected to be very small.
#include <stddef.h>
typedef struct {
// A key-value pair of integers
int key, value;
} Entry;
typedef struct node_t {
// A node in a linked list - internal implementation of a Map
Entry *entry; // The current entry in our map
struct node_t *next; // The rest of our map
} Node;
typedef struct {
// Outer map wrapper (to hide interal implementation and
// reserve `NULL` for representing an invalid map reference instead of an empty map)
Node *root;
} Map;
int map_get(const Map *map, int key) {
// Returns the corresponding value to the key in the map
// Assumption: the key is present in the map
// (querying a nonexistent key yields undefined behavior)
const Node *n = map->root;
while (n->entry->key != key)
n = n->next;
return n->entry->value;
}
void map_set(Map *map, int key, int value) {
// Adds the key-value pair to the map if not present;
// otherwise reassigns it at the corresponding entry
Node *n = map->root;
while (n != NULL && n->entry->key != key)
n = n->next;
if (n != NULL)
n->entry->value = value;
else {
Node *tmp = map->root;
map->root = malloc(sizeof(Node));
map->root->entry = malloc(sizeof(Entry));
map->root->entry->key = key;
map->root->entry->value = value;
map->root->next = tmp;
}
}
void map_remove(Map *map, int key) {
// Removes an entry from the map with the given key
// Assumption: The given key-value pair exists
// (attempting to delete a nonexistent entry yields undefined behavior)
// This also implies that the map cannot be empty
if (map->root->entry->key == key) {
Node *tmp = map->root->next;
free(map->root->entry);
free(map->root);
map->root = tmp;
} else {
Node *parent = map->root, *child = parent->next;
while (child->next != NULL && child->entry->key != key) {
parent = child;
child = child->next;
}
parent->next = child->next;
free(child->entry);
free(child);
}
}
#include <criterion/criterion.h>
typedef struct {
// A key-value pair of integers
int key, value;
} Entry;
typedef struct node_t {
// A node in a linked list - internal implementation of a Map
Entry *entry; // The current entry in our map
struct node_t *next; // The rest of our map
} Node;
typedef struct {
// Outer map wrapper (to hide interal implementation and
// reserve `NULL` for representing an invalid map reference instead of an empty map)
Node *root;
} Map;
int map_get(const Map *map, int key);
void map_set(Map *map, int key, int value);
void map_remove(Map *map, int key);
Map *m;
Test(the_map_datatype, should_allow_querying_by_integer_key) {
// Map { 5 => 373, 12 => 23, -3 => 133 }
m = &((Map){
.root = &((Node){
.entry = &((Entry){
.key = 5,
.value = 373
}),
.next = &((Node){
.entry = &((Entry){
.key = 12,
.value = 23
}),
.next = &((Node){
.entry = &((Entry){
.key = -3,
.value = 133
}),
.next = NULL
})
})
})
});
cr_assert_eq(map_get(m, 12), 23);
cr_assert_eq(map_get(m, -3), 133);
cr_assert_eq(map_get(m, 5), 373);
cr_assert_eq(map_get(m, -3), 133, "A key-value pair should be able to be queried more than once");
}
Test(the_map_datatype, should_allow_us_to_set_key_value_pairs) {
m = malloc(sizeof(Map));
m->root = NULL; // `m` is now a properly initialized empty map
map_set(m, 3, 5);
cr_assert_eq(map_get(m, 3), 5);
map_set(m, 2, 7);
cr_assert_eq(map_get(m, 2), 7);
map_set(m, -1, -1);
cr_assert_eq(map_get(m, -1), -1);
map_set(m, 10, -187);
cr_assert_eq(map_get(m, 10), -187);
map_set(m, 3, 663);
cr_assert_eq(map_get(m, 3), 663);
map_set(m, 10, 2);
cr_assert_eq(map_get(m, 10), 2);
Node *n = m->root;
size_t size = 0;
while (n != NULL) {
size++;
n = n->next;
}
cr_assert_eq(size, 4, "The map should contain 4 elements at this point");
cr_assert_neq(size, 6, "The map should not contain 6 elements at this point");
n = m->root;
while (n != NULL) {
Node *tmp = n->next;
free(n->entry);
free(n);
n = tmp;
}
free(m);
}
Test(the_map_datatype, should_allow_us_to_remove_elements_from_it) {
m = malloc(sizeof(Map));
m->root = NULL;
map_set(m, 3, 5);
map_set(m, 2, 7);
map_set(m, -1, -1);
map_set(m, 10, -187);
map_set(m, 3, 663);
map_set(m, 10, 2);
cr_assert_eq(map_get(m, 3), 663);
cr_assert_eq(map_get(m, 2), 7);
cr_assert_eq(map_get(m, -1), -1);
cr_assert_eq(map_get(m, 10), 2);
map_remove(m, -1);
cr_assert_eq(map_get(m, 3), 663);
cr_assert_eq(map_get(m, 2), 7);
cr_assert_eq(map_get(m, 10), 2);
Node *n = m->root;
size_t size = 0;
while (n != NULL) {
size++;
n = n->next;
}
cr_assert_eq(size, 3, "The map should contain 3 elements at this point");
map_remove(m, 2);
cr_assert_eq(map_get(m, 3), 663);
cr_assert_eq(map_get(m, 10), 2);
n = m->root;
size = 0;
while (n != NULL) {
size++;
n = n->next;
}
cr_assert_eq(size, 2, "The map should contain 2 elements at this point");
map_remove(m, 10);
cr_assert_eq(map_get(m, 3), 663);
n = m->root;
size = 0;
while (n != NULL) {
size++;
n = n->next;
}
cr_assert_eq(size, 1, "The map should contain 1 element at this point");
map_remove(m, 3);
cr_assert_eq(m->root, NULL, "The map should be empty at this point");
free(m);
}
Really simple problem to work on if you have just started learing C#.
Determine the SUM of the 3 arrays and return the total in an int format.
Enjoy..
#Arrays
using System;
using System.Linq;
public static class Kata
{
public static int ArraySum(int[] arr1, int[] arr2, int[] arr3)
{
int[] newArray1 = arr1.Concat(arr2).ToArray();
int[] newArray2 = newArray1.Concat(arr3).ToArray();
int sum = newArray2.Sum();
return sum;
}
}
namespace Solution {
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest
{
[Test]
public void ArraySumBasicTest()
{
Assert.AreEqual(38, Kata.ArraySum(new int[]{6,2,9}, new int[]{1,5,4}, new int[]{10,1,0}));
Assert.AreEqual(-10, Kata.ArraySum(new int[]{-8,-6,3}, new int[]{5,-11,-8}, new int[]{2,8,5}));
}
}
}
#
#include <criterion/criterion.h>
#include <stdio.h>
Test(the_multiply_function, should_pass_all_the_tests_provided) {
for (int i = 0; i < 50; i++) {
puts("blah blah blah");
cr_expect_eq(1, 0);
}
}
Some user interactions, such as resizing and scrolling, can create a huge number of browser events in a short period of time. If listeners attached to these events take a long time to execute, the user's browser can start to slow down significantly. To mitigate this issue, we want to to implement a throttle function that will detect clusters of events and reduce the number of times we call an expensive function.
Your function will accept an array representing a stream of event timestamps and return an array representing the times that a callback should have been called. If an event happens within wait time of the previous event, it is part of the same cluster. Your function should satisfy the following use cases:
- Firing once on the first event in a cluster, e.g. as soon as the window starts resizing.
- Firing once after the last event in a cluster, e.g. after the user window stops resizing.
- Firing every interval milliseconds during a cluster, e.g. every 100ms while the window is resizing.
function throttle(wait, onLast, onFirst, interval, timestamps) {
let ret = [];
let cluster = [timestamps[0]];
for(let i=1; i<timestamps.length; i++) {
if(timestamps[i] - timestamps[i-1] <= wait) {
cluster.push(timestamps[i]);
} else {
let clusterEventTimes = evaluateCluster(wait, onLast, onFirst, interval, cluster);
clusterEventTimes.forEach( function(el){ ret.push(el); });
cluster = [timestamps[i]];
}
if(i == timestamps.length-1) {
let clusterEventTimes = evaluateCluster(wait, onLast, onFirst, interval, cluster);
clusterEventTimes.forEach( function(el){ ret.push(el); });
}
}
return ret;
}
// Determines all times when an event needs to be fired
function evaluateCluster(wait, onLast, onFirst, interval, cluster){
let ret = [];
if(onFirst) {
ret.push(cluster[0]); // push cluster start
}
if(interval != 0) {
let maxInterval = cluster[cluster.length-1];
if(onLast) {
maxInterval += wait;
}
for(let intEv = cluster[0]+interval; intEv < maxInterval; intEv+=interval) {
ret.push(intEv);
}
}
if(onLast) {
ret.push(cluster[cluster.length-1]+wait); // push cluster end
}
return ret;
}
// TODO: Replace examples and use TDD development by writing your own tests
describe('default tests', function() {
it('test1', function(){
Test.assertSimilar(throttle(20, false, true, 0, [0,10,20,30]), [0]);
});
it('test2', function(){
Test.assertSimilar(throttle(20, true, false, 0, [0,10,20,30]), [50]);
});
it('test3', function(){
Test.assertSimilar(throttle(20, false, true, 20, [0,10,20,30]), [0,20]);
});
it('test4', function(){
Test.assertSimilar(throttle(20, false, true, 0, [0,10,40]), [0,40]);
});
it('test5', function(){
Test.assertSimilar(throttle(20, true, false, 0, [0,10,40]), [30,60]);
});
it('test6', function(){
Test.assertSimilar(throttle(20, true, true, 0, [0,10,50]), [0,30,50,70]);
});
it('test7', function(){
Test.assertSimilar(throttle(20, true, true, 10, [0,10,50]), [0,10,20,30,50,60,70]);
});
});
Set 1 Challenge 1 for the cryptopal crypto challenges (https://cryptopals.com/sets/1/challenges/1).
Convert hex to base64
function hexToBase64(hex) {
return hex;
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should test for something", function(){
Test.assertEquals(hexToBase64(
'49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'),
'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t', 'Sample test provied');
});
});
You will be given an array of integers and a target value. Determine the number of pairs of array elements that have a difference equal to the target value.
For example, given an array of [1,2,3,4] and a target value of 1, we have three pairs meeting the condition. 2 - 1 = 1, 3 - 2 = 1, and 4 - 3 = 1.
Input Format:
The first line contains n and k, the number of array elements and the target value.
The second line contains n space-separated integers of the array.
Constraints:
2 ≤ n ≤ 105
0 < k < 109
each integer element arr[i], will conform to 0 < arr[i] < 2^31 - 1
each integer arr[i] will be unique
Output Format
An integer representing the number of pairs of integers whose difference is k.
Sample Input:
5, 2, [1, 5, 3, 4, 2]
Sample Output:
3
Explanation:
There are 3 pairs of integers in the set with a difference of 2: [5,3], [4,2], and [3,1].
function pairs(num_elements, target_value, array) {
return 0;
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe('default tests', function() {
it('t01', function(){
Test.assertSimilar(pairs(226, 687, [967551, 42711, 652888, 556131, 432461, 689084, 878716, 707516, 462627, 719131, 921983, 626364, 4162, 381455, 628368, 434733, 845482, 789342, 129922, 384203, 516975, 872544, 958157, 257969, 383516, 972027, 753530, 579132, 732314, 692990, 938898, 673695, 304274, 911598, 386363, 643777, 897942, 705604, 307205, 691832, 525153, 13560, 131633, 967903, 704917, 719007, 275998, 823133, 381356, 694812, 130946, 14247, 881464, 212321, 535615, 388113, 263786, 993408, 303132, 347246, 957012, 356253, 80278, 682192, 79591, 22168, 399471, 130259, 302213, 146877, 143512, 464001, 323710, 716383, 252562, 704230, 528752, 385676, 433835, 84087, 324397, 19622, 726853, 400158, 765711, 879403, 717070, 796189, 630429, 735240, 899316, 897255, 682879, 943532, 548896, 650909, 128885, 156561, 260454, 861309, 463314, 396080, 486644, 483429, 306518, 579819, 726166, 319856, 689771, 346559, 466803, 340669, 602785, 686432, 259959, 146736, 878107, 718444, 272951, 371357, 690458, 625990, 672321, 968982, 211634, 966184, 806955, 421135, 486063, 350431, 856525, 674382, 968295, 709010, 81652, 874036, 487437, 966921, 318376, 402219, 956325, 319682, 346722, 112336, 643090, 670617, 700593, 580506, 695051, 996996, 486750, 989387, 738565, 873231, 311817, 351118, 77220, 129572, 900003, 880777, 109146, 675069, 829732, 420069, 519779, 692670, 391266, 683566, 349744, 629055, 305831, 14934, 216260, 302900, 347933, 85417, 307892, 367031, 433148, 431774, 871170, 955638, 629386, 252687, 151756, 290426, 642403, 213008, 693677, 349307, 80965, 376767, 879481, 177826, 382142, 591034, 733001, 967608, 381793, 957699, 382829, 251634, 641716, 226476, 530957, 871857, 658236, 615467, 401532, 681505, 485376, 694364, 144675, 23169, 673008, 146049, 581193, 461940, 22324, 641029, 878794, 620846, 558429, 6994, 41576, 717757]), 80);
});
it('t02', function(){
Test.assertSimilar(pairs(520, 1341, [480247, 690951, 368650, 575544, 932592, 321567, 652970, 963956, 746702, 824511, 980999, 242171, 75168, 144120, 203281, 992812, 430432, 46770, 566884, 92507, 792622, 718045, 789412, 790753, 802355, 881533, 612820, 506671, 502468, 665638, 66191, 951403, 922175, 881334, 291814, 742679, 370213, 713716, 14949, 629095, 91166, 894145, 178277, 835114, 896011, 824973, 920015, 269023, 234465, 402146, 357349, 395469, 910656, 176710, 711413, 726112, 433114, 96368, 686702, 297662, 135664, 95027, 998231, 820113, 699691, 528591, 250234, 797555, 199258, 688762, 783282, 281335, 190961, 349489, 587162, 850086, 639235, 74994, 718529, 123181, 552080, 250564, 403128, 431140, 442349, 16543, 502801, 701950, 456529, 772458, 91184, 654812, 193933, 347157, 933933, 870810, 400418, 127204, 318247, 348498, 406169, 15202, 918819, 102695, 150771, 918674, 90677, 710072, 823632, 856234, 906310, 160235, 506824, 510573, 836828, 901556, 699472, 500897, 403487, 510915, 141438, 148591, 312882, 801014, 954648, 281117, 1106, 262483, 252916, 841213, 623621, 794873, 957677, 657494, 394128, 810582, 914651, 798332, 391446, 755404, 505150, 679777, 822795, 314223, 389594, 606607, 125863, 17631, 344343, 458427, 259089, 989403, 181599, 593315, 988512, 580598, 936534, 367309, 799673, 271705, 320929, 360031, 503809, 846577, 22595, 641086, 535783, 494704, 68552, 338979, 807411, 64529, 368075, 428458, 717392, 466549, 476353, 686973, 923116, 821454, 429091, 934899, 794776, 97519, 632949, 41245, 995494, 172116, 959858, 681118, 118915, 293202, 248893, 344475, 156419, 212590, 492022, 124522, 826314, 682459, 692292, 561421, 238980, 498215, 205666, 403923, 94837, 552521, 792094, 716398, 188802, 619598, 632016, 543965, 329954, 207226, 569425, 157760, 392787, 2447, 14066, 715057, 385708, 84803, 233616, 242362, 970989, 17784, 406600, 190058, 631608, 516318, 580430, 53746, 3374, 279019, 855452, 996890, 748043, 813264, 313625, 97709, 772158, 369416, 485470, 678410, 900215, 195274, 634290, 491797, 949301, 496874, 833604, 821829, 431773, 717739, 807900, 43509, 173457, 3788, 201940, 465658, 120256, 311541, 413762, 75343, 642456, 700813, 317648, 159101, 559156, 88502, 781591, 740587, 315015, 521764, 832196, 635631, 708731, 741928, 356008, 346807, 316356, 716867, 894513, 496804, 797970, 130748, 586503, 642427, 646069, 957903, 444465, 707390, 633357, 656993, 237639, 11826, 316906, 103685, 356856, 494122, 838169, 486757, 843895, 270364, 750395, 793435, 463867, 242694, 365968, 87148, 689298, 491556, 878640, 416615, 200599, 854111, 356584, 328613, 490899, 315564, 88484, 490456, 991956, 658127, 736560, 197956, 349839, 404828, 523105, 483347, 584480, 995549, 312333, 585821, 16934, 975304, 896546, 874617, 693633, 365715, 244874, 492781, 318962, 234957, 13861, 645179, 315565, 568084, 492240, 893522, 881838, 552193, 658334, 129149, 314966, 654311, 13769, 576885, 40072, 115125, 879156, 403659, 228762, 453847, 324249, 744020, 238238, 407941, 306587, 771117, 148637, 598738, 17884, 48869, 560284, 794644, 356657, 594656, 251575, 596308, 869469, 895486, 812515, 260602, 877299, 222492, 525909, 662368, 965297, 706240, 88489, 358526, 187258, 502238, 875958, 490681, 915992, 588503, 12520, 643941, 762594, 98860, 504941, 319588, 126516, 897533, 334149, 996835, 130213, 316905, 145461, 180976, 170775, 570766, 537124, 998176, 506491, 729202, 493581, 103764, 655652, 359018, 411918, 77428, 974422, 313674, 125341, 744610, 578226, 236298, 935274, 494479, 482006, 883179, 484688, 465208, 121597, 459553, 310411, 208567, 811923, 93848, 493138, 505483, 357998, 174798, 226999, 222733, 892181, 962615, 94822, 451165, 683431, 591974, 15593, 473717, 845236, 775340, 348699, 524446, 18972, 842554, 148147, 527250, 65870, 656153, 353975, 692, 354667, 318989, 331295, 340320, 287289, 366734, 175369, 350830, 142779, 894555, 471557, 643768, 674387, 478608, 856793, 390002, 355316, 809241, 877815, 196615, 994153, 471101, 677069, 574203, 938399, 796214, 316307, 534142, 322908, 211249, 459768, 101003, 577077, 358690, 673046, 990184, 309958, 451388, 712375, 455188, 206055, 527236, 92525, 54848, 879981, 935193, 620939, 4902, 921883, 461109]), 205);
});
it('t03', function(){
Test.assertSimilar(pairs(517, 812, [954818, 241033, 33130, 770982, 268961, 612387, 4694, 920450, 204026, 578561, 905400, 335039, 911529, 343403, 531471, 818030, 429413, 666038, 584156, 471248, 607892, 942323, 539016, 279499, 703163, 376851, 501882, 281461, 929502, 480261, 241212, 571608, 775056, 168082, 338290, 54785, 939503, 147529, 569984, 837271, 763542, 64258, 377663, 716858, 877549, 776680, 875582, 438741, 967488, 44397, 572144, 797670, 530875, 493357, 53749, 936749, 899221, 212351, 350831, 316195, 876737, 251042, 135260, 818842, 537452, 311339, 257475, 768872, 628049, 25361, 580997, 355301, 256008, 595301, 904209, 426401, 924680, 896443, 950331, 716247, 512825, 552587, 152729, 949519, 796858, 492545, 225791, 317819, 532066, 680205, 926567, 679393, 379225, 580185, 25503, 552021, 819654, 141913, 6318, 43585, 629808, 535828, 177213, 659635, 326464, 958066, 669159, 181416, 161859, 531255, 228882, 930201, 422310, 678223, 621490, 494981, 852726, 168606, 539394, 420019, 530659, 241170, 310527, 161047, 778304, 165334, 532067, 250230, 308290, 100913, 367412, 375587, 102882, 194122, 709517, 935125, 507056, 5380, 121400, 658913, 136884, 359888, 57729, 516523, 596113, 787816, 125984, 676599, 310726, 259099, 111154, 482930, 228070, 654604, 723593, 768253, 514449, 515261, 665640, 162285, 619866, 573768, 27797, 984557, 582682, 7130, 821278, 466538, 133780, 539076, 366600, 179603, 420505, 797134, 996709, 928191, 171122, 826430, 643488, 924943, 278687, 918727, 921163, 267743, 770987, 970121, 309914, 248606, 869640, 799294, 681017, 229694, 441177, 521646, 584968, 661882, 828081, 794851, 733189, 810624, 619054, 169418, 349266, 919638, 11862, 947183, 637643, 162671, 956442, 137, 687541, 831830, 658823, 846874, 939067, 870452, 531254, 788628, 312151, 925755, 594489, 804310, 353298, 663602, 931373, 153704, 770689, 120433, 822976, 419961, 136072, 898409, 383863, 385168, 619671, 868828, 934205, 241758, 207414, 690642, 334985, 620678, 530443, 24691, 418881, 101048, 900414, 487782, 778734, 867204, 440365, 178837, 941353, 333180, 518147, 663064, 203276, 176401, 441989, 317007, 529847, 641419, 41593, 390615, 868016, 664414, 43217, 733386, 26985, 23067, 713811, 168894, 909976, 470423, 988165, 587318, 439553, 334173, 566198, 241073, 368224, 932637, 549585, 61730, 621295, 596925, 313384, 249418, 588185, 969112, 803436, 431037, 714623, 46021, 538264, 793837, 377211, 369036, 487426, 590675, 665226, 545079, 355599, 807544, 174867, 909409, 577749, 443148, 52125, 475864, 634439, 604989, 137354, 10467, 74439, 988392, 256663, 649813, 969924, 775868, 761389, 897597, 875925, 719927, 332549, 585409, 935017, 167270, 984261, 764237, 762559, 337478, 895631, 933501, 376399, 443960, 113017, 766100, 613220, 310631, 342518, 315132, 931013, 444566, 793679, 230506, 927379, 787004, 512013, 917915, 835208, 632284, 925574, 884006, 662694, 494169, 357721, 478300, 794892, 30754, 154979, 924904, 408428, 195091, 820466, 829705, 242344, 622203, 55597, 430225, 920351, 918014, 388179, 587174, 763371, 643855, 329021, 788941, 903756, 570796, 321960, 500240, 32318, 556670, 536640, 369848, 160235, 504277, 948707, 476676, 455603, 531907, 825618, 513637, 207980, 707135, 863491, 674064, 31506, 193467, 717502, 278804, 2224, 343330, 975012, 828893, 938691, 517335, 903746, 131159, 952104, 642231, 418069, 53973, 678581, 551795, 934313, 764183, 245063, 572956, 378023, 417257, 894495, 601777, 289281, 933393, 661070, 860326, 242267, 583344, 99424, 159423, 730079, 714228, 333361, 765978, 519341, 433382, 26173, 277526, 559659, 678299, 677411, 705419, 477488, 534738, 515711, 444772, 378475, 824806, 6545, 530442, 777110, 772611, 488868, 769065, 443706, 864337, 49922, 955630, 765166, 581720, 763013, 581058, 901332, 397636, 208226, 877924, 532878, 658011, 777492, 339102, 45209, 717420, 389803, 42405, 401865, 830517, 364816, 5506, 492644, 969871, 234527, 937067, 495793, 762201, 663647, 767441, 740649, 957254, 108566, 64095, 391627, 871162, 932581, 798453, 265449, 517287, 764354, 336666, 894007, 258287, 25757, 344142, 137696, 582532, 138508, 918826, 935937, 58478, 74468, 581870, 245226, 14684, 937879, 550320, 968300]), 192);
});
it('t16', function(){
Test.assertSimilar(pairs(5, 2, [1, 5, 3, 4, 2]), 3);
});
it('t17', function(){
Test.assertSimilar(pairs(10, 1, [363374326 364147530, 61825163, 1073065718, 1281246024, 1399469912, 428047635, 491595254, 879792181, 1069262793]), 0);
});
});