pypuzzle allows you create programming puzzles that can be played by anyone. it is written in python3.x and is available under the MIT License.
pypuzzle-server serves puzzles from the puzzles directory. if it does not exist it will be created on startup.
a puzzle contains two methods: generate() and solve()
generate() gives a list of arguments that are used to test the puzzle
def generate():
return list(range(0,100))
solve() is the solution for one of the values from generate()
def solve(a):
if a % 5 == 0 and a % 3 == 0:
return "FizzBuzz"
elif a % 3 == 0:
return "Fizz"
elif a % 5 == 0:
return "Buzz"
else:
return a
doing a puzzle is simple. create a function that would solve the puzzle then
import pypuzzle
def func(a):
if a % 5 == 0 and a % 3 == 0:
return "FizzBuzz"
elif a % 3 == 0:
return "Fizz"
elif a % 5 == 0:
return "Buzz"
else:
return a
pypuzzle.challenge("localhost/fizzbuzz",func)
alternatively, the @solution(url)
decorator can be used
from pypuzzle import solution
@solution("localhost/fizzbuzz")
def func(a):
if a % 5 == 0 and a % 3 == 0:
return "FizzBuzz"
elif a % 3 == 0:
return "Fizz"
elif a % 5 == 0:
return "Buzz"
else:
return a
func()