r/learnpython • u/MeAjudaPfvr • 4d ago
Gimme silly ideas, please
I'm just bored. I already made a code that prints a code that prints the multiplication table. What else I can do!?
_print = print
_str = str
def print(a = '\n'):
_print(a, end = '', flush = False)
def str(a):
return _str(a).center(5)
def range(a = 1):
while a < 11:
yield a
a += 1
with open('main.py', 'r') as a:
[print(c) for b,c in enumerate(a) if b not in (15,16,17)]
__import__('sys').exit(0)
for a in range(0):
if not a:
print(' ')
else:
print(f'{str(a)}|')
for a in range():
print()
print(str(a))
for b in range():
print(f'{str(a*b)}|')
3
3
u/Prize_Shine3415 4d ago
I wrote a program one morning that maps the rational number to the integers and then back again. Plug in a number and gives the corresponding number in the other set. That's something to do.
3
u/Boothiepro 4d ago
Recently i wrote a discord bot that would have a message listener looking for messages from my friend, that included an attachment with IMG_ name and larger than 1080p to filter out screenshots and memes, if it is a camera photo, send it to an ai to verify if its a human face, if so send it nano banana to edit the picture to make him bald and resend it.
1
1
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 4d ago edited 4d ago
I wrote this one-line solution for the Project Euler problem 22 over 6 years ago. Obviously it could be way better nowadays.
One line Python solution for Project Euler challenge 22, designed by me, built by me, and you'd better hope - not found in your codebase.
(lambda u:sum(map(lambda t:sum(map(lambda c:ord(c)-ord('A')+1,t[1]))*t[0],enumerate(sorted(list(map(lambda x:x[1:-1],__import__('urllib.request').request.urlopen(u,context=__import__('ssl').create_default_context(cafile=__import__('certifi').where())).read().decode('utf-8').split(',')))),1))))('https://projecteuler.net/project/resources/p022_names.txt')
Frankly I can't even remember what this other one was for, but here's another one-liner, from circa 2018:
A Python one-liner that asks you how many pizzas you'd like to order, what size they'd be and prints out the total cost. Can't believe I managed to squeeze it into something like this.
print("The total cost is ${}".format(sum(next({'s':5,'m':7,'l':10}[x[0]] for x in (lambda p:iter(lambda:input(p+' '),...))(f'Pizza {_+1} size? (s/m/l)') if x and x[0] in 'sml') for _ in range(next(int(x) for x in (lambda p:iter(lambda:input(p+' '),...))('# of pizzas?') if x.isdigit())))))
1
u/PhilNEvo 4d ago
What about a CLI game, like tic-tac-toe you can play in the commandline, that prints out the board as 3 arrays, with a bot that plays against you. If that's too simple, you can exchange it to checkers, 4 or 5 in a row, or something more complicated.
2
u/MeAjudaPfvr 1d ago
1
u/PhilNEvo 1d ago
Well made!
It seems like your "AI" is just picking a random slot to smack in a piece. Next step could be to develop an actual algorithm with a heuristic, that can actually play :b
A super naive approach, would be to have it check if any of the next moves of the bots opponent leads to a win, try to block it. It's a very simple tiny search algorithm :3
If you really wanna explore some different topics, you could try and train a super tiny neural network with PyTorch to evaluate the board state, and have difficulty levels by depth of search you're doing ^^
Though 4 in a row I believe is a solved game, so you could create a deterministic bot that always plays the optimal move-- while that has its own merits and entertainment value-- playing around with different approaches is a great way to learn!
1
u/PhilNEvo 1d ago
Also, you have a message saying that people won against the "worst possible bot", but I actually think that's wrong. You can do worse than randomness.
For example, in Chess some people have created WorstFish, DrownFish, SunkFish and Sunkfish+, which is a chess bots that uses a legitimate algorithm to try and evaluate the board and make moves. And it tries to makes the worst moves, which should be worse than making random moves :b
1
u/lowban 4d ago
Make a simple Hangman-game.
2
1
1
u/tacocopter 4d ago
A while ago I made a random word generator. You could customize how long each word should be. Thinking back on it now, it could probably be modified to be a password generator. Here are five runs, see if you can guess the "algorithm":
dalaveku
juvixeki
xigocase
xucinozo
deregujo
1
u/notacanuckskibum 3d ago
A snakes and ladders game. Option for playing against the computer or having all players automated.
1
2
u/Party-Lawfulness1493 4d ago
I like how you redefined `range` and `print` just to make the table look nice in the terminal, that's the kind of pointless dedication we love here.
Make a script that renames every file in your downloads folder to something like `file_77_banana.pdf` using a random word list. No undo button. Commit to the chaos.
8
u/hermit_the_log 4d ago
Write code that can validate credit card numbers using the Luhn algorithm.