Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 added 48 characters in body
source | link

The wrong answer got accepted! The correct answer is 3.

From Wikipedia: Kendall tau distance is also called bubble-sort distance since it is equivalent to the number of swaps that the bubble sort algorithm would take to place one list in the same order as the other list.

import itertools

def kendell_tau_distance(order_a, order_b): pairs = itertools.combinations(range(1, len(order_a)+1), 2) distance = 0 for x, y in pairs: a = order_a.index(x) - order_a.index(y) b = order_b.index(x) - order_b.index(y) if a * b < 0: distance += 1 return distance

print kendell_tau_distance([3,1,2], [2,1,3]) 3

import itertools

def kendall_tau_distance(order_a, order_b):
    pairs = itertools.combinations(range(1, len(order_a)+1), 2)
    distance = 0
    for x, y in pairs:
        a = order_a.index(x) - order_a.index(y)
        b = order_b.index(x) - order_b.index(y)
        if a * b < 0:
            distance += 1
    return distance

print kendall_tau_distance([3,1,2], [2,1,3])
3

The wrong answer got accepted! The correct answer is 3.

From Wikipedia: Kendall tau distance is also called bubble-sort distance since it is equivalent to the number of swaps that the bubble sort algorithm would take to place one list in the same order as the other list.

import itertools

def kendell_tau_distance(order_a, order_b): pairs = itertools.combinations(range(1, len(order_a)+1), 2) distance = 0 for x, y in pairs: a = order_a.index(x) - order_a.index(y) b = order_b.index(x) - order_b.index(y) if a * b < 0: distance += 1 return distance

print kendell_tau_distance([3,1,2], [2,1,3]) 3

The wrong answer got accepted! The correct answer is 3.

From Wikipedia: Kendall tau distance is also called bubble-sort distance since it is equivalent to the number of swaps that the bubble sort algorithm would take to place one list in the same order as the other list.

import itertools

def kendall_tau_distance(order_a, order_b):
    pairs = itertools.combinations(range(1, len(order_a)+1), 2)
    distance = 0
    for x, y in pairs:
        a = order_a.index(x) - order_a.index(y)
        b = order_b.index(x) - order_b.index(y)
        if a * b < 0:
            distance += 1
    return distance

print kendall_tau_distance([3,1,2], [2,1,3])
3
1
source | link

The wrong answer got accepted! The correct answer is 3.

From Wikipedia: Kendall tau distance is also called bubble-sort distance since it is equivalent to the number of swaps that the bubble sort algorithm would take to place one list in the same order as the other list.

import itertools

def kendell_tau_distance(order_a, order_b): pairs = itertools.combinations(range(1, len(order_a)+1), 2) distance = 0 for x, y in pairs: a = order_a.index(x) - order_a.index(y) b = order_b.index(x) - order_b.index(y) if a * b < 0: distance += 1 return distance

print kendell_tau_distance([3,1,2], [2,1,3]) 3