5 kyu

Shuffle It Up

433 of 574raulbc777

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 Trained3283
Total Skips236
Total Code Submissions3889
Total Times Completed574
Python Completions433
Ruby Completions39
Haskell Completions34
JavaScript Completions86
Factor Completions6
Rust Completions14
Go Completions5
Total Stars77
% of votes with a positive feedback rating87% of 107
Total "Very Satisfied" Votes84
Total "Somewhat Satisfied" Votes18
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