Return all possible permutations of a set of distinct integers.

This problem asks for all possible permutations of a set of distinct integers.

Problem

Given a set of distinct integers, return all possible permutations.
Example input:
[1,2,3]
Example output:
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def permute(nums):
    if len(nums) == 1:
        return [nums]
    else:
        result = []
        for i in range(len(nums)):
            for j in permute(nums[:i] + nums[i+1:]):
                result.append([nums[i]] + j)
        return result

print(permute([1,2,3]))

A.I. Evaluation of the Solution

This solution is complete and solves the problem. The approach is to generate all permutations by iterating through the list of numbers and recursively generating all permutations of the remaining numbers.

Evaluated at: 2022-12-06 00:15:43