Skip to content

Commit

Permalink
Merge pull request #47 from gustavwilliam/feature-new_levels
Browse files Browse the repository at this point in the history
Added special golfing levels
  • Loading branch information
gustavwilliam authored Jul 28, 2024
2 parents 1250418 + 1094eae commit 6d7f8d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
6 changes: 3 additions & 3 deletions bot/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ def _success_more_pages(self) -> list[StoryPage]:
class LevelA(Level): # noqa: D101
id = 12
name = "Level A"
topic = "Code Golf Apprentice"
topic = "Quadratic Quest"
map_position = (8, -2)


class LevelB(Level): # noqa: D101
id = 13
name = "Level B"
topic = "Code Golf Journeyman"
topic = "Fusion Master"
map_position = (12, 1)

async def on_success(self, interaction: Interaction[discord.Client]) -> Interaction:
Expand All @@ -346,7 +346,7 @@ def _success_more_pages(self) -> list[StoryPage]:
class LevelC(Level): # noqa: D101
id = 14
name = "Level C"
topic = "Code Golf Master"
topic = "Final Frontier"
map_position = (13, 4)

def _success_page(self) -> StoryPage:
Expand Down
62 changes: 29 additions & 33 deletions bot/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,53 +543,49 @@
"output": "125"
}
],
"max_characters": 45
"max_characters": 44
}
],
"13": [
{
{
"type": "write_golf_code",
"question": "Golf the following code to return the sum of squares of a list of integers.\n```python\ndef sum_of_squares(nums):\n result = 0\n for num in nums:\n result += num ** 2\n return result\n```",
"question": "Golf the following code to merge two sorted lists of ints into a single sorted list.\n\n```python\ndef merge_sorted_lists(list1, list2):\n result = []\n i = j = 0\n while i < len(list1) and j < len(list2):\n if list1[i] < list2[j]:\n result.append(list1[i])\n i += 1\n else:\n result.append(list2[j])\n j += 1\n result.extend(list1[i:])\n result.extend(list2[j:])\n return result\n```",
"hints": [
"Remove any spaces that aren't strictly necessary.",
"Use built-in functions to minimize code length.",
"Use a single line list comprehension.",
"Remember -- it only has to work. It doesn't have to be readable!"
"Consider using the sorted function.",
"Combine the two lists first."
],
"test_cases": [
{
"input": "sum_of_squares([1, 2, 3, 4])",
"output": "30"
},
{
"input": "sum_of_squares([0, 5, 10])",
"output": "125"
}
],
"max_characters": 45
{
"input": "merge_sorted_lists([1, 3, 5], [2, 4, 6])",
"output": "[1, 2, 3, 4, 5, 6]"
},
{
"input": "merge_sorted_lists([0, 10, 20], [5, 15, 25])",
"output": "[0, 5, 10, 15, 20, 25]"
}
],
"max_characters": 41
}
],
"14": [
{
{
"type": "write_golf_code",
"question": "Golf the following code to return the sum of squares of a list of integers.\n```python\ndef sum_of_squares(nums):\n result = 0\n for num in nums:\n result += num ** 2\n return result\n```",
"question": "Golf the following code to find all prime numbers up to a given number n.\n\n```python\ndef find_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n is_prime = False\n break\n if is_prime:\n primes.append(num)\n return primes\n```",
"hints": [
"Remove any spaces that aren't strictly necessary.",
"Use built-in functions to minimize code length.",
"Use a single line list comprehension.",
"Remember -- it only has to work. It doesn't have to be readable!"
"Use list comprehensions to condense the code.",
"Consider using the all() function."
],
"test_cases": [
{
"input": "sum_of_squares([1, 2, 3, 4])",
"output": "30"
},
{
"input": "sum_of_squares([0, 5, 10])",
"output": "125"
}
{
"input": "find_primes(10)",
"output": "[2, 3, 5, 7]"
},
{
"input": "find_primes(20)",
"output": "[2, 3, 5, 7, 11, 13, 17, 19]"
}
],
"max_characters": 45
}
"max_characters": 89
}
]
}

0 comments on commit 6d7f8d4

Please sign in to comment.