Skip to main content

Questions tagged [python]

This challenge is related to the Python language. Note that challenges that require the answers to be in a specific language are generally discouraged.

Filter by
Sorted by
Tagged with
0 votes
1 answer
108 views

You have to code in python, and the number generated by your code must be bigger than all other current submissions. You need to make your code as small as possible, it has to terminate but you can ...
IAmNotLarry's user avatar
4 votes
1 answer
121 views

What is Buckshot Roulette? Buckshot Roulette is an indie game, released by Mike Klubnika to itch.io in 2023. Okay, but how do you play? To quote from the wiki: "At its core, Buckshot Roulette is ...
Natelolzzz's user avatar
0 votes
1 answer
326 views

I have the following Python code, which is 214 bytes long: ...
RannStudio's user avatar
3 votes
5 answers
408 views

You are in charge of running a board game tournament. Unfortunately, you only have one copy of the game and only so much time, so only a limited number of games can be played. Similarly, you have a ...
Spitemaster's user avatar
  • 2,189
1 vote
0 answers
90 views

Write a piece of code that is compatible with both C and Python compilers/interpreters, which can output its own source code. Quine is quite easy, but how about this double language version? Hint: To ...
NoNormalCreeper's user avatar
0 votes
1 answer
401 views

The following code is 47 characters. print(("Ekki v","V")["COV"in input()]+"eikur!") How can it be reduced to 46 or less? I ...
LargeHorse's user avatar
6 votes
4 answers
638 views

Code Golf Challenge Given a string of 10 characters: 'abcdefghij' I want to format it in this pattern and print it in the console in a minimum number of characters: ...
Karine Bauch's user avatar
18 votes
16 answers
3k views

In this challenge, you will play the iterated Prisoner's Dilemma, but with a twist: There's also an adversary trying to mess you up! The Prisoner's dilemma is a scenario in game theory where there are ...
izzyg's user avatar
  • 42.3k
8 votes
1 answer
564 views

Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only. Answers meeting this extra ...
Shuri2060's user avatar
  • 191
5 votes
3 answers
529 views

Background In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can ...
Mardoxx's user avatar
  • 181
-3 votes
1 answer
591 views

So I got kinda bored and was wondering if it was possible to make this code shorter without modifying anything except a file named coin.py... ...
Eric's user avatar
  • 121
17 votes
19 answers
6k views

The bots are looking for love. Can you help them? The rules The goal of this game is find the bot you have the highest compatibility with. However, robots, who are inexperienced at dating are unable ...
mousetail's user avatar
  • 14.4k
6 votes
2 answers
451 views

I have the code: ...
Dark Programmer's user avatar
27 votes
14 answers
3k views

Python string parsing has quite a few edge cases. This is a string: "a" Putting 2 strings immediately after each other implicitly concatenates them, so ...
mousetail's user avatar
  • 14.4k
9 votes
2 answers
692 views

I want to read two strings on separate lines, each string the same length and containing only 0's and 1's, and determine if the first is the one's complement of the second. How succinctly can this be ...
Fixee's user avatar
  • 191
4 votes
3 answers
1k views

So the golf question was like this: You are given a number T and then a total of T number of 17-character strings. For each of ...
chnmasta05's user avatar
14 votes
16 answers
3k views

In this king-of-the-hill challenge, you will program a bot, consisting of a python function of the form def BOTNAME(info, me, round): pass # ... main body ...
Qaziquza's user avatar
  • 1,693
-6 votes
2 answers
373 views

King of the Hill: Greed Control What is Greed Control Greed control is a multiplayer round-based game in which in every round, a player bet a number inside a ...
Sunny's user avatar
  • 2,004
8 votes
2 answers
354 views

I have a coding problem that goes like this: Given a positive integer \$N\$, return a list of all possible pairs of positive integers \$(x,y)\$ such that $$\frac1x+\frac1y=\frac1N$$ I already solved ...
Aiden Chow's user avatar
  • 14.6k
-11 votes
1 answer
400 views

Here is the program to return [[0, 0, 0], [0, 1, 0], [0, 0, 0]] [[0]*3,[0,1,0],[0]*3] Try it online! Can you shorten this code?...
Fmbalbuena's user avatar
  • 5,085
9 votes
2 answers
983 views

I am trying to write a solution to the following problem using as few characters as possible (to meme my friend and introduce him to golfing). Can any improvements be done to my code? So the problem ...
chnmasta05's user avatar
3 votes
3 answers
805 views

Code Python 3, 245 bytes ...
Fmbalbuena's user avatar
  • 5,085
9 votes
4 answers
3k views

I'm writing a program that takes a number from input (call it x), loops from 0 to (x - 1) (let's call our iterator y) and prints \$y^x+x\$ for each y. After the loop, it then prints "SUM: N" ...
Fmbalbuena's user avatar
  • 5,085
20 votes
1 answer
805 views

I've recently stumbled upon a Russian site called acmp.ru, in which one of the tasks, HOK, asks us to find the LCM of two positive integers. The full statement, translated to English is as follows: ...
dingledooper's user avatar
  • 23.4k
6 votes
2 answers
476 views

I am trying to push my limits of making a python code as short as possible. I left the readability part way behind. I was attempting the K-Goodness String problem from Round A of Google Kick Start ...
Ishaan Kapoor's user avatar
-3 votes
1 answer
456 views

I'm not really sure if this is the right place to ask this. Now, I know I can convert a float to an int with int, but is there some shorter way?
Alan Bagel's user avatar
  • 4,279
4 votes
2 answers
1k views

The goal is to create a generator generator [...] generator generator comprehension. The generator must be created via generator comprehension. The following expression must be valid for any number ...
DivideByZero's user avatar
7 votes
4 answers
1k views

Introduction This challenge is about producing a code to count the frequency of bigrams in a text. A bigram is two consecutive letters in a text. For instance 'aabbcd' contains the bigrams aa, ab, bb, ...
willmaths's user avatar
  • 179
9 votes
2 answers
4k views

I have 2 inputs: 1 single number and some numbers separated by whitespace: 1 1 2 3 4 5 I want to loop over the second input, and I don't need the first input. I ...
Basto's user avatar
  • 573
5 votes
1 answer
385 views

I wrote this function in 48 bytes and I wonder, is there any way to write this code 2 characters shorter? p=lambda n,c:(n*c)[:n//2]+(n*c)[:n//2+n%2][::-1] The ...
Diana Andrei's user avatar
8 votes
6 answers
798 views

Background So, nowadays the popular Prisoner's Dilemma variant is the Prisoner's Trilemma, where there are three options. I can easily see that being increased, so I figured Why settle for three ...
4D4850's user avatar
  • 189
12 votes
16 answers
2k views

The Prisoner's Dilemma, but with 3 choices, and the payoffs are random! Each round, your bot recieves a 3x3 grid and chooses a row to play. The grid might be this: ...
Spitemaster's user avatar
  • 2,189
6 votes
6 answers
1k views

In this king-of-the-hill challenge, you will be making a python 3 bot to play the card game judgement! Sandbox Rules Judgement is a hand based game similar to games like rummy. In each round, 7 cards ...
Rushabh Mehta's user avatar
22 votes
9 answers
4k views

I'm not sure if this is the right place to ask, but I found this similar question so I'll go ahead. I'm very new to code golfing, so keep your smothered laughs and throw-up emoji's to yourselves ...
Have a nice day's user avatar
8 votes
1 answer
438 views

What does "jelly" mean in the title?. Cop's thread Robbers, you are to choose an uncracked Cop answer, and attempt to find a Jelly program which is: shorter than the Cop's answer solves the ...
caird coinheringaahing's user avatar
12 votes
3 answers
1k views

What does "jelly" mean in the title?. Robber's thread Jelly has an "Evaluate the argument as Python 3" atom, ŒV which takes a string as an ...
caird coinheringaahing's user avatar
16 votes
17 answers
1k views

Github You have probably played, and may even have written a program to play, a simple number guessing game. If so, this probably looks familiar: ...
Miriam's user avatar
  • 843
-5 votes
1 answer
296 views

Your challenge is to write a Python program to print all the primes (separated by whitespace) less than a given integer N with an asterisk (...
user101295's user avatar
-7 votes
1 answer
214 views

Create a function which takes in a input integer and then returns the number of factors it has, like if you pass 25 then it will return ...
Smilecat's user avatar
  • 165
2 votes
0 answers
237 views

I just realized that Python allows more than names as for loop iteration variables: for a[i] in sequence: pass The real fun ...
Aristide's user avatar
  • 129
3 votes
2 answers
667 views

How do I remove all duplicates from list and order it based on count? ...
12944qwerty's user avatar
43 votes
17 answers
7k views

Just like code-golf, restricted-source pushes one to exploit quirks and hidden features of the Python language. We already have a place to collect all these tips for code-golf, those for restricted-...
Wheat Wizard's user avatar
  • 103k
1 vote
2 answers
850 views

Input: from STDIN number of vertices in Graph \$2 \leq N \leq 100\$. Rules: [Code size] = max ([code length without spaces, tabs and newlines], [total code length divided by 4]) Math formulation: In ...
Evgeny's user avatar
  • 333
4 votes
2 answers
1k views

So, this is a task from one very popular educational site in Russia: https://acmp.ru/index.asp?main=task&id_task=786&ins=1 Mathematically, you need to find the power of two not exceeding the ...
Evgeny's user avatar
  • 333
16 votes
8 answers
1k views

A great Python golfing tip is to omit needless spaces. But if you are like me, you don't always have the time to search for which spaces to remove. If only there was a way to speed up the process... ...
dingledooper's user avatar
  • 23.4k
12 votes
3 answers
2k views

I started a CodeWars kata in Python, just two days ago, related to code golf. Task: Given two congruent circles a and b of radius r, return the area of their intersection rounded down to the nearest ...
Leo oeL's user avatar
  • 123
4 votes
2 answers
3k views

I am trying to find the shortest code in python 3, to solve this problem: You are driving a little too fast, and a police officer stops you. Write code to take two integer inputs, first one ...
Sayandip Dutta's user avatar
4 votes
1 answer
803 views

On CodingGame, there is a Puzzle that ask to write words with ascii art. I solve the puzzle then tried to golf it. What improvement can I do on it? ...
Dorian Turba's user avatar
11 votes
3 answers
859 views

In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted ...
Dorian Turba's user avatar
15 votes
12 answers
1k views

In Imperial China, ranks in society were not decided by birth or wealth, but by a person's ability to excel in the Imperial Examinations. The Jade Emperor, divine ruler of the Heavens, has called for ...
AlienAtSystem's user avatar