lua_code_dataset / data.json
tfcbhop's picture
Added data to data.json
1c9c9bf verified
raw
history blame
No virus
2.27 kB
[
{
"instruction": "Write a Lua function that calculates the Fibonacci sequence up to a given number n.",
"input": "Generate Fibonacci sequence up to n=10.",
"output": "function fibonacci(n)\n local fib = {0, 1}\n for i = 3, n do\n fib[i] = fib[i - 1] + fib[i - 2]\n end\n return fib\nend\n\nprint(table.concat(fibonacci(10), ', '))"
},
{
"instruction": "Write a Python function to check if a given string is a palindrome.",
"input": "Check if the string 'radar' is a palindrome.",
"output": "def is_palindrome(s):\n return s == s[::-1]\n\nprint(is_palindrome('radar'))"
},
{
"instruction": "Implement a JavaScript function to find the longest substring without repeating characters.",
"input": "Find the longest substring without repeating characters in 'abcabcbb'.",
"output": "function longestSubstringWithoutRepeating(s) {\n let longest = 0;\n let start = 0;\n let map = new Map();\n \n for (let i = 0; i < s.length; i++) {\n if (map.has(s[i])) {\n start = Math.max(start, map.get(s[i]) + 1);\n }\n map.set(s[i], i);\n longest = Math.max(longest, i - start + 1);\n }\n \n return longest;\n}\n\nconsole.log(longestSubstringWithoutRepeating('abcabcbb'));"
},
{
"instruction": "Write a Lua function that calculates the factorial of a given number.",
"input": "Calculate the factorial of 5.",
"output": "function factorial(n)\n if n == 0 then\n return 1\n else\n return n * factorial(n - 1)\n end\nend\n\nprint(factorial(5))"
},
{
"instruction": "Write a Python function to find the largest prime factor of a given number.",
"input": "Find the largest prime factor of 13195.",
"output": "def largest_prime_factor(n):\n i = 2\n while i * i <= n:\n if n % i:\n i += 1\n else:\n n //= i\n return n\n\nprint(largest_prime_factor(13195))"
},
{
"instruction": "Implement a JavaScript function to reverse words in a given string.",
"input": "Reverse the words in the string 'Hello World'.",
"output": "function reverseWords(str) {\n return str.split(' ').reverse().join(' ');\n}\n\nconsole.log(reverseWords('Hello World'));"
}
]