← 목록

Synth · CodeAlpaca일부

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

[output] | def is_prime(number): if (number <= 1): return False if (number <= 3): return True if (number % 2 == 0 or number % 3 == 0): return False i = 5 while (i * i <= number): if (number % i == 0 or number % (i + 2) == 0): return False [instruction] | Using a loop and a conditional statement in Python, check if the number is a prime number. [input] | let number = 13;

[output] | for (let item of myList) { console.log(item); } [instruction] | Create a for loop which iterates through the given list and prints the value of each item. [input] | let myList = [3, 5, 7, 9];

[output] | let result = []; for (let i = 0; i < my_data.length; i++) { let max_val = 0; for (let j = 0; j < my_data[i].length; j++) { if (my_data[i][j] > max_val) { max_val = my_data[i][j]; } } result.push(max_val); } console.log(result); [instruction] | Using the given data, calculate and output the maximum values of each row. [input] | let my_data = [[1, 10, 2], [12, 4, 9], [5, 3, 7]];

[output] | let index = my_array.lastIndexOf(my_number); console.log(index); [instruction] | Determine and output the last occurence of the given number in an array. [input] | let my_array = [2, 4, 8, 6, 2]; let my_number = 2;

[output] | let second_half = my_string.substring(my_string.length / 2); console.log(second_half); [instruction] | Print the second half of the given string. [input] | let my_string = "How are you doing today?"

[output] | def containsValue(arr, value): for item in arr: if item == value: return True return False print(containsValue(myArray, myValue)) [instruction] | Implement a function that takes two parameters, an array and a value, and returns true if the array contains the value and false if it does not. [input] | let myArray = [1, 2, 3, 4, 5]; let myValue = 3;

[output] | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); printMyName(); } public static void printMyName(){ System.out.println("John Doe"); } } [instruction] | Edit the following Java program to add a method printMyName. The method should print your name. [input] | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }

[output] | function largestPrime(N){ let max_prime = -1; for(let i = 2; i <= N; i++) { if (isPrime(i) && i > max_prime) max_prime = i; } return max_prime; } function isPrime(number){ for (let i = 2; i < Math.sqrt(number); i++) { if (number % i == 0) [instruction] | Build a JavaScript program to compute the largest prime number less than a given number N [input] |

[output] | def longestIncreasingSubarray(arr): n = len(arr) max_len = 1 curr_len = 1 for i in range(1, n): #if current element is greater than its previous element if (arr[i] > arr[i-1]): curr_len += 1 else: if (curr_len > max_len): [instruction] | Create an algorithm to find the longest continuous increasing subarray. [input] |

[output] | SELECT DATEDIFF(date_field_2, date_field_1) AS Days_Difference FROM table; [instruction] | Write a SQL query to calculate the number of days between two date fields [input] |

[output] | def maximize_sum(arr, k): arr.sort() result = 0 for i in range(len(arr)-1, len(arr)-k-1, -1): result += arr[i] return result [instruction] | Implement an algorithm to select k elements from an array such that the sum of those elements is maximized [input] |

[output] | Fruits: Apple, Banana, Lemon Vegetables: Carrot, Tomato [instruction] | Categorize the words from the list ["Apple", "Carrot", "Banana", "Tomato", "Lemon"] [input] |

[output] | public class Fibonacci { public static void main(String[] args) { int limit = 10; System.out.print("Fibonacci Series of "+limit+" numbers: "); for(int i=0; i<limit; i++){ System.out.print(fibonacci(i)+" "); } } public static int fibonacci(int [instruction] | Write a Java program to produce Fibonacci numbers up to a given number [input] |

[output] | import numpy as np rand_sample = np.random.randint(low=0, high=100, size=10) [instruction] | Generate a random sample of size 10 using numpy [input] |

[output] | from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/v1/get_data', methods=['GET']) def get_data(): data = [1, 2, 3, 4, 5] return jsonify(data) if __name__ == '__main__': app.run() [instruction] | Construct an API using Flask that returns an array of integers in response to a request [input] |

[output] | import matplotlib.pyplot as plt male_salaries = [3000, 3500, 3000, 3500, 4000] female_salaries = [2500, 3000, 2500, 3000, 3500] plt.bar(range(len(male_salaries)), male_salaries, width=0.35, label='Male Salaries') plt.bar([x+0.35 for x in range(len(female_salaries))], [instruction] | Design a data visualization to show the average salary per gender [input] |

[output] | int total = 0; for (int i = 0; i <= 100000000-1; i+=2){ total += (i + (i + 1)); } [instruction] | Rewrite the following Java for loop for producing the same results in a more efficient way. [input] | int total = 0; for (int i = 0; i < 100000000; i++) { total += i; }

[output] | class Deck: def __init__(self): self.cards = [] def populate(self): suits = ['Hearts', 'Spades', 'Clubs', 'Diamonds'] numbers = [2,3,4,5,6,7,8,9,10,'Jack','Queen','King','Ace'] for suit in suits: for number in numbers: self.c [instruction] | Design a Python class structure for playing cards with two classes: Deck and Card. [input] |

[output] | SELECT * FROM sales WHERE sales_amount > 1000; [instruction] | Write a SQL query for finding records where the sales amount is greater than 1000. [input] |

[output] | Three methods for removing duplicate elements from an array in JavaScript are: 1. Using the Set object: The Set object lets you store unique values of any type, escluding duplicate values. 2. Using the filter method: The filter method creates a new array with all elements that pass the test implemen [instruction] | Suggest three methods for removing duplicate elements from an array in JavaScript. [input] |

[output] | function findCommonNumbers(arrA, arrB, arrC) { let common = []; for (let i=0; i < arrA.length; i++) { if (arrB.includes(arrA[i]) && arrC.includes(arrA[i])) { common.push(arrA[i]); } if (common.length === 3) { break; } } return common; } let arrayA [instruction] | Write a JavaScript function to find the first three common numbers in three arrays. [input] | Array A: [2, 3, 5, 6, 7, 9] Array B: [5, 7, 10, 11, 15] Array C: [7, 9, 10, 11, 12]

[output] | SELECT * FROM table WHERE parent_id > (SELECT MIN(id) FROM Table) [instruction] | Write a SQL query to find the rows in a table where the value of the 'parent_id' column is greater than the minimum value of the 'id' column. [input] |

[output] | function isLeapYear(year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); } [instruction] | Create a function to identify leap years in JavaScript. [input] |

[output] | SELECT post_id, AVG(likes) AS avg_likes FROM table GROUP BY post_id [instruction] | Write a SQL query to find the average number of 'likes' for each post in a table. [input] |

[output] | SELECT user_id, COUNT(*) AS num_posts FROM table GROUP BY user_id HAVING COUNT(*) > 5 [instruction] | Write a query to find users who have more than 5 posts in a table. [input] |

[output] | same_elements = [] missing_elements = [] for i in list1: if i in list2: same_elements.append(i) else: missing_elements.append(i) for i in list2: if i not in list1: missing_elements.append(i) print("Same elements:",same_elements) print("Missing elements:",missing_elements) # Outpu [instruction] | Write a Python script to compare two lists and print out missing and same elements. [input] | list1 = [1, 2, 3, 4] list2 = [2, 3, 4, 5]

[output] | for letter in 'abcdefghijklmnopqrstuvwxyz': print(letter) [instruction] | Write a Python script that prints out all of the letters of the alphabet one per line. [input] |

[output] | char_list = list(string) print(char_list) # Output: ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'] [instruction] | Convert a string into list of characters. [input] | string = "Hello World!"

[output] | string = list(string) string[0] = '_' string = ''.join(string) print(string) # Output: _ello World! [instruction] | Write code to replace the first letter of a string with an underscore (_). [input] | string = "Hello World!"

[output] | def character_check(string, character): if character in string: return True else: return False check = character_check(string, character) print(check) # Output: True [instruction] | Detect if a particular character is included in a string or not. [input] | string = "Hello World!" character = '!'

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