← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 477/668
🔀 랜덤
불러오는 중…

[output] | def herons_formula(lengths): a, b, c = lengths[0], lengths[1], lengths[2] s = (a + b + c) / 2 area = (s*(s-a)*(s-b)*(s-c))** 0.5 return area [instruction] | Find the area of a triangle using the Heron's formula [input] | lengths = [3, 4, 5]

[output] | def concatenate(str1, str2): return str1 + str2 [instruction] | Develop an algorithm to concatenate two strings. [input] | String 1: "Hello," String 2: "World!"

[output] | import string import random def random_string(): capitalletter = random.choice(string.ascii_uppercase) lowercaseletter1 = random.choice(string.ascii_lowercase) lowercaseletter2 = random.choice(string.ascii_lowercase) return capitalletter + lowercaseletter1 + lowercaseletter2 [instruction] | Generate a random string with the a capital letter followed by two lower case letters. [input] |

[output] | # Node class class Node: def __init__(self, data): self.data = data self.children = [] # A function to print the n-ary tree def printNaryTreeUtil(root, func, level = 0): # If node is None, simply return if root is None: return # Process child nodes of root r [instruction] | Develop an algorithm to print all the possible n-ary trees with a given number of nodes. [input] | n=4

[output] | ^[a-z]+$ [instruction] | Generate a regular expression to match words that contain only lowercase letters. [input] |

[output] | def third_largest(root): if root is None: return None queue = [] queue.append(root) while len(queue): curr = queue.pop(0) if curr.right: queue.append(curr.right) if curr.left: queue.append(curr.left) if len(queue)>1: [instruction] | You need to write an algorithm to find the third largest value in a Binary Search Tree. [input] | 8 / \ 3 10 / \ \ 1 6 14 / \ / 4 7 13

[output] | # Function to validate an IPv4 address def validate_IPv4(IP): # Split the IP string by '.' ip_split = IP.split('.') #Checking for the corner cases if (len(ip_split) == 4) and (1 <= int(ip_split[0]) <= 223) and (int(ip_split[0]) != 127) and (int(ip_split[0]) != 169 or int(ip_sp [instruction] | Edit the given code to validate an IP address. [input] | # Function to validate an IPv4 address def validate_IPv4(IP):

[output] | def modify_string(string): new_string = "" for i in string: if (i.isupper()) == True: new_string += i.lower() elif (i.islower()) == True: new_string += i.upper() return new_string [instruction] | Develop an algorithm to modify a given string by changing the case of each character. [input] | string = "Hello World"

[output] | def count_parameters(url): params = url.split('?')[-1] return len(params.split('&')) [instruction] | Suppose a web page contains an unknown number of parameters. Write a function to count the number of parameters present in a given URL. [input] | https://www.example.com?query=environment&limit=10&sort=descending

[output] | def remove_first_occurrence(arr, element): if element in arr: arr.remove(element) return arr [instruction] | Write a function to remove the first occurrence of a specified element from a given list. [input] | [2, 4, 8, 9, 4]

[output] | def find_duplicates(numbers): seen = set() duplicates = set() for num in numbers: if num in seen: duplicates.add(num) else: seen.add(num) return list(duplicates) [instruction] | Write a function to find all elements that appear more than once in a given array. [input] | [1, 3, 2, 3, 8, 9, 10]

[output] | import string import random def gen_random_string(size): letters = string.ascii_letters + string.digits return ''.join(random.choice(letters) for i in range(size)) random_string = gen_random_string(8) print(random_string) [instruction] | Generate an 8 character random string. [input] |

[output] | #!/bin/bash # Remove all system log files sudo rm /var/log/*.log [instruction] | Create a script to delete all system logs. [input] |

[output] | function sumArray(array) { let result = 0; array.forEach(function(element) { result += element; }); return result; } [instruction] | Compute the sum of all elements in an array given as an argument to a JavaScript function. [input] |

[output] | function classifyObject(object) { if(object.shape === 'round') { return 'object is round'; } else if(object.color === 'red') { return 'object is red'; } else if(object.size <= 8) { return 'object is small'; } else { return 'object is large'; } } [instruction] | Classify three objects using a decision tree algorithm written in JavaScript. [input] | Object 1: round, red, 5cm Object 2: square, green, 10cm Object 3: triangular, red, 8cm

[output] | #!/bin/bash # Capture the output of command result=$(bash -c "${COMMAND}") # Store the output of command in a file echo "$result" >> output.txt # Include timestamp echo "Result at: $(date)" >> output.txt # Add a newline to results file echo >> output.txt [instruction] | Modify a given shell script to generate a text-based report of the commands run in the bash shell. [input] |

[output] | public static List<int[]> findSumPairs(int[] arr, int target) { List<int[]> pairs = new ArrayList<>(); Map<Integer, Integer> numFreqMap = new HashMap<>(); for (int value : arr) { numFreqMap.put(value, numFreqMap.getOrDefault(value, 0) + 1); } for (int value : arr) [instruction] | Write a Java program to find all pairs of integers from an array whose sum equals a given number. [input] |

[output] | zyxwvutsrq [instruction] | Generate a string containing the first 10 characters of the alphabet in reverse order. [input] |

[output] | The function of the Bluetooth signal is to send a signal to the Bluetooth module. [instruction] | Determine the function of the Bluetooth signal in the given program. [input] | void setup() { Serial.begin(9600); Bluetooth.begin(9600); } void loop() { BluetoothSignal(); } void BluetoothSignal() { // Code to send a signal to the Bluetooth module. }

[output] | def convert_celsius_to_kelvin(celsius): kelvin = celsius + 273.15 return kelvin [instruction] | Create a Python program to convert a given temperature in Celsius to Kelvin. [input] |

[output] | SELECT city, COUNT(*) AS num_employees FROM employees GROUP BY city; [instruction] | Create a SQL query that returns the number of employees in each city. [input] |

[output] | my_list = [10, 20, 30, 40, 50] sum = 0.0 for x in my_list: sum += x mean = sum / len(my_list) [instruction] | Edit the given Python code to compute the mean of the given list of numbers. [input] | my_list = [10, 20, 30, 40, 50] sum = 0.0 for x in my_list: sum += x

[output] | import pandas as pd from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier # Import Iris dataset iris_data = pd.read_csv("iris.csv") # Split dataset into training and testing X = iris_data.drop("species", axis=1) y = iris_data['species'] X_train, X [instruction] | Train a Random Forest classifier in Python on the Iris dataset. [input] |

[output] | switch(grade) { case 'A': gradeValue = 4.0; break; case 'B': gradeValue = 3.0; break; case 'C': gradeValue = 2.0; break; case 'D': gradeValue = 1.0; break; default: gradeValue = 0; break; } [instruction] | Rewrite the following if-statement into a switch statement. [input] | if (grade == "A") { gradeValue = 4.0; } else if (grade == "B") { gradeValue = 3.0; } else if (grade == "C") { gradeValue = 2.0; } else if (grade == "D") { gradeValue = 1.0; }

[output] | def normalize_string(string): """Normalize a string by removing white spaces, changing to lower case and replacing special characters with underscores.""" # Remove whitespaces normalized_string = string.replace(" ", "") # Convert to lowercase normalized_string = normalized_strin [instruction] | Write a function in Python to normalize a given string by removing white spaces, changing to lower case and replacing special characters with underscores. [input] | "Hello World!"

[output] | my_array = [5, 11, 7, 10, 2] # Function to find the largest number def find_largest_number(array): # Assume that the first item in the array is the largest largest = array[0] # Now loop through the array to find the largest number for num in array: # If a number is larger t [instruction] | Print the largest number in a given array in Python. [input] | my_array = [5, 11, 7, 10, 2]

[output] | for (let i = 10; i > 0; i--) { console.log(i); } // Output: 10 9 8 7 6 5 4 3 2 1 [instruction] | Create a for loop in JavaScript to loop backwards from 10 to 1. [input] |

[output] | def add(*nums): """Add two or more numbers.""" # Initialize sum result = 0 # Iterate through given numbers for num in nums: result += num # Return the sum return result # Example sum = add(15, 7, 10) print(sum) # Output: 32 [instruction] | Create a function in Python to add two numbers, which may take any number of arguments. [input] |

[output] | public class Stack { private int[] stackArray; private int maxSize; private int top; public Stack(int size) { maxSize = size; stackArray = new int[maxSize]; top = -1; } public void push(int item) { stackArray[++top] = item; } [instruction] | Write a stack class in Java. [input] |

[output] | def DFS(root): S = [] visited = [] S.append(root) while len(S) > 0: node = S.pop() visited.append(node) for vertex in node.get_adjacent_vertices(): if vertex not in visited: S.append(vertex) return visited [instruction] | Implement a DFS algorithm for a tree data structure. [input] |

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프