← run

bcb-0000

1.000
10/10 tests· lib-knowledge

Proposed solution

```python
import itertools
from random import shuffle

def task_func(numbers=list(range(1, 3))):
    """
    Calculates the average of the sums of absolute differences between each pair of consecutive numbers 
    for all permutations of a given list. Each permutation is shuffled before calculating the differences.

    Args:
    - numbers (list): A list of numbers. Default is numbers from 1 to 10.
    
    Returns:
    float: The average of the sums of absolute differences for each shuffled permutation of the list.

    Requirements:
    - itertools
    - random.shuffle

    Example:
    >>> result = task_func([1, 2, 3])
    >>> isinstance(result, float)
    True
    """
    if len(numbers) <= 1:
        return 0.0
    
    # Generate all permutations of the input list
    permutations = list(itertools.permutations(numbers))
    
    total_sum = 0.0
    
    # For each permutation, shuffle it and calculate the sum of absolute differences
    for perm in permutations:
        # Create a copy of the permutation to avoid modifying the original
        shuffled = list(perm)
        shuffle(shuffled)
        
        # Calculate sum of absolute differences between consecutive elements
        diff_sum = 0.0
        for i in range(len(shuffled) - 1):
            diff_sum += abs(shuffled[i] - shuffled[i + 1])
        
        total_sum += diff_sum
    
    # Return the average
    return total_sum / len(permutations)
```

Test output (stdout)

..........                                                               [100%]
10 passed in 6.36s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.