All Possible Permutations

Given a set of distinct integers, this algorithm will return all possible permutations of those integers. For example, if the input is [1,2,3], the algorithm will return [[ 1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]].


Given a set of distinct integers, return all possible permutations.
Example input: 
Example output: 


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]
        result = []
        for i in range(len(nums)):
            for j in permute(nums[:i] + nums[i+1:]):
                result.append([nums[i]] + j)
        return result


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 sublist without the current number. This is then added to the list of permutations.

Evaluated at: 2022-11-30 16:15:26