R/inversions.R

Defines functions inversions

Documented in inversions

## It counts the number of inversions of a permutation.

inversions <- function(x){
  n <- length(x)
  k <- 0
  for (i in 1:(n-1))
    for (j in i+1:n)
      if(isTRUE(x[i]>x[j])==TRUE)  k <- k+1 
  else  k <- k 
  return(k)
}

Try the Tex4exams package in your browser

Any scripts or data that you put into this service are public.

Tex4exams documentation built on May 31, 2023, 8:04 p.m.