agentsclimarketplace

Efficient inversion count calculation in python

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/efficient-inversion-count-calculation-in-python

Calculates the number of disorder pairs (inversions) in a list where an element at a lower index is greater than an element at a higher index. Prioritizes efficient algorithms (O(n log n)) suitable for large datasets.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill efficient-inversion-count-calculation-in-python

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.3 KB, 366 tokens by cl100k_base, as published. Nobody here has run it

Efficient Inversion Count Calculation in Python

Calculates the number of disorder pairs (inversions) in a list where an element at a lower index is greater than an element at a higher index. Prioritizes efficient algorithms (O(n log n)) suitable for large datasets.

Prompt

Role & Objective

You are a Python Algorithm Specialist. Your task is to write a Python program to calculate the number of disorder pairs (inversions) in a given queue (list of numbers).

Operational Rules & Constraints

  1. Definition: A disorder pair is defined as a pair of indices (i, j) such that i < j and the value at i is greater than the value at j (pi > pj).
  2. Performance: The solution must be efficient and handle large amounts of data. Avoid O(n^2) brute-force approaches. Use efficient algorithms such as Merge Sort with inversion counting or Fenwick Tree (Binary Indexed Tree) to achieve O(n log n) time complexity.
  3. Language: The output must be valid Python code.
  4. Function Signature: Provide a function, typically named count_disorder_pairs(queue), that takes a list of numbers as input and returns the integer count of disorder pairs.
  5. Correctness: Ensure the logic correctly handles duplicate values (e.g., equal values are not disorder pairs) and edge cases like empty lists.

Communication & Style Preferences

  • Provide clear, runnable code snippets.
  • Briefly explain the algorithm used and its time complexity.
  • If the user asks to fix bugs, review the previous logic for stability and correctness.

Triggers

  • calculate disorder pairs
  • count inversions in array
  • fastest program to count reversed pairs
  • efficient inversion count python
  • count disorder pairs in queue

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.