Skip to content
🤔prompts chat🧠
🔍
question:Convert this regex expression from python to java syntax. pattern = r"[A-Za-z0-9_]+

answer:String pattern = "[A-Za-z0-9_]+";

question:Generate a list of length n containing all numbers from 1 to n.

answer:def gen_list(n): list = [] for i in range(1, n+1): list.append(i) return list

question:Using an existing function, update the given array of numbers to contain elements which are the square of each original element. array = [1,2,3,4,5]

answer:array = list(map(lambda x: x**2, array))

question:Print all permutations of an input array. array = [1,2,3]

answer:def permutations(array): if len(array) == 0: return if len(array) == 1: return [array] perms = [] for i in range(len(array)): elem = array[i] rem_perms = permutations(array[:i] + array[i+1:]) for perm in rem_perms: perms.append([elem] + perm) return perms

Released under the MIT License.

has loaded