5 kyu

Shuffle It Up

436 of 577raulbc777

Description:

We have an array of unique elements. A special kind of permutation is the one that has all of its elements in a different position than the original.

Let's see how many of these permutations may be generated from an array of four elements. We put the original array with square brackets and the wanted permutations with parentheses.

arr = [1, 2, 3, 4]
      (2, 1, 4, 3)
      (2, 3, 4, 1)
      (2, 4, 1, 3)
      (3, 1, 4, 2)
      (3, 4, 1, 2)
      (3, 4, 2, 1)
      (4, 1, 2, 3)
      (4, 3, 1, 2)
      (4, 3, 2, 1)
      _____________
A total of 9 permutations with all their elements in different positions than arr

The task for this kata would be to create a code to count all these permutations for an array of certain length.

Features of the random tests:

l = length of the array
10 ≤ l ≤ 5000

See the example tests.

Enjoy it!

Performance
Algorithms
Mathematics
Machine Learning
Combinatorics
Number Theory

Stats:

CreatedSep 12, 2018
PublishedSep 12, 2018
Warriors Trained3291
Total Skips236
Total Code Submissions3901
Total Times Completed577
Python Completions436
Ruby Completions40
Haskell Completions35
JavaScript Completions88
Factor Completions7
Rust Completions15
Go Completions6
Total Stars78
% of votes with a positive feedback rating87% of 108
Total "Very Satisfied" Votes84
Total "Somewhat Satisfied" Votes19
Total "Not Satisfied" Votes5
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • raulbc777 Avatar
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • cliffstamp Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • avermakov Avatar
  • gifti Avatar
Ad