All Questions
Tagged with programming-challenge python
1,025 questions
3
votes
1
answer
135
views
Efficient polynomial multiplication in Python
I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
1
vote
1
answer
96
views
Finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
5
votes
3
answers
867
views
Project Euler 127 - abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
We shall ...
2
votes
1
answer
46
views
Optimal Extraction of Longest Sorted Sequence from Individually Sorted Bucket Arrays Without Repetitions
Consider a bucket array containing sorted and/or empty buckets, and the goal is to extract the longest possible sequence in sorted order, under the following conditions:
Only one element in each ...
5
votes
1
answer
210
views
Performance Tuning to enable answer for Project Euler #566 "Cake Icing Puzzle"
Related to this question I am still looking for a solution to Project Euler Problem 566 (see link for a nice simulation also):
Adam plays the following game with his birthday cake.
He cuts a piece ...
5
votes
2
answers
345
views
Coding challenge for mixing a string
Challenge at https://www.codewars.com/kata/5629db57620258aa9d000014/train/python
Given two strings s1 and s2, we want to visualize how different the
two strings are. We will only take into account ...
2
votes
3
answers
567
views
Extract data from poorly formatted phonebook
The Problem
John keeps a backup of his old personal phone book as a text file. On
each line of the file he can find the phone number (formated as
+X-abc-def-ghij where X stands for one or two digits),...
4
votes
1
answer
145
views
Longest spell to cast from pages of spellbook follow-up
This question is from the PCTC 2022 R2 Past Paper and is a follow-up on my previous question. Previous question
I have implemented several solutions suggested, such as creating an array with pages ...
6
votes
4
answers
581
views
Longest spell to cast from pages of spellbook
While practicing for a school coding challenge, I came across this problem. My code got the right answers but exceeded the time limited. Any tips for how to reduce the time complexity?
https://pctc....
1
vote
3
answers
217
views
LeetCode 856: Score of Parentheses
Given a balanced parentheses string s, return the score of the string.
The score of a balanced parentheses string is based on the following rule:
- "()" ...
1
vote
2
answers
127
views
Optimizing an algebraic assignment puzzle
I am going to do a math competition which allows writing programs to solve problems.
The code attempts to solve problem 25 from the Purple Comet Spring 2004 Mathematics Meet:
In the addition problem
<...
1
vote
1
answer
133
views
Read millions of integers from stdin and process them in Python within 2 seconds
This is a competitive programming problem which has never been solved in Python within the time limit of 2 seconds. It is about Disjoint Set Union:
Source: Algorithms In Context #10: Disjoint Sets
...
6
votes
2
answers
717
views
Making a Rock Paper Scissors game in Python - How to reduce repetition and make it more effective?
I am a "new" coder to Python - saying this because I got stuck in the tutorial hell - and I saw that doing projects was a way of consolidating what I had learnt from those tutorials, so here ...
0
votes
2
answers
119
views
Advent of Code 2023 - Day 19: Aplenty (Part 1)
Description:
The task involves processing a set of workflows, each comprising rules. These rules define conditions based on part ratings and dictate the destination workflow if the conditions are ...
4
votes
1
answer
170
views
Roman numerals look and say sequence
I was practicing question 1 of the 2020 british informatics olympiad past paper:
The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each
block of ...
0
votes
2
answers
74
views
Advent of Code 2023 - Day 15: Lens Library
Part 1:
The task involves initializing the Lava Production Facility using an
initialization sequence. The sequence consists of steps, each requiring the
application of the Holiday ASCII String Helper ...
0
votes
1
answer
54
views
Advent of Code 2023 - Day 9: Mirage Maintenance
Part 1:
The task involves analyzing an environmental report from an oasis using the
Oasis And Sand Instability Sensor (OASIS). The report consists of multiple
histories, each containing a sequence of ...
0
votes
1
answer
57
views
Advent of Code 2023 - Day 8: Haunted Wasteland (Part 1)
Description:
The task involves navigating a haunted wasteland on a desert island using a camel. The objective is to escape from the current position (AAA) to the destination (ZZZ) by following left/...
2
votes
1
answer
169
views
Codewars 4 Kyu kata: "Most frequently used words in a text"
This was the first kata I found hard so I wanted to ask about it. Any ways I could I have done it better?
here's the question -> Most frequently used words in a text
...
2
votes
3
answers
746
views
Find median value of two Sorted Arrays
To improve my coding knowledge can you please give me suggested changes on my code?
...
4
votes
1
answer
107
views
Advent of Code 2023 - Day 6: Wait For It
Part One:
The task involves organizing multiple toy boat races, each assigned a specific race time and a recorded distance. To surpass the existing record, participants must optimize the duration of ...
2
votes
1
answer
134
views
Advent of Code 2023 - Day 5: If You Give A Seed A Fertilizer (Part 1)
The task involves determining the lowest location number corresponding to a given set of seeds by following numerical mappings for soil, fertilizer, water, light, temperature, humidity, and location.
...
3
votes
1
answer
95
views
Finding the number of "block chains" that are a certain length and begin with a certain string
I'm currently practicing for the british informatics olympiad by doing past papers.
I was doing question 3 of the 2019 paper:
A set of children’s blocks, each illustrated with a single different ...
3
votes
2
answers
167
views
Advent of Code 2023 - Day 4: Scratchcards
Part 1:
The task involves determining the total points of a set of scratchcards. Each scratchcard contains two lists of numbers: the winning numbers and the numbers the player has. Points are awarded ...
1
vote
1
answer
143
views
Advent of Code 2023 - Day 2: Cube Conundrum
Part 1:
The challenge involves analyzing recorded games where an Elf reveals subsets of cubes in a bag, each identified by a game ID. The goal is to determine which games would be possible if the bag ...
2
votes
2
answers
391
views
Advent of Code 2023 Day 3, Part 2 in Python
Part 2
I'm not sure if my solution covers all edge cases. The puzzle goes as follows: Given some input like this:
...
1
vote
1
answer
90
views
HackerRank Algorithm Problem: Climbing the Leaderboard (Python)
Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this?
...
3
votes
2
answers
308
views
Trailing Digits
https://www.acmicpc.net/problem/23204
I've solved a programming challenge where you need to count the occurrences of a specific digit at the end of the product of multiples of a given number within a ...
0
votes
1
answer
118
views
HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers
I again share my Python code which didn't pass time limit test cases in the HackerRank contest of ProjectEuler.
...
1
vote
1
answer
105
views
Project Euler 10(Python) | Summation of Primes
This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases.
...
3
votes
1
answer
328
views
Project Euler 60: Prime Pair Sets
Project Euler Prime Pair Sets:
The primes 3, 7, 109, and 673 are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime.
For example, taking 7 ...
3
votes
3
answers
507
views
Increment a large integer represented as array of digits
This problem can be found at LeetCode. Since I was studying idiomatic or 'pythonic' code in my language today, I decided to take the most 'pythonic' approach and challenged myself to do this in one ...
4
votes
3
answers
845
views
Codewars: Multiplying Polynomials
I'm trying to solve the following Kata from Codewars in Python.
My code produces the desired result for all the tests, yet it is not optimal, so it takes too much time to accomplish the big tests.
<...
3
votes
1
answer
358
views
Python function to find the count of digits of numerals in base n up to a given limit
This is a simple exercise to find the count of digits of all numerals in a given base up to a given limit (not including the limit), I wrote it to determine the ratio of bytes saved when the numbers ...
4
votes
4
answers
1k
views
Lottery Analysis (Python Crash Course, exercise 9-15)
I was working on Python Crash Course, exercise 9-15: 'Lottery Analysis'. It took me a very long time to get it to work. The reason it took that long is I wanted to use my existing class from the ...
0
votes
1
answer
250
views
Python Logic Gate Circuit Simulator [closed]
I have recently become interested in simulating logic circuits because of a electronics class at school. I have created a functioning simulator for logic gate circuits in Python. My implementation ...
0
votes
3
answers
198
views
Efficient Solution for Finding Product of Largest Pair in Array
Hello fellow developers,
I have written a function called max_product that aims to find the product of the largest two integers in a unique array of positive ...
1
vote
1
answer
162
views
Determine the chance a streak of 6 HEADs or 6 TAILS appear in 100 flips, repeated 10000 times [closed]
Here's the problem from the book Automate the boring stuff:
write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of heads and ...
3
votes
1
answer
720
views
Validating a Sudoku Board in Python
The problem statement is as follows:
Sudoku is a game played on a 9x9 grid. The goal of the game is to fill
all cells of the grid with digits from 1 to 9, so that each column,
each row, and each of ...
4
votes
3
answers
165
views
Improving efficiency of Rust algorithm ported from Python generator
I'm learning Rust by solving ProjectEuler problems.
To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
0
votes
1
answer
2k
views
sum of intervals kata in codewars
instructions for the kata:
Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only ...
0
votes
1
answer
261
views
Permutations CodeWars problem solved!
i have solved a question in codewars:
https://www.codewars.com/kata/5254ca2719453dcc0b00027d/python
, here's my solution is it unefficient to use itertools because people are blaming that is cheating ...
0
votes
1
answer
317
views
Calculate score of rock-paper-scissors (Advent of Code 2022: Day 2)
Advent of code, Day 2.
Here is my code.
Less verbose version of the question follows.
...
2
votes
1
answer
209
views
Finger Exercise: Update book cipher by creating new book
I'm working my way through the finger exercises in John Guttag's book Introduction to Python Programming, third edition. The following finger exercise on page 143 describes encryption/decryption with ...
7
votes
2
answers
1k
views
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size.
The problem: Given a list ...
4
votes
1
answer
329
views
Leetcode, longest palindromic substring
Here's a link
Given a string s, return the longest palindromic substring in s. A string is called a palindrome string if the reverse of that string is the same as the original string.
Example 1:
...
1
vote
2
answers
712
views
Find the cheapest flight to reach from source to destination
As the input you get the flight schedule as an array, each element of which is the price of a direct flight between 2 cities ...
3
votes
3
answers
1k
views
Creating Phone Number challenge from Code Wars
I solved a question on Codewars about creating a phone number:
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone ...
5
votes
1
answer
489
views
Connecting ropes with minimum cost
Question:
There are given N ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes ...
3
votes
0
answers
156
views
Finding the number of possible paths in a cave system (Python)
I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...