Text Generation
Transformers
Safetensors
French
English
Chinese
deepseek_v4
cortex
code-generation
web-development
software-engineering
Mixture of Experts
8-bit precision
fp8
Instructions to use Frankenstein-Labs/Cortex-ai with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Frankenstein-Labs/Cortex-ai with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Frankenstein-Labs/Cortex-ai")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Frankenstein-Labs/Cortex-ai") model = AutoModelForCausalLM.from_pretrained("Frankenstein-Labs/Cortex-ai", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Frankenstein-Labs/Cortex-ai with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Frankenstein-Labs/Cortex-ai" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Frankenstein-Labs/Cortex-ai", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Frankenstein-Labs/Cortex-ai
- SGLang
How to use Frankenstein-Labs/Cortex-ai with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Frankenstein-Labs/Cortex-ai" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Frankenstein-Labs/Cortex-ai", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Frankenstein-Labs/Cortex-ai" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Frankenstein-Labs/Cortex-ai", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Frankenstein-Labs/Cortex-ai with Docker Model Runner:
docker model run hf.co/Frankenstein-Labs/Cortex-ai
File size: 69,677 Bytes
6fbe100 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | {"text": "### Instruction\nCreate an array of length 5 which contains all even numbers between 1 and 10.\n\n### Response\narr = [2, 4, 6, 8, 10]", "source_id": ""}
{"text": "### Instruction\nFormulate an equation to calculate the height of a triangle given the angle, side lengths and opposite side length.\n\n### Response\nHeight of triangle = opposite side length * sin (angle) / side length", "source_id": ""}
{"text": "### Instruction\nWrite a replace method for a string class which replaces the given string with a given set of characters.\n\n### Response\ndef replace(self, replace_with):\n new_string = \"\"\n for char in self:\n if char == \" \":\n new_string += replace_with\n else:\n new_string += char\n return new_string", "source_id": ""}
{"text": "### Instruction\nCreate an array of length 15 containing numbers divisible by 3 up to 45.\n\n### Response\narr = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]", "source_id": ""}
{"text": "### Instruction\nWrite a function to find the number of distinct states in a given matrix.\n\n### Response\ndef find_num_distinct_states(matrix):\n states = set()\n for row in matrix:\n state = \"\".join([str(x) for x in row])\n states.add(state)\n return len(states)", "source_id": ""}
{"text": "### Instruction\nCreate a nested loop to print every combination of numbers between 0-9\n\n### Response\nfor i in range(10):\n for j in range(10):\n print(i, j)", "source_id": ""}
{"text": "### Instruction\nWrite a function to find the maximum difference between two numbers in a given array.\n\n### Response\ndef max_difference(arr):\n max_diff = 0\n for i in range(len(arr)-1):\n diff = arr[i+1] - arr[i]\n if diff > max_diff:\n max_diff = diff\n return max_diff", "source_id": ""}
{"text": "### Instruction\nWrite a function to generate the nth Fibonacci number.\n\n### Response\ndef fib(n):\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fib(n-2) + fib(n-1)", "source_id": ""}
{"text": "### Instruction\nWrite a class to represent a 2D point with x and y coordinates.\n\n### Response\nclass Point:\n def __init__(self, x, y):\n self.x = x \n self.y = y \n \n def __str__(self): \n return \"({0},{1})\".format(self.x, self.y)", "source_id": ""}
{"text": "### Instruction\nWrite code that removes spaces from a given string.\n\n### Response\ndef remove_spaces(string): \n return \"\".join(string.split())", "source_id": ""}
{"text": "### Instruction\nWrite a function that checks if a give number is even or odd.\n\n### Response\ndef is_even(n):\n if n%2 == 0:\n return True \n else:\n return False", "source_id": ""}
{"text": "### Instruction\nWrite code to create a list of all prime numbers between 2 and 100.\n\n### Response\ndef find_primes(n): \n prime_list = [2] \n for number in range(2, n + 1): \n is_prime = True\n for k in range(2, number): \n if number % k == 0: \n is_prime = False \n if is_prime: \n prime_list.append(number) \n return prime_list", "source_id": ""}
{"text": "### Instruction\nEdit the following code to print out all even numbers from 1 to 10.\n\n### Response\nfor i in range(1,11):\n if i % 2 == 0:\n print(i)", "source_id": ""}
{"text": "### Instruction\nWrite code to find the sum of all numbers between 1 and 10.\n\n### Response\nsum = 0\nfor i in range(1,11):\n sum += i\nprint(sum)", "source_id": ""}
{"text": "### Instruction\nCreate a function to calculate the area of a given circle.\n\n### Response\ndef area_circle(radius):\n return 3.14 * (radius**2)", "source_id": ""}
{"text": "### Instruction\nFollow the comments in the code to complete the program which prints a conversion table from Fahrenheit to Celsius.\n\n### Response\n# This program prints a conversion table from Fahrenheit to Celsius\n\n# Print a heading for the table\nprint(\"Fahrenheit to Celsius Conversion Table\")\n\n# Print the column headings\nprint(\"Fahrenheit \\t Celsius\")\n\n# Calculate and print the table body\nfor fahr in range(-50 , 121):\n celsius = (fahr - 32) * 5 / 9\n print(\"%3d \\t\\t %.2f\" % (fahr, celsius))", "source_id": ""}
{"text": "### Instruction\nDevelop a classification algorithm in Python to predict whether a bird is a hawk or a falcon.\n\n### Response\nimport pandas as pd\nimport numpy as np\n\n# Define features\nfeatures = [\"wing_shape\", \"size\", \"tails_length\", \"color_pattern\"] \n\n# Load the data\ndata = pd.read_csv(\"birds.csv\")\n\n# Preprocess the data to generate feature vectors\nX = np.array(data[features]) \n\n# Make a target vector \ny = np.array(data[\"species\"]) \n\n# Divide the data into training and test sets\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Train a classification model\nfrom sklearn.tree import DecisionTreeClassifier\nmodel = DecisionTreeClassifier()\nmodel.fit(X_train, y_train)\n\n# Make predictions\ny_pred = model.predict(X_test)\n\n# Generate evaluation metrics\nfrom sklearn.metrics import accuracy_score\naccuracy = accuracy_score(y_test, y_pred)\n\nprint(\"Model accuracy: %.2f\" % accuracy)", "source_id": ""}
{"text": "### Instruction\nCreate a function in Java for computing the factorial of a positive integer number.\n\n### Response\npublic static long factorial(int n) {\n if (n == 0) {\n return 1;\n }\n long result = 1;\n for (int i = 1; i <= n; i++) {\n result *= i;\n }\n return result;\n}", "source_id": ""}
{"text": "### Instruction\nCreate a C++ program for randomly shuffling an array of integers.\n\n### Response\n#include <iostream>\n#include <algorithm>\n#include <random>\n\nvoid shuffleArray(int array[], int size) {\n\tstd::random_device rd;\n\tstd::mt19937 g(rd()); \n\tstd::shuffle(array, array+size, g); \n}\n\nint main() \n{ \n\tint array[] = {1, 2, 3, 4, 5, 6, 7, 8}; \n\tint size = sizeof(array) / sizeof(array[0]); \n\n // Print original array\n std::cout << \"Original array: \";\n for (int i : array)\n std::cout << i << \" \";\n std::cout << \"\\n\";\n\n // Shuffle array\n\tshuffleArray(array, size); \n\n // Print shuffled array\n std::cout << \"Shuffled array: \";\n for (int i : array)\n std::cout << i << \" \";\n std::cout << \"\\n\";\n\n\treturn 0; \n}", "source_id": ""}
{"text": "### Instruction\nUse the function to debug the given program and prevent the segmentation fault.\n\n### Response\n#include <stdio.h>\n\nint main() {\n int array[] = {1, 2, 3, 4, 5};\n int n = 5;\n int i;\n // Limit loop size to the length of the array\n for (i = 0; i < n; i++) {\n printf(\"%d\\n\", array[i]);\n }\n return 0;\n}", "source_id": ""}
{"text": "### Instruction\nReplace the placeholder with a for loop for iterating over the numbers from 1 to n and printing them.\n\n### Response\nfor i in range(1, n+1):\n print(i)", "source_id": ""}
{"text": "### Instruction\nUse try-except statements to detect and handle exceptions in the code.\n\n### Response\ntry:\n for i in range(n):\n x = 1/i\nexcept ZeroDivisionError:\n print(\"Zero division error encountered!\")", "source_id": ""}
{"text": "### Instruction\nRe-write the code segment as a list comprehension.\n\n### Response\nnumbers = [i for i in range(10) if i % 2 == 0]", "source_id": ""}
{"text": "### Instruction\nRemove the boilerplate code from the program for printing 10 random numbers.\n\n### Response\nimport random\n\n# Generate 10 random numbers\nfor i in range(10):\n print(random.randrange(1, 101))", "source_id": ""}
{"text": "### Instruction\nModify the code to perform the mathematical expression “x to the power of y”.\n\n### Response\n# Calculate x to the power of y\nx_pow_y = x**y", "source_id": ""}
{"text": "### Instruction\nCreate a dictionary for counting the occurrence of each letter in the given string.\n\n### Response\nstring = \"hello world\"\nletter_counts = {}\n\nfor letter in string:\n if letter in letter_counts:\n letter_counts[letter] += 1\n else:\n letter_counts[letter] = 1\n\nprint(letter_counts)", "source_id": ""}
{"text": "### Instruction\nFollow the comments to complete the code that finds the maximum value in an array.\n\n### Response\n# Find the maximum value in an array\narr = [4, 5, 2, 8, 7]\n\nmax_value = arr[0]\nfor i in range(1, len(arr)):\n if arr[i] > max_value:\n max_value = arr[i]\n\nprint(max_value)", "source_id": ""}
{"text": "### Instruction\nWrite a function in HTML for creating a table of n rows and m columns.\n\n### Response\n<table>\n <tbody>\n <% for (let i = 0; i < n; i++) { %>\n <tr>\n <% for (let j = 0; j < m; j++) { %>\n <td>Cell Content</td>\n <% } %>\n </tr>\n <% } %>\n </tbody>\n</table>", "source_id": ""}
{"text": "### Instruction\nCreate a CSS script that centers the login form on the webpage.\n\n### Response\n.login-form {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}", "source_id": ""}
{"text": "### Instruction\nCreate a Java program that prints out the sum of the numbers in the array.\n\n### Response\npublic class SumOfArray {\n public static void main(String[] args) {\n int[] numbers = {1, 2, 3 , 4, 5};\n int sum = 0;\n for(int i=0; i < numbers.length;i++) {\n sum = sum + numbers[i];\n }\n System.out.println(\"The sum of numbers in the given array is: \" + sum);\n }\n}", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to calculate the total number of orders in the \"orders\" table.\n\n### Response\nSELECT COUNT(*) AS \"Total Number of Orders\" \nFROM orders;", "source_id": ""}
{"text": "### Instruction\nWrite a Python function to convert a given string to lowercase.\n\n### Response\ndef to_lowercase(string):\n return string.lower()\n\nstring = \"FOO\"\nprint(to_lowercase(string))", "source_id": ""}
{"text": "### Instruction\nCreate a C program that prints out the Fibonacci sequence.\n\n### Response\n#include <stdio.h>\n\nint main()\n{\n int i, num, first=0, second=1, next;\n printf(\"Enter the number of elements: \");\n scanf(\"%d\", &num);\n printf(\"Fibonacci Series: \");\n for (i = 0; i < num; i++)\n {\n if (i <= 1)\n next = i;\n else\n {\n next = first + second;\n first = second;\n second = next;\n }\n printf(\"%d \", next);\n }\n return 0;\n}", "source_id": ""}
{"text": "### Instruction\nWrite a function in JavaScript to count the number of vowels in a given string.\n\n### Response\nfunction countVowels(string) {\n let vowelCount = 0;\n const vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"];\n \n for (let i = 0; i < string.length; i++) {\n if (vowels.includes(string[i])) {\n vowelCount++;\n }\n }\n \n return vowelCount;\n}\n\nconst string = \"abcdefg\";\nconsole.log(countVowels(string));", "source_id": ""}
{"text": "### Instruction\nCreate a JSX code that renders a \"Hello, World!\" message in the browser.\n\n### Response\nimport React from \"react\";\n\nfunction App() {\n return (\n <div>\n <h1>Hello, World!</h1>\n </div>\n );\n}\n\nexport default App;", "source_id": ""}
{"text": "### Instruction\nWrite an SQL query to calculate the average order price for each product category in the \"orders\" table.\n\n### Response\nSELECT category, AVG(price) as \"Average Order Price\"\nFROM orders\nGROUP BY category;", "source_id": ""}
{"text": "### Instruction\nCreate a Java program that prints out the contents of a given two-dimensional array.\n\n### Response\npublic class TwoDArray {\n\n public static void main(String[] args) {\n int[][] arr = {{1,2},{3,4},{5,6}};\n\n for(int i=0;i<arr.length;i++){\n for(int j=0;j<arr[i].length;j++){\n System.out.print(arr[i][j]+\" \");\n }\n System.out.println();\n }\n }\n}", "source_id": ""}
{"text": "### Instruction\nCreate a C++ program that sorts a given array in descending order.\n\n### Response\n#include<iostream>\nusing namespace std;\n \nint main()\n{\n int array[] = {6, 3, 8, 12, 9, 4};\n int arraySize = sizeof(array)/sizeof(array[0]);\n \n //ascending order sorting\n for(int i = 0; i < arraySize; i++)\n {\n // find the position of smallest element\n int small = i;\n for(int j = i+1; j < arraySize; j++)\n {\n if(array[j] > array[small])\n small = j;\n }\n \n // swap the position of smallest element\n int temp = array[i];\n array[i] = array[small];\n array[small] = temp;\n }\n \n // print the sorted array\n cout << \"Sorted array : \";\n for(int i = 0; i < arraySize; i++)\n cout << array[i] << \" \";\n \n return 0;\n}", "source_id": ""}
{"text": "### Instruction\nEdit the Python code so that it prints out the total number of elements in the list.\n\n### Response\nlist = [1, 2, 3, 4, 5]\nprint(\"Total number of elements in the list: \", len(list))", "source_id": ""}
{"text": "### Instruction\nCreate a Swift code that show the number of days in the given month.\n\n### Response\nlet month = 5\nlet daysEndingInth = [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]\nlet daysInMonth = daysEndingInth[month - 1] \nprint(\"The number of days in the month of \\(month) is \\(daysInMonth).\")", "source_id": ""}
{"text": "### Instruction\nWrite a HTML code that create a form for user to fill out their current address.\n\n### Response\n<form action=\"\">\n <label for=\"street\">Street</label>\n <input type=\"text\" name=\"street\" id=\"street\">\n <label for=\"city\">City</label>\n <input type=\"text\" name=\"city\" id=\"city\">\n <label for=\"state\">State</label>\n <input type=\"text\" name=\"state\" id=\"state\">\n <label for=\"zip\">Zip Code</label>\n <input type=\"text\" name=\"zip\" id=\"zip\"> \n <input type=\"submit\" value=\"Submit\">\n</form>", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to find the total number of orders placed between two given dates.\n\n### Response\nSELECT COUNT(*)\nFROM orders\nWHERE order_date BETWEEN '2020-01-01' AND '2020-02-01';", "source_id": ""}
{"text": "### Instruction\nCreate a Ruby code that prints out the median of a given array of numbers.\n\n### Response\nnums = [1, 7, 3, 6]\nsorted_nums = nums.sort\n\n# Calculation of median \nif sorted_nums.length % 2 == 0\n mid_index = sorted_nums.length/2\n median = (sorted_nums[mid_index] + sorted_nums[mid_index - 1])/2.to_f\nelse\n mid_index = sorted_nums.length/2\n median = sorted_nums[mid_index]\nend\n\nputs median", "source_id": ""}
{"text": "### Instruction\nCreate a PHP code to check if an array contains a given item.\n\n### Response\n<?php\n$input_array = array(1,2,3,4,5);\n$item_to_check = 3;\n\nif(in_array($item_to_check, $input_array)) {\n echo \"Array contains the given item.\";\n} else {\n echo \"Array doesn't contain the given item.\";\n}\n?>", "source_id": ""}
{"text": "### Instruction\nEdit the code to create a try-except block to handle the exception.\n\n### Response\ntry:\n a = 5\n b = 0\n\n ans = a/b\nexcept ZeroDivisionError:\n print(\"Cannot divide by zero.\")", "source_id": ""}
{"text": "### Instruction\nWrite a script using Bash that replaces all vowels with a number.\n\n### Response\n#!/bin/bash\n\nstring=\"Hello World!\"\nvowels=(\"a\" \"e\" \"i\" \"o\" \"u\" \"A\" \"E\" \"I\" \"O\" \"U\")\n\nfor i in \"${vowels[@]}\"\ndo\n string=\"${string//$i/0}\"\ndone\n\necho $string #H0ll0 W0rld!", "source_id": ""}
{"text": "### Instruction\nChange the variable `x` to the data type desired.\n\n### Response\nx = \"Hello World!\"", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes an array as an argument and returns the sum of all the elements in the array.\n\n### Response\ndef arraySum(arr):\n total = 0\n for num in arr:\n total += num\n return total", "source_id": ""}
{"text": "### Instruction\nSort the array in ascending order.\n\n### Response\narr.sort() # [1, 2, 3, 4, 5]", "source_id": ""}
{"text": "### Instruction\nGenerate a random integer between 4 and 8 (inclusively).\n\n### Response\nimport random\nx = random.randint(4, 8)", "source_id": ""}
{"text": "### Instruction\nWrite a list comprehension to square each number in the list.\n\n### Response\narr = [x**2 for x in arr] # [1, 4, 9, 16, 25]", "source_id": ""}
{"text": "### Instruction\nWrite a function that takes a string and reverses the words.\n\n### Response\ndef reverseWords(text):\n return ' '.join(text.split()[::-1])\n\nreverseWords(text) # \"World! Hello\"", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to return the sum of all salaries.\n\n### Response\nSELECT SUM(salary)\nFROM employees;", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes in two numbers as arguments and returns the product of the two.\n\n### Response\ndef multiply(x, y):\n return x*y", "source_id": ""}
{"text": "### Instruction\nSum up the numbers in the array in Javascript.\n\n### Response\nlet sum = arr.reduce((total, num) => total + num);\nconsole.log(sum); // 15", "source_id": ""}
{"text": "### Instruction\nUsing the given function, create a loop that counts from 0 to 9.\n\n### Response\nfor (let i = 0; i < 10; i++){\n printNum(i);\n}", "source_id": ""}
{"text": "### Instruction\nCreate a JSON object with three key-value pairs.\n\n### Response\n{\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"age\": 30\n}", "source_id": ""}
{"text": "### Instruction\nCount the number of characters in the string.\n\n### Response\nlen(text) # 12", "source_id": ""}
{"text": "### Instruction\nGenerate a random number between 0 and 1 (inclusively).\n\n### Response\nMath.random(); // a random number between 0 and 1 (inclusively)", "source_id": ""}
{"text": "### Instruction\nCompose a function named average_list which takes a list of numbers as its argument and computes the average.\n\n### Response\ndef average_list(nums):\n return sum(nums)/len(nums)", "source_id": ""}
{"text": "### Instruction\nGenerate a snippet of code to extract all the URLs from the given string.\n\n### Response\nimport re\n\nstring = \"This string contains some urls such as https://www.google.com and https://www.facebook.com.\"\n\nurls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', string) \n\nprint(urls)", "source_id": ""}
{"text": "### Instruction\nWrite a code to convert a given spredsheet in csv format to json format.\n\n### Response\nimport csv\nimport json\n\ndef csv_to_json():\n # Path of csv file\n file_csv = 'mycsvfile.csv'\n \n # Path of json file\n file_json = 'myjsonfile.json'\n \n with open(file_csv, 'r') as input_file:\n reader = csv.DictReader(input_file)\n data = list(reader)\n \n with open(file_json, 'w') as output_file:\n json.dump(data, output_file)\n\ncsv_to_json()", "source_id": ""}
{"text": "### Instruction\nCreate a list comprehension to generate a list of multiples of 3 from 0 to 23.\n\n### Response\nlist_of_multiples_of_3 = [x*3 for x in range(8)]", "source_id": ""}
{"text": "### Instruction\nDesign a program to find the longest element in the given list.\n\n### Response\ndef longest_element(list):\n max_length = 0\n max_length_item = None\n\n for item in list:\n if len(item) > max_length:\n max_length = len(item)\n max_length_item = item\n\n return max_length_item\n\nlist = [10, 100, 200, 500, 400]\nlongest_element(list) # 500", "source_id": ""}
{"text": "### Instruction\nWrite a function to print all prime numbers between two given numbers.\n\n### Response\ndef print_prime_numbers_in_range(start, end):\n # start = starting number\n # end = ending number\n\n for num in range(start, end+1):\n # Prime numbers are greater than 1\n if num > 1:\n for i in range(2, num):\n if (num % i) == 0:\n break\n else:\n print(num)\n---\n\n11. Instruction: Generate a snippet of code to reverse given string\n11. Input:\n<noinput>\n11. Output:\ndef reverse_string(input_string):\n string_length = len(input_string)\n reversed_string = \"\"\n \n for i in range(string_length-1,-1,-1):\n reversed_string += input_string[i]\n \n return reversed_string", "source_id": ""}
{"text": "### Instruction\nDescribe the basic syntax of a Java function?\n\n### Response\nA Java function consists of a function name, return type, parameters (arguments), and body. The syntax of a Java function is as follows: \npublic <return type> <function name>(<list of parameters>) { \n // function body \n <statements> \n}", "source_id": ""}
{"text": "### Instruction\nHow to reverse a list in C++?\n\n### Response\nYou can reverse a list in C++ using the std::reverse algorithm. To reverse the list, pass the list as the first parameter and the beginning and end of the list as the second and third parameter, respectively. Alternatively, you can also reverse the list using a for loop and the operator [] to access each element of the list.", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to update a value x in a column y in a table z.\n\n### Response\nUPDATE payments \nSET amount = 5 \nWHERE payments.amount IS NOT NULL;", "source_id": ""}
{"text": "### Instruction\nWrite an algorithm in Python to determine if a number is even or odd.\n\n### Response\ndef is_even(num): \n if num % 2 == 0: \n return True \n else: \n return False", "source_id": ""}
{"text": "### Instruction\nWhat is the purpose of a constructor in a class in Java?\n\n### Response\nThe purpose of a constructor in a class in Java is to initialize an object of that class. A constructor is a special kind of method that is used to create an object of its associated class. When an object of the class is created, the constructor is used to set the initial state of the object.", "source_id": ""}
{"text": "### Instruction\nWrite a JavaScript code to get the current browser URL.\n\n### Response\nvar currentURL = window.location.href;\nconsole.log(currentURL);", "source_id": ""}
{"text": "### Instruction\nRewrite the following C++ code using only pointer references instead of array subscripts:\n\n### Response\nint arr[3] = {1,2,3};\nint sum = 0;\nint* ptr = arr;\nfor (int i = 0; i < 3; i++) \n{\n sum += *(ptr+i); \n}", "source_id": ""}
{"text": "### Instruction\nWrite a MySQL query to print the column names of a table named 'employees'.\n\n### Response\nSELECT column_name FROM information_schema.columns WHERE table_name = 'employees';", "source_id": ""}
{"text": "### Instruction\nGenerate a regular expression to match a valid email address.\n\n### Response\n/^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$/", "source_id": ""}
{"text": "### Instruction\nHow to delete a particular row in an SQLite database table?\n\n### Response\nTo delete a particular row in an SQLite database table, you can use the DELETE statement with a WHERE clause to specify the row to be deleted. For example: DELETE FROM table_name WHERE condition;", "source_id": ""}
{"text": "### Instruction\nIs it possible to set a breakpoint that is not associated with any source code line in a GDB program?\n\n### Response\nYes, it is possible to set a breakpoint that is not associated with any source code line in a GDB program. For example, you can set a breakpoint on a function or a memory address. You can do this by using the break command with '*' prefix followed by the address of the breakpoint.", "source_id": ""}
{"text": "### Instruction\nWrite a C++ code to find the average of an array of integers.\n\n### Response\n#include <iostream>\n\nint calculateAverage(int array[], int n){\n int sum = 0; \n for (int i=0; i<n; i++){\n sum += array[i]; \n } \n int average = sum/n;\n return average;\n}", "source_id": ""}
{"text": "### Instruction\nHow can we encrypt a string in Python?\n\n### Response\nWe can encrypt a string in Python using the cryptography module. The cryptography module provides high level cryptographic primitives using the Fernet cipher. The Fernet cipher uses AES-128 in CBC mode and PKCS7 padding to encrypt the string.", "source_id": ""}
{"text": "### Instruction\nWhat is the purpose of declaring a function as static in C++?\n\n### Response\nThe purpose of declaring a function as static in C++ is to restrict its visibility to only the translation unit in which it is declared. A static function can only be called from within the same translation unit and thus, it cannot be accessed from outside of that translation unit.", "source_id": ""}
{"text": "### Instruction\nHow to print the elements of a two-dimensional array in C?\n\n### Response\nWe can use nested loops to print the elements of a two-dimensional array in C. The outer loop iterates over the rows, while the inner loop iterates over the columns. For example, the following code snippet prints the elements of a two-dimensional array: \n \nint array[3][3] = {{1,2,3},{4,5,6},{7,8,9}};\nfor (int i=0; i<3; i++)\n{ \n for(int j=0; j<3; j++) \n {\n printf(\"%d \", array[i][j]); \n }\n printf(\"\\n\");\n}", "source_id": ""}
{"text": "### Instruction\nUsing the following code, clean up the bugs and make sure the output functions correctly.\n\n### Response\ndef example_func(lst):\n output_lst = []\n for element in lst:\n if (type(element) == int):\n output_lst.append(element + 5)\n return output_lst\n \nexample_func([1, 2, \"hello\"])", "source_id": ""}
{"text": "### Instruction\nWrite a C++ function to generate a random integer between 0 and 10.\n\n### Response\n#include <iostream> \n#include <cstdlib> \n#include <ctime> \nusing namespace std; \n\nint randomIntGenerator() \n{ \n // Setting the seed \n srand(time(0)); \n\n // Generating random integer \n return (rand()%11); \n}", "source_id": ""}
{"text": "### Instruction\nCreate a table to store customer information.\n\n### Response\nCREATE TABLE customers (\n id int NOT NULL AUTO_INCREMENT,\n name varchar(100) NOT NULL,\n email varchar(100) NOT NULL,\n phone varchar(20) NOT NULL,\n address varchar(200) NOT NULL,\n PRIMARY KEY (id)\n);", "source_id": ""}
{"text": "### Instruction\nCreate a class in Java named Puppy that has two instance variables, age and name and two methods, bark and sleep.\n\n### Response\npublic class Puppy { \n // Instance Variables \n String name; \n int age; \n \n // Constructor \n public Puppy(String name, int age){ \n this.name = name; \n this.age = age; \n } \n \n // Methods \n public void bark(){ \n System.out.println(\"Woof Woof!\"); \n } \n \n public void sleep(){ \n System.out.println(\"Zzzzzz...\"); \n } \n}", "source_id": ""}
{"text": "### Instruction\nParse the string and return the number of unique alphabets in the string.\n\n### Response\nint count = 0;\nfor (int i = 0; i < StringInput.length(); i++) {\n if ((StringInput.charAt(i) >= 'a' && StringInput.charAt(i) <= 'z') || (StringInput.charAt(i) >= 'A' && StringInput.charAt(i) <= 'Z')) {\n count++;\n }\n}\nSystem.out.println(\"Number of unique alphabets: \" + count);", "source_id": ""}
{"text": "### Instruction\nWrite a shell script to print the top 3 most frequently used commands.\n\n### Response\n#!/bin/bash\n# Store all commands used in the last hour in command_list.\nhistory | tail -$(($(date +%H) * 60)) -n $(($(date +%M)+1)) | cut -d ' ' -f 5 > command_list\n# Create frequency database and store them in frequency.dat\ncat command_list | sort | uniq -c | sort -rn > frequency.dat\n# Print top 3 commands\nhead -3 frequency.dat", "source_id": ""}
{"text": "### Instruction\nRead the JSON string below and convert it into a dictionary.\n\n### Response\nimport json\n\njsonObject = json.loads(jsonString)\ndictionary = dict(jsonObject)\nprint(dictionary)", "source_id": ""}
{"text": "### Instruction\nImplement a function that finds the maximum element in a given array.\n\n### Response\ndef find_max_element(arr): \n max_element = arr[0] \n for index in range(1, len(arr)): \n if arr[index] > max_element: \n max_element = arr[index] \n return max_element\n \narr = [45, 7, 0, 82, 23]\nmax_element = find_max_element(arr) \nprint(max_element)", "source_id": ""}
{"text": "### Instruction\nValidate whether the string contains only alphabets or not.\n\n### Response\ndef check_string_alphabets(myString):\n for character in myString:\n if (not character.isalpha()):\n return False\n return True\n\nmyString = \"abc123\"\nif (check_string_alphabets(myString)):\n print(\"String contains only alphabets\")\nelse:\n print(\"String contains numbers\")", "source_id": ""}
{"text": "### Instruction\nRewrite the following code using ternary operator.\n\n### Response\nnum1 = 5\nnum2 = 10\n\nprint(\"num1 is smaller than num2\") if (num1 < num2) else print(\"num1 is greater than or equal to num2\")", "source_id": ""}
{"text": "### Instruction\nWrite a script to check if a given number is a palindrome or not.\n\n### Response\n# Function to check whether the inputNumber is palindrome or not\ndef is_palindrome(inputNumber):\n\n # negative numbers are not palindrome\n if inputNumber < 0:\n return False\n\n # find the number of digits in the inputNumber\n div = 1\n while (inputNumber / div >= 10):\n div *= 10\n\n # check if the most significant and least significant digits match\n while (inputNumber != 0):\n # compare first and last digits\n firstdigit = inputNumber // div\n lastdigit = inputNumber % 10\n if firstdigit != lastdigit:\n return False\n\n # remove the most and least significant digit of inputNumber\n inputNumber = (inputNumber % div) // 10\n\n # reduce div by a factor of 2, since 2 digits\n # were removed\n div = div // 100\n return True\n\n# Driver code to test above\ninputNumber = 121\nif is_palindrome(inputNumber) :\n print(\"Yes\")\nelse:\n print(\"No\")", "source_id": ""}
{"text": "### Instruction\nEdit the following code to remove the bugs.\n\n### Response\ndef reverse_string(user_string): \n reversed_string = ''\n if len(user_string) == 0: \n return \"\" \n else: \n reversed_string = reverse_string(user_string[1:]) + user_string[0] \n return reversed_string\n\nuser_string = 'test'\nprint(reverse_string(user_string))", "source_id": ""}
{"text": "### Instruction\nWhat is the output of the following code?\n\n### Response\na\nbb\nccc", "source_id": ""}
{"text": "### Instruction\nWrite a function to remove all whitespace characters from a given string.\n\n### Response\ndef remove_whitespaces(myString):\n return ''.join(myString.split())\n\nmyString = \"Hello World \"\nprint(remove_whitespaces(myString))", "source_id": ""}
{"text": "### Instruction\nEdit the following code to add try catch block.\n\n### Response\nx = \"5\"\ny = \"2\"\ntry:\n sum = int(x) + int(y)\n print(\"Sum of x and y is\", sum)\nexcept:\n print(\"Error: Invalid input\")", "source_id": ""}
{"text": "### Instruction\nWrite a Python function that takes two lists of equal length and creates a dictionary of the elements in each list that have the same index.\n\n### Response\ndef list_dict(list_one, list_two):\n \"\"\"Create a dictionary of elements in the two lists which have the same index.\"\"\"\n assert len(list_one) == len(list_two), \"lists must be same length\"\n dict = {}\n for i in range(len(list_one)):\n dict[list_one[i]] = list_two[i]\n return dict", "source_id": ""}
{"text": "### Instruction\nCreate a quick-sort algorithm in Python.\n\n### Response\ndef quick_sort(arr):\n \"\"\"Sort a list of numbers in ascending order using the Quick-Sort algorithm\"\"\"\n if len(arr) == 0:\n return []\n\n pivot = arr[0]\n left_arr = [x for x in arr if x < pivot]\n right_arr = [x for x in arr if x > pivot]\n return quick_sort(left_arr) + [pivot] + quick_sort(right_arr)", "source_id": ""}
{"text": "### Instruction\nDevelop an algorithm to find the value of n where n is the index of the Fibonacci sequence.\n\n### Response\ndef nth_fibonacci_number(n):\n \"\"\"Find the value of n where n is the index of the Fibonacci Sequence.\"\"\" \n if n < 2:\n return n \n elif n == 2:\n return 1\n else:\n return nth_fibonacci_number(n-1) + nth_fibonacci_number(n-2)", "source_id": ""}
{"text": "### Instruction\nCreate a program that finds all the prime numbers less than or equal to a given number.\n\n### Response\ndef find_primes(num):\n \"\"\"Find all the prime numbers less than or equal to a given number.\"\"\"\n primes = []\n for i in range(2, num + 1):\n is_prime = True\n for j in range(2, int(i ** 0.5) + 1):\n if i % j == 0:\n is_prime = False\n break\n if is_prime:\n primes.append(i)\n return primes", "source_id": ""}
{"text": "### Instruction\nWrite a function that takes in a list of numbers and prints out the greatest number.\n\n### Response\ndef find_greatest(list):\n \"\"\"Print out the greatest number from a list of numbers.\"\"\"\n greatest = list[0]\n for num in list:\n if num > greatest:\n greatest = num\n print('The greatest number is: ', greatest)", "source_id": ""}
{"text": "### Instruction\nDesign an algorithm that takes a list of strings and returns the longest string.\n\n### Response\ndef find_longest(list):\n \"\"\"Return the longest string from a list of strings.\"\"\" \n longest = list[0]\n for item in list:\n if len(item) > len(longest):\n longest = item\n return longest", "source_id": ""}
{"text": "### Instruction\nWrite a function that takes in a matrix of numbers and reverses the order of the rows and columns.\n\n### Response\ndef reverse_matrix(matrix):\n \"\"\"Reverse the order of the rows and columns in a matrix of numbers.\"\"\"\n reversed_matrix = [[0 for i in range(len(matrix[0]))] for j in range(len(matrix))]\n for i in range(len(matrix)):\n for j in range(len(matrix[i])):\n reversed_matrix[j][i] = matrix[i][j]\n return reversed_matrix", "source_id": ""}
{"text": "### Instruction\nDesign an algorithm that creates a random password of 8 characters.\n\n### Response\ndef generate_password():\n \"\"\"Generate a random password of 8 characters.\"\"\"\n import random\n chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()'\n password = ''\n for i in range(8):\n password += random.SystemRandom().choice(chars)\n return password", "source_id": ""}
{"text": "### Instruction\nFOr a given list, create a program that prints out the standard deviation of the elements in the list.\n\n### Response\ndef std_dev(list):\n \"\"\"Print the standard deviation of elements in a given list.\"\"\"\n numerator = 0\n mean = sum(list) / len(list)\n for num in list:\n numerator += (num - mean) ** 2\n sd = (numerator / (len(list) - 1)) ** 0.5\n return sd", "source_id": ""}
{"text": "### Instruction\nCreate a program that can filter out words of a string that contain a specific character.\n\n### Response\ndef filter_string(string, character):\n \"\"\"Filter out words of a string that contain a specific character.\"\"\"\n words = string.split(' ')\n filtered_words = []\n for word in words:\n if character not in word:\n filtered_words.append(word)\n return ' '.join(filtered_words)", "source_id": ""}
{"text": "### Instruction\nCreate a program that can calculate the distance between two points in three-dimensional space.\n\n### Response\ndef dist_points_3d(point1, point2):\n \"\"\"Calculate the distance between two points in three-dimensional space.\"\"\"\n distance = ((point1[0] - point2[0]) ** 2 + \n (point1[1] - point2[1]) ** 2 + \n (point1[2] - point2[2]) ** 2) ** 0.5\n return distance", "source_id": ""}
{"text": "### Instruction\nCreate a program that ciphers a given text using the caesar cipher.\n\n### Response\ndef caesar_cipher(text, key):\n \"\"\"Cipher a given text using the Caesar Cipher.\"\"\"\n ciphertext = \"\"\n for char in text: \n if not char.isalpha():\n ciphertext += char\n continue\n offset = ord('a') if char.islower() else ord('A')\n new_char = (ord(char) - offset + key) % 26\n ciphertext += chr(offset + new_char)\n return ciphertext", "source_id": ""}
{"text": "### Instruction\nFind the second smallest element in an integer array of size n.\n\n### Response\ndef second_smallest(array):\n\nsmallest = min(array)\nsecond_smallest = float('inf')\n\nfor num in array:\n if num > smallest and num < second_smallest:\n second_smallest = num\n \nreturn second_smallest", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to find all the users in a database with age greater than 25.\n\n### Response\nSELECT * FROM users WHERE age > 25", "source_id": ""}
{"text": "### Instruction\nCreate a function to calculate the maximum of two numbers.\n\n### Response\ndef max_of_two(x, y):\n if x > y:\n return x\n else:\n return y", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to split a string on a given character separator.\n\n### Response\ndef split(mystring, separator):\n return mystring.split(separator)", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to get the day of week from a given date and time.\n\n### Response\nfrom datetime import datetime\n\ndef get_day_of_week(date):\n return date.strftime(\"%A\")", "source_id": ""}
{"text": "### Instruction\nWrite a Javascript function to determine if the given number is an even number or not.\n\n### Response\nfunction isEven(num) {\nreturn num % 2 === 0;\n}", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to print out an ASCII art of a given word.\n\n### Response\ndef draw_word(word):\n art = \"\"\"\n __\n _ / \\\\\n \\\\_/\\_/\\_/\n / |\n \\___/\n \\\\\\\\_//\n \\/ \\/\n \\/\n \"\"\"\n for letter in word:\n art += \" \" + letter\n print(art)", "source_id": ""}
{"text": "### Instruction\nWrite a JavaScript function to validate a given URL.\n\n### Response\nfunction isValidURL(url) {\n const regex = /^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$/;\n return regex.test(url);\n}", "source_id": ""}
{"text": "### Instruction\nWrite a C# program to find the maximum and minimum of three numbers.\n\n### Response\npublic void Maximum_Minimum(int num1, int num2, int num3)\n{\n int max = Math.Max(Math.Max(num1, num2),num3);\n int min = Math.Min(Math.Min(num1,num2),num3);\n Console.WriteLine(\"Maximum Number is : \" + max);\n Console.WriteLine(\"Minimum Number is : \" + min);\n}", "source_id": ""}
{"text": "### Instruction\nWrite a Java program to reverse a given string.\n\n### Response\npublic class ReverseString\n{ \n\n public static void main(String[] args) \n { \n String input = \"Hello\"; \n StringBuilder input1 = new StringBuilder(); \n \n // append a string into StringBuilder input1 \n input1.append(input); \n \n // reverse StringBuilder input1 \n input1 = input1.reverse(); \n \n // print reversed String \n System.out.println(input1); \n } \n}", "source_id": ""}
{"text": "### Instruction\nWrite an HTML template to display a greeting message. The message should include the name of the user who visits the website.\n\n### Response\n<html>\n\t<head>\n\t\t<title>Greeting Message</title>\n\t</head>\n\t<body>\n\t\t<h1>Hello, {{ username }}!</h1>\n\t</body>\n</html>", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to concatenate all elements in a list into a string separated by a given separator.\n\n### Response\ndef list_to_string(input_list, separator):\n return separator.join(input_list)", "source_id": ""}
{"text": "### Instruction\nWrite a C program to find the sum of all digits of a given number\n\n### Response\n#include <stdio.h>\n\nint getSumOfDigits(int num) {\n // Initialize sum\n int sum = 0;\n\n // Find the sum of digits\n while(num > 0) {\n sum += num % 10;\n num /= 10;\n }\n\n return sum;\n}\n\nint main() {\n int num;\n scanf(\"%d\", &num);\n\n printf(\"Sum of digits of %d is %d\\n\", num, getSumOfDigits(num));\n\n return 0;\n}", "source_id": ""}
{"text": "### Instruction\nWrite a Java program to generate random numbers\n\n### Response\nimport java.util.Random; \n \npublic class GenerateRandom { \n \n public static void main(String[] args) \n { \n \n Random rand = new Random(); \n \n // Generate random integers in range 0 to 999 \n int x = rand.nextInt(1000); \n System.out.println(\"Random Integers: \" + x); \n \n // Generate Random doubles \n double y = rand.nextDouble(); \n System.out.println(\"Random Doubles: \" + y); \n \n // Generate Random Boolean \n boolean z = rand.nextBoolean(); \n System.out.println(\"Random Boolean: \" + z); \n } \n}", "source_id": ""}
{"text": "### Instruction\nRewrite the following Python code using a for-loop.\n\n### Response\nfor i in range(11):\n print(i)", "source_id": ""}
{"text": "### Instruction\nWrite a code to print the current date and time in ISO format.\n\n### Response\nfrom datetime import datetime\n\ndate_time_obj = datetime.now()\n\nprint(date_time_obj.isoformat()) # prints \"2020-07-29T15:10:01.584131\"", "source_id": ""}
{"text": "### Instruction\nCreate a new folder called 'data' within the current working directory.\n\n### Response\nimport os\n\n# create 'data' folder in the current working directory\ncurrent_directory = os.getcwd()\nnew_directory = os.path.join(current_directory, 'data')\nos.mkdir(new_directory)", "source_id": ""}
{"text": "### Instruction\nWrite a code to sort the following array in increasing order.\n\n### Response\n# sorting array using insertion sort\narr = [10, 2, 7, 8, 32, 4] \n\n# traverse through all array elements \nfor i in range(1, len(arr)):\n key = arr[i]\n\n # move elements of arr[0..i-1], that are greater than key,\n # to one position ahead of their current position\n j = i-1\n while j >= 0 and key < arr[j] : \n arr[j + 1] = arr[j] \n j -= 1\n arr[j + 1] = key\n \n#print the sorted array\nprint(arr)", "source_id": ""}
{"text": "### Instruction\nCreate a function in JavaScript that takes an array of integers and returns the largest number.\n\n### Response\nfunction findMax(arr) {\n let max = arr[0];\n for (let i = 1; i < arr.length; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n return max;\n}", "source_id": ""}
{"text": "### Instruction\nCreate a regular expression to validate a URL string.\n\n### Response\n# Regular expression to validate a URL string\n^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/)?(www\\.)?([a-zA-Z0-9]+(-?[a-zA-Z0-9])*\\.)+[\\w]{2,5}(\\/\\S*)?$", "source_id": ""}
{"text": "### Instruction\nWrite a Python code to calculate the mean of a given array.\n\n### Response\n# calculate the mean of given array\narr = [1,2,3,4]\n\ndef calc_mean(arr):\n sum = 0\n for num in arr:\n sum += num\n return sum / len(arr)\n\nprint(calc_mean(arr)) # prints 2.5", "source_id": ""}
{"text": "### Instruction\nCreate a function in Java that takes a string and prints the reversed version.\n\n### Response\npublic static void reverseString(String str) { \n StringBuilder sb = new StringBuilder(); \n \n for (int i = str.length() - 1; i >= 0; i--) { \n sb.append(str.charAt(i)); \n } \n \n System.out.print(sb.toString()); \n}", "source_id": ""}
{"text": "### Instruction\nWrite a code to get the time difference between two date-time objects.\n\n### Response\nfrom datetime import datetime\n\ndef time_difference(date1, date2):\n date1_obj = datetime.strptime(date1, '%Y-%m-%d %H:%M:%S')\n date2_obj = datetime.strptime(date2, '%Y-%m-%d %H:%M:%S')\n\n return (date2_obj - date1_obj).total_seconds() // 3600\n\nprint(time_difference('2019-05-11 21:00:00', '2019-05-13 10:00:00')) # prints 33.0", "source_id": ""}
{"text": "### Instruction\nWrite a code to connect to a remote database.\n\n### Response\nimport psycopg2\n\nconn = psycopg2.connect(host=\"100.10.0.10\", database=\"mydb\", user=\"john\", password=\"john123\")", "source_id": ""}
{"text": "### Instruction\nCreate an HTML form with a textbox, a submit button, and two radio buttons.\n\n### Response\n<form>\n <input type=\"text\" id=\"textbox\">\n <input type=\"submit\" value=\"Submit\">\n <input type=\"radio\" name=\"choice\" value=\"yes\">Yes\n <input type=\"radio\" name=\"choice\" value=\"no\">No\n</form>", "source_id": ""}
{"text": "### Instruction\nWrite a code to access the nth element of a linked list.\n\n### Response\n# defining the Node class\nclass Node: \n\tdef __init__(self, data): \n\t\tself.data = data \n\t\tself.next = None\n\ndef getNthElement(head, n): \n\tcurrent = head \n\tcount = 0\n\n\t# looping through the linked list\n\twhile(current is not None): \n\t\tif (count == n): \n\t\t\treturn current.data \n\t\tcount += 1\n\t\tcurrent = current.next\n\treturn -1", "source_id": ""}
{"text": "### Instruction\nCreate a function in JavaScript to find the number of occurrences of a letter in a word.\n\n### Response\nfunction findOccurrences(word, letter) {\n let count = 0;\n for (let i = 0; i < word.length; i++) {\n if (word.charAt(i) === letter) {\n count++;\n }\n }\n return count;\n}", "source_id": ""}
{"text": "### Instruction\nWrite a code to add two linked lists of different sizes.\n\n### Response\n# adding two linked lists\nclass Node: \n\tdef __init__(self, data): \n\t\tself.data = data \n\t\tself.next = None\n\ndef addTwoLists(first, second):\n # defining current and prev variables\n prev = None\n carry = 0\n temp = None\n\n # looping until one list has all nodes added\n while(first is not None or second is not None): \n Node = Node() \t\t# Node data\n\n Node.data = carry + (first.data if first else 0) + (second.data if second else 0) \n\t\t\n # update carry\n if Node.data >= 10: \n Node.data = Node.data % 10\n carry = 1\n else: \n carry = 0\n \n temp = Node\n # Move first, second pointers ahead\n if first is not None: \n first = first.next\n if second is not None: \n second = second.next\n\n # Attach the previous node to the current node\n if prev is not None: \n prev.next = Node \n prev = Node\n\t\t\n if carry > 0: \n temp.next = Node \n temp.data = carry \n return result", "source_id": ""}
{"text": "### Instruction\nCreate a function in Java to convert a list of strings to a 2D array.\n\n### Response\npublic static String[][] convertTo2DArray(List<String> strings) {\n int n = strings.size();\n String[][] array = new String[n][1];\n for (int i = 0; i < n; i++) {\n array[i][0] = strings.get(i);\n }\n return array;\n \n}", "source_id": ""}
{"text": "### Instruction\nModify the code below to make it calculate the sum of all the numbers from 1 to n.\n\n### Response\nnum = 5\nsum = 0\nfor i in range(1, num+1):\n sum += i", "source_id": ""}
{"text": "### Instruction\nCreate a program to generate a histogram using data from a set of numbers.\n\n### Response\nimport matplotlib.pyplot as plt\n\nvalues = [3, 4, 2, 5, 8, 1, 2, 6]\n\nplt.hist(values, bins= 10, edgecolor='black', color='b')\n\nplt.xlabel('Values')\nplt.ylabel('Frequency')\n\nplt.title('Histogram')\n\nplt.show()", "source_id": ""}
{"text": "### Instruction\nCreate a function to convert Celsius to Fahrenheit.\n\n### Response\ndef celsius_to_fahrenheit(c):\n f = c * (9/5) + 32\n return f", "source_id": ""}
{"text": "### Instruction\nWrite a function to find the number of occurrences of an element in a list.\n\n### Response\ndef count_occurrences(arr, element):\n count = 0\n for e in arr:\n if e == element:\n count += 1\n return count\n\nprint(count_occurrences(arr, 40)) # Outputs: 3", "source_id": ""}
{"text": "### Instruction\nWrite a JavaScript code snippet to print the numbers from 1 to 10.\n\n### Response\nfor (let i = 1; i <= 10; i++) {\n console.log(i);\n}", "source_id": ""}
{"text": "### Instruction\nGenerate a dictionary of 10 key-value pairs, where the key is a string and the values are random numbers from 1 to 100.\n\n### Response\nimport random\n\nd = dict()\n\nkeys = [\"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\"]\n\nfor key in keys:\n d[key] = random.randint(1,100)\n\nprint(d)", "source_id": ""}
{"text": "### Instruction\nCreate a JavaScript function which takes a string as a parameter and returns the most frequent character in the string.\n\n### Response\nfunction mostFrequentChar(string) {\n let charMap = {};\n let maxCount = 0;\n let freqChar = '';\n \n for (let char of string) {\n if (charMap[char]) {\n charMap[char]++;\n } else {\n charMap[char] = 1;\n }\n }\n \n for (let char in charMap) {\n if (charMap[char] > maxCount) {\n maxCount = charMap[char];\n freqChar = char;\n }\n }\n \n return freqChar;\n}", "source_id": ""}
{"text": "### Instruction\nWrite a C# function which takes 2 strings as parameters and returns a new string which is a concatenation of the two parameters.\n\n### Response\nstring ConcatenateStrings(string str1, string str2)\n{\n return str1 + str2;\n}", "source_id": ""}
{"text": "### Instruction\nCreate an HTML page where the main content area has a random background color when the page is loaded.\n\n### Response\n<!DOCTYPE html>\n<html>\n <head>\n <title>RandomBackground</title>\n <script>\n window.addEventListener(\"load\",function(){\n var randomColor = \"#\"+((1<<24)*Math.random()|0).toString(16);\n document.querySelector(\"body\").style.background = randomColor;\n });\n </script>\n </head>\n <body>\n </body>\n</html>", "source_id": ""}
{"text": "### Instruction\nCreate a Java program which takes an integer array as a parameter, sorts the array in ascending order, and returns the sorted array.\n\n### Response\npublic int[] SortIntegerArray(int[] nums)\n{\n Arrays.sort(nums);\n return nums;\n}", "source_id": ""}
{"text": "### Instruction\nWrite an SQL query to select the number of employees in each department, sorted by the department name in ascending order.\n\n### Response\nSELECT department, COUNT(employee_ID)\nFROM employees\nGROUP BY department\nORDER BY department ASC;", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to remove all instances of a given value from a given list.\n\n### Response\ndef remove_value(nums, val):\n res = []\n for num in nums:\n if num != val:\n res.append(num)\n return res", "source_id": ""}
{"text": "### Instruction\nCreate a Java program to take a given string and replace all occurrences of a given letter with another given letter\n\n### Response\npublic String ReplaceLetters(String str, char oldChar, char newChar) {\n return str.replace(oldChar, newChar);\n}", "source_id": ""}
{"text": "### Instruction\nWrite an SQL query to calculate the average salary of all employees in a table, rounded to the nearest integer.\n\n### Response\nSELECT ROUND(AVG(salary))\nFROM employees;", "source_id": ""}
{"text": "### Instruction\nCreate a JavaScript function that takes a given sentence as a parameter and capitalizes the first letter of each word.\n\n### Response\nfunction capitalizeSentence(str) {\n let words = str.split(' ');\n let res = [];\n \n for (let word of words) {\n res.push(word[0].toUpperCase() + word.slice(1));\n }\n \n return res.join(' ');\n}", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to generate the first n Fibonacci numbers.\n\n### Response\ndef generate_fibonacci_numbers(n):\n if n==1:\n return [0]\n elif n==2:\n return [0,1]\n else:\n fib_list = [0,1]\n for i in range(2,n):\n fib_list.append(fib_list[i-1]+fib_list[i-2])\n return fib_list", "source_id": ""}
{"text": "### Instruction\nCreate a C# program which takes two strings as parameters, and returns true if the two strings are anagrams of each other.\n\n### Response\nbool AreAnagrams(string s1, string s2)\n{\n if (s1.Length != s2.Length)\n return false;\n \n int[] a = new int[256];\n int n = s1.Length;\n for (int i = 0; i < n; i++)\n {\n int c1 = (int)s1[i];\n int c2 = (int)s2[i];\n \n a[c1]++;\n a[c2]--;\n }\n \n for (int i = 0; i < 256; i++)\n {\n if (a[i] != 0)\n return false;\n }\n \n return true;\n}", "source_id": ""}
{"text": "### Instruction\nWrite an SQL query to calculate the difference between the total salaries of male and female employees in a table.\n\n### Response\nSELECT SUM(CASE WHEN gender = 'female' THEN salary ELSE 0 END) - SUM(CASE WHEN gender = 'male' THEN salary ELSE 0 END)\nFROM employees;", "source_id": ""}
{"text": "### Instruction\nCreate a JavaScript program which takes an array of integers as a parameter and reverses the array in-place.\n\n### Response\nfunction reverseArrayInPlace(nums) {\n let left = 0;\n let right = nums.length - 1;\n \n while (left < right) {\n let temp = nums[left];\n nums[left] = nums[right];\n nums[right] = temp;\n \n left++;\n right--;\n }\n return nums;\n}", "source_id": ""}
{"text": "### Instruction\nExplain what the following line of code does.\n\n### Response\nThis line of code assigns the remainder of a divided by b to a, so that the resulting value of a is the remainder of a divided by b. For example, if a is 10 and b is 3, the value of a after executing this line of code would be 1 (the remainder of 10 divided by 3).", "source_id": ""}
{"text": "### Instruction\nConstruct an if-else statement that returns ‘even’ if the given number is even and ‘odd’ if the given number is odd.\n\n### Response\nif n % 2 == 0:\n return 'even'\nelse:\n return 'odd'", "source_id": ""}
{"text": "### Instruction\nMultiply two vectors of size 5 and return the output.\n\n### Response\n[5, 8, 9, 8, 5]", "source_id": ""}
{"text": "### Instruction\nCreate a list comprehension that takes all the elements of list_one and creates a new list where all the elements are doubled.\n\n### Response\n[x*2 for x in list_one]", "source_id": ""}
{"text": "### Instruction\nYou are given a matrix of m rows and n columns. Write a function that calculates the transpose of the given matrix.\n\n### Response\ndef transpose(matrix):\n m = len(matrix)\n n = len(matrix[0])\n\n transpose_matrix = [[0] * m for _ in range(n)]\n for i in range(m):\n for j in range(n):\n transpose_matrix[j][i] = matrix[i][j]\n\n return transpose_matrix", "source_id": ""}
{"text": "### Instruction\nGiven a list of numbers, print the difference between the largest and the smallest number.\n\n### Response\ndifference = max(list_of_numbers) - min(list_of_numbers)\nprint(difference)", "source_id": ""}
{"text": "### Instruction\nCreate a for loop that goes through every element of list_of_words and prints ‘success’ if an element is equal to “example” and prints ‘failure’ in any other case.\n\n### Response\nfor word in list_of_words:\n if word == \"example\":\n print(\"success\")\n else:\n print(\"failure\")", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes in a list of temperatures and returns the average temperature\n\n### Response\ndef average_temperature(temperatures):\n num_items = len(temperatures)\n sum_items = 0\n for temperature in temperatures:\n sum_items += temperature\n return sum_items / num_items", "source_id": ""}
{"text": "### Instruction\nYou are given a list of numbers. Create a function that returns a new list with duplicates removed\n\n### Response\ndef remove_duplicates(numbers):\n new_list = []\n for num in numbers:\n if num not in new_list:\n new_list.append(num)\n return new_list", "source_id": ""}
{"text": "### Instruction\nIn a given string, create a function that returns the longest consecutive sequence of characters.\n\n### Response\ndef longest_consecutive(string):\n character_list = []\n max_length = 0\n max_sequence = ''\n for char in string:\n if char in character_list:\n continue\n else:\n character_list.append(char)\n current_length = 1\n for i in range(1, len(string)):\n if string[i-1] == char and string[i] == char:\n current_length += 1\n if current_length>max_length:\n max_length = current_length\n max_sequence = char*max_length\n return max_sequence", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes in a string and counts the number of vowels in it\n\n### Response\ndef count_vowels(string):\n vowels = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n count = 0\n for char in string:\n if char in vowels:\n count += 1\n return count", "source_id": ""}
{"text": "### Instruction\nWrite a function that takes in a string and returns a list of all the words that have more than 5 characters\n\n### Response\ndef long_words(string):\n words = string.split()\n long_words_list = []\n for word in words:\n if len(word) > 5:\n long_words_list.append(word)\n return long_words_list", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes in a string and replaces all punctuation with a space\n\n### Response\nimport string\n\ndef replace_punctuation(string):\n for char in string:\n if char in string.punctuation:\n string = string.replace(char, \" \")\n return string", "source_id": ""}
{"text": "### Instruction\nCreate a function that takes in a list of numbers and returns true if the list contains at least one positive number\n\n### Response\ndef is_positive_number(numbers):\n for num in numbers:\n if num > 0:\n return True\n return False", "source_id": ""}
{"text": "### Instruction\nWrite code in Java to generate the Fibonacci sequence up to N numbers.\n\n### Response\npublic class Fibonacci { \n \n public static void FibonacciN(int n) { \n int i, f=0, s=1; \n \n if (n == 1) \n System.out.print(f+ \" \"); \n \n else { \n System.out.print(f+\" \"+s+\" \"); \n \n for (i = 2; i < n; i++) { \n int next = f + s; \n System.out.print(next+\" \"); \n f= s; \n s = next; \n } \n } \n } \n}", "source_id": ""}
{"text": "### Instruction\nWrite an algorithm to find the largest element in an array.\n\n### Response\n// Algorithm to find the largest element in an array\n\n// Step 1: Create a variable 'max' and initialize it with value of the first element in the array\nint max = arr[0];\n\n// Step 2: Iterate through the array and compare each element with 'max'\nfor (int i = 1; i < arr.length; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n}\n\n// Step 3: Return the value of 'max'\nreturn max;", "source_id": ""}
{"text": "### Instruction\nWrite code in Java to sort an array of integers in ascending order.\n\n### Response\npublic static void sortAscending(int[] arr) {\n for(int i = 0; i < arr.length - 1; i++) {\n int min = i;\n for (int j = i + 1; j < arr.length; j++) {\n if (arr[j] < arr[min]) {\n min = j;\n }\n }\n int tmp = arr[i];\n arr[i] = arr[min];\n arr[min] = tmp;\n }\n}", "source_id": ""}
{"text": "### Instruction\nCreate a new button using HTML.\n\n### Response\n<button>My Button</button>", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to add a new column \"age\" in the employees table.\n\n### Response\nALTER TABLE Employees\nADD COLUMN age INT;", "source_id": ""}
{"text": "### Instruction\nDesign a function in Python to delete duplicates from a list.\n\n### Response\ndef remove_duplicates(list): \n \n unique_list = [] \n \n for x in list: \n if x not in unique_list: \n unique_list.append(x) \n return unique_list \n \nlist = [2, 3, 2, 4, 5, 5, 6] \nprint (\"Original List: \", list) \nprint (\"Unique List: \", remove_duplicates(list)) \n\nOutput: \nOriginal List: [2, 3, 2, 4, 5, 5, 6]\nUnique List: [2, 3, 4, 5, 6]", "source_id": ""}
{"text": "### Instruction\nImplement an algorithm to find the sum of all the elements in an array.\n\n### Response\n// Algorithm to calculate the sum of all the elements in an array\n\n// Step 1: Initialize a variable 'sum' and set it equal to 0\nint sum = 0;\n\n// Step 2: Iterate through the array and add each element to 'sum'\nfor (int i = 0; i < arr.length; i++) {\n sum += arr[i];\n}\n\n// Step 3: Return the value of sum\nreturn sum;", "source_id": ""}
{"text": "### Instruction\nWrite a MySQL query to display the name, job and salary of all employees.\n\n### Response\nSELECT name, job, salary \nFROM employees;", "source_id": ""}
{"text": "### Instruction\nFind the sum of two numbers using C#.\n\n### Response\nint result = 123 + 456;\nConsole.WriteLine(result); //Output: 579", "source_id": ""}
{"text": "### Instruction\nCreate a web page using HTML and CSS that displays a div with some text.\n\n### Response\n<html>\n <head>\n <title>Div Example</title>\n </head>\n <body>\n <div>Hello, welcome to my website!</div>\n </body>\n</html>", "source_id": ""}
{"text": "### Instruction\nWrite a JavaScript function to capitalize the first letter of each word in a string.\n\n### Response\nfunction capitalizeFirstLetter(str) {\n return str.replace(/\\w\\S*/g, function(txt) {\n return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n });\n}\ncapitalizeFirstLetter('This is an example');", "source_id": ""}
{"text": "### Instruction\nWrite a Python program to loop through all the items in a given list.\n\n### Response\nmy_list = [1, 2, 3, 4, 5, 6]\nfor item in my_list:\n print(item)", "source_id": ""}
{"text": "### Instruction\nWrite a SQL query to select the name and address from a given table.\n\n### Response\nSELECT name, address FROM Employee", "source_id": ""}
{"text": "### Instruction\nCreate a new CSS animation rule to rotate an object a full circle.\n\n### Response\n@keyframes rotate {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}", "source_id": ""}
{"text": "### Instruction\nWrite a PL/SQL program to print out all numbers from 1 to 10.\n\n### Response\nBEGIN\n FOR i IN 1..10 LOOP\n DBMS_OUTPUT.PUT_LINE(i);\n END LOOP;\nEND;", "source_id": ""}
{"text": "### Instruction\nWrite a JavaScript code snippet to remove the last element from an array.\n\n### Response\nlet array = [1, 2, 3, 4, 5];\narray.pop(); // remove the last element\nconsole.log(array); // [1, 2, 3, 4]", "source_id": ""}
{"text": "### Instruction\nConvert the following binary number to a decimal number.\n\n### Response\n19 (10011 = 2^4 + 2^3 + 2^1 = 16 + 8 + 1 = 25)", "source_id": ""}
{"text": "### Instruction\nWrite a Java program to calculate the sum of the two given integers.\n\n### Response\npublic static int addIntegers(int a, int b) {\n int sum = a + b;\n return sum;\n}\n\npublic static void main(String[] args) {\n int x = 4, y = 9;\n int sum = addIntegers(x, y);\n System.out.println(\"Sum is: \"+sum);\n}", "source_id": ""}
{"text": "### Instruction\nWhat is the largest prime factor of the number 885?\n\n### Response\nThe largest prime factor of 885 is 5.", "source_id": ""}
{"text": "### Instruction\nCreate a function in Python which takes two parameters and returns their product.\n\n### Response\ndef product(a, b):\n return a*b", "source_id": ""}
{"text": "### Instruction\nConstruct a for loop that prints out the numbers from 1 to 10\n\n### Response\nfor i in range(1, 11):\n print(i)", "source_id": ""}
{"text": "### Instruction\nCreate an HTML form with three input fields: firstName, lastName and age.\n\n### Response\n<form> \n First Name:<br> \n <input type=\"text\" name=\"firstName\"><br> \n Last Name:<br> \n <input type=\"text\" name=\"lastName\"><br> \n Age:<br> \n <input type=\"number\" name=\"age\"><br><br> \n <input type=\"submit\" value=\"Submit\"> \n</form>", "source_id": ""}
{"text": "### Instruction\nWrite a function in Java that takes two strings as parameters and returns true if the first string is a substring of the second.\n\n### Response\npublic boolean isSubstring(String s1, String s2) \n{ \n int M = s1.length(); \n int N = s2.length(); \n \n for (int i = 0; i <= N - M; i++) { \n int j; \n \n for (j = 0; j < M; j++) \n if (s2.charAt(i + j) != s1.charAt(j)) \n break; \n \n if (j == M) \n return true; \n } \n \n return false; \n}", "source_id": ""}
{"text": "### Instruction\nConstruct a while loop that increments a counter every time a number is divisible by 3.\n\n### Response\nint count = 0; \nint i = 0; \nwhile(i < 100)\n{\n if(i % 3 == 0)\n count++; \n i++;\n}", "source_id": ""}
{"text": "### Instruction\nCreate a Regular Expression pattern to find words that contain the letters \"a\", \"b\", and \"c\".\n\n### Response\n\\b[abc]+\\w*\\b", "source_id": ""}
{"text": "### Instruction\nCreate a class in Python to represent a Person.\n\n### Response\nclass Person:\n # Constructor \n def __init__(self, name, age): \n \n # instance attributes \n self.name = name \n self.age = age \n \n # instance method \n def greeting(self): \n print(\"My name is\", self.name) \n \n# construct an object \nperson1 = Person(\"John\", 36) \n \n# call a method of the object \nperson1.greeting()", "source_id": ""}
{"text": "### Instruction\nWrite a code to check whether the input string is a palindrome or not.\n\n### Response\n\"\"\"\nWrite a code to check whether the input string is a palindrome or not\n\"\"\"\n\ndef check_palindrome(input_string):\n rev_str = input_string[::-1]\n \n # Checking if both string are equal or not\n if rev_str == input_string:\n return True\n return False\n \n# main function\nif __name__ == \"__main__\":\n str = \"a man a plan a canal panama\"\n if check_palindrome(str):\n print(\"String is Palindrome\")\n else:\n print(\"String is not Palindrome\")", "source_id": ""}
{"text": "### Instruction\nWrite a code to remove the duplicates from a given list.\n\n### Response\n\"\"\"\nWrite a code to remove the duplicates from a given list\n\"\"\"\n\n# List containing the elements\nmylist = [1,2,3,1,2]\n\n# Creating a new list with unique elements\nunique_list = list(set(mylist))\n\n# Printing the new list\nprint(\"New list with unique elements is {}\".format(unique_list))", "source_id": ""}
{"text": "### Instruction\nCreate a dictionary containing the key-value pair of a given string.\n\n### Response\n\"\"\"\nCreate a dictionary containing the key-value pair of a given string\n\"\"\"\n\n# Given string\nstring = \"test string\"\n\n# Initialising an empty dictionary\nmy_dict = {}\n\n# Looping through the given string\nfor char in string:\n # If the character is not already in dictionary\n if char not in my_dict:\n # Adding the character to the dictionary\n my_dict[char] = 1\n # If the character already exists in dictionary\n else:\n # Incrementing the frequency\n my_dict[char] += 1\n \n# Printing the dictionary\nprint(my_dict)", "source_id": ""}
{"text": "### Instruction\nWrite a code to generate a random number between 1 to 10.\n\n### Response\n\"\"\"\nWrite a code to generate a random number between 1 to 10\n\"\"\"\n\nimport random\n\n# Generate random number between 1 to 10 \nrandom_number = random.randint(1,10)\n\n# Printing the random number\nprint(random_number)", "source_id": ""}
{"text": "### Instruction\nWrite a code to create a 3 x 3 matrix containing all 0s.\n\n### Response\n\"\"\"\nWrite a code to create a 3 x 3 matrix containing all 0s\n\"\"\"\n\n# Creating an empty 3 x 3 matrix\nmatrix = [[0 for x in range(3)] for y in range(3)] \n \n# Printing the matrix\nprint(matrix)", "source_id": ""}
|