Challenges

0/5 Solved

Overall Progress0%
Pro Tip

Test your prompts with multiple approaches to find the most effective one!

2

Code Explanation Assistant

Medium

Problem Description

Create a prompt that generates clear and concise explanations for code snippets. The prompt should: 1. Analyze the given code snippet and identify its purpose 2. Explain the code's functionality in simple terms 3. Highlight key programming concepts used in the code 4. Provide examples of how the code might be used 5. Suggest potential improvements or alternative approaches Your prompt will be tested with various code snippets in different programming languages and evaluated based on the clarity and accuracy of the explanations generated.

Your Goal

Create a prompt that successfully handles all test cases below. Your prompt will be evaluated based on accuracy, consistency, and quality of outputs.

Example 1

Input:
def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2)
Expected Output:
This code defines a function called 'fibonacci' that calculates the nth number in the Fibonacci sequence using recursion. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. Here's how it works: 1. The function takes an input 'n', which is the position of the Fibonacci number we want to calculate. 2. If 'n' is 0 or 1, the function returns 'n' itself, as these are the base cases of the sequence. 3. For any other value of 'n', the function calls itself twice: - Once with 'n-1' and once with 'n-2' - It then returns the sum of these two recursive calls This implementation, while straightforward, is not efficient for large values of 'n' due to the repeated recursive calls. An iterative approach or memoization could be used to improve performance for larger inputs.

💡 The explanation breaks down the code's purpose, functionality, and key concepts (recursion, base cases) while also suggesting potential improvements.

Pro Tips

  • •Be specific and clear in your prompt instructions
  • •Include examples in your prompt to guide the AI
  • •Define the desired output format and tone
  • •Test with edge cases to ensure robustness

Prompt Editor

Write and test your prompt below

💡 Use placeholder like {input} to reference test inputs

0 characters

Test Case 1

Tests the prompt's ability to explain sorting algorithms

Input:
function quickSort(arr) { if (arr.length <= 1) { return arr; } const pivot = arr[arr.length - 1]; const left = []; const right = []; for (let i = 0; i < arr.length - 1; i++) { if (arr[i] < pivot) { left.push(arr[i]); } else { right.push(arr[i]); } } return [...quickSort(left), pivot, ...quickSort(right)]; }

Test Case 2

Tests the prompt's ability to explain data structures

Input:
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node return current = self.head while current.next: current = current.next current.next = new_node

Test Case 3

Tests the prompt's ability to explain frontend framework concepts

Input:
import React, { useState, useEffect } from 'react'; function DataFetcher() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetch('https://api.example.com/data') .then(response => response.json()) .then(result => { setData(result); setLoading(false); }); }, []); if (loading) return <div>Loading...</div>; return <div>{JSON.stringify(data)}</div>; }