All Questions
Tagged with python programming-challenge
115
questions
7
votes
3answers
3k views
Efficiency of Project Euler problem 35
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, ...
56
votes
9answers
13k views
Project Euler problem 1 in Python - Multiples of 3 and 5
I'd like suggestions for optimizing this brute force solution to problem 1. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to ...
7
votes
2answers
3k views
Project Euler - Problem 54: testing poker hands
This was a very fun and thought provoking problem, and I'm quite proud of the way I was able to pull it off. I broke it down into 2 parts, testing and comparing.
Testing each group of cards for ...
3
votes
4answers
2k views
Sieve of Eratosthenes: making it quicker
I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
15
votes
4answers
3k views
Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R
A friend of mine recently started learning R, and she complained to me that R is very slow. She was working on Project Euler Problem 7, which asks for the value of the 10001st prime number. For ...
12
votes
2answers
3k views
CodeFights: Pipes game
Description
Carlos always loved playing video games, especially the well-known computer game "Pipes". Today he finally decided to write his own version of the legendary game from scratch.
In ...
6
votes
2answers
746 views
4 sum challenge (part 2)
This is a continued discussion from (4 sum challenge) by return count only.
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[...
4
votes
1answer
5k views
BFS shortest path for Google Foobar challenge “Prepare the Bunnies' Escape”
This is the Google Foobar challenge "Prepare the Bunnies' Escape":
You have maps of parts of the space station, each starting at a prison
exit and ending at the door to an escape pod. The map is ...
7
votes
1answer
5k views
BFS shortest path for Google Foobar “Prepare the Bunnies' Escape”
This is the Google Foobar puzzle "Prepare the Bunnies' Escape":
You have maps of parts of the space station, each starting at a prison
exit and ending at the door to an escape pod. The map is ...
5
votes
2answers
3k views
Character Picture Grid exercise - automatetheboringstuff
Regarding the Character picture exercise located at the end the following page:
https://automatetheboringstuff.com/chapter4/
Say you have a list of lists where each value in the inner lists is a
...
2
votes
3answers
8k views
Finding Pythagorean Triple that sums to 1000
I am doing this Project Euler Question #9:
A Pythagorean triplet is a set of three natural numbers, \$a < b < c\$, for which,
$$a^2 + b^2 = c^2$$
For example, \$3^2 + 4^2 = 9 + 16 = ...
7
votes
2answers
314 views
Finding min and max values of an iterable on the fly
This is a follow up for my question about optimizing solution for DNA Health HackerRank problem.
Short re-cap:
You are given 2 arrays (genes and ...
6
votes
2answers
788 views
Typeahead autocomplete functionality challenge
I'm working on a Talent Buddy challenge . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the ...
5
votes
3answers
3k views
Efficiency on Project Euler Problem #8
I am doing Project Euler problem #8:
The four adjacent digits in the 1000-digit number that have the
greatest product are 9 × 9 × 8 × 9 = 5832.
...
4
votes
1answer
284 views
Counting ways to fit bottles in crates
I'm calculating how many possibilities there are to fit \$n\$ identical bottles inside \$k\$ crates of various capacities.
n = Number of bottles
k = Number of crates
K = List of the number of bottles ...
2
votes
2answers
778 views
Project Euler problem 23 - non-abundant sums
I present my solution for Project Euler problem 23 written in Python (2.7).
The problem statement is:
A perfect number is a number for which the sum of its proper divisors
is exactly equal to ...
1
vote
1answer
206 views
Project Euler 34 # Digit Factorials in Python
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are ...
31
votes
1answer
7k views
100 gunmen in a circle kill next person
I am very happy because I solved this problem with very little code:
...
30
votes
6answers
68k views
Checking for balanced brackets in Python
I'm solving HackerRank "Stacks: Balanced Brackets" in Python.
A bracket is considered to be any one of the following characters: (,
...
27
votes
6answers
83k views
Project Euler #1: Multiples of 3 and 5
Challenge Description:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of ...
25
votes
4answers
1k views
Generalized Project Euler 1: A sledgehammer to crack a nut
The problem
Project Euler 1 is one of the most asked questions on site. However I wanted to solve the more general problem of division.
Multiples of a list
If we list all the natural numbers ...
14
votes
4answers
13k views
Google Foobar Challenge: Save Beta Rabbit in Python
I'm going through the Google Foobar challenges and am currently on the first challenge of level three. I've come up with a working solution, however, it's not an acceptable solution because it runs ...
7
votes
1answer
12k views
Shortest Path For Google Foobar (Prepare The Bunnies Escape)
I have been working on Google Foobar since a few days ago. I am currently in the third level but is stuck in the second challenge of "Prepare the Bunnies' Escape."
I have checked this post but it did ...
8
votes
5answers
2k views
Leetcode two sum
I'm currently learning c++ coming from a python background, so I'll include a solution in python and in c++ for the following problem statement:
Given an array of integers nums and an integer target, ...
10
votes
4answers
3k views
First non-repeating Character, with a single loop in Python
I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop.
My thinking is, it would be easy to tell you what ...
9
votes
2answers
2k views
Pangrams CodeEval challenge
I took a challenge on CodeEval. Although the code seems to work for the examples taken from the site, I feel it is not really pretty and must be more complicated than it should be.
Description:
...
7
votes
2answers
5k views
Google FooBar XOR Checksum Challenge
Google FooBar came up a few days ago and I took it as a challenge to learn python quickly while having fun. However, I ran into one challenge today that has left me stumped, I've come up with a ...
5
votes
0answers
427 views
4 sum challenge [duplicate]
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.
To make problem a bit easier, all A, B, C,...
5
votes
4answers
2k views
Any better way to solve Project Euler Problem #5?
Here's my attempt at Project Euler Problem #5, which is looking quite clumsy when seen the first time. Is there any better way to solve this? Or any built-in library that already does some part of the ...
15
votes
4answers
6k views
Google Foobar Challenge: Lucky Triples
Note: Since my time has passed for this challenge, I do not remember exactly the stipulations but will attempt to recapitulate them to the best of my knowledge.
Essentially, the challenge was this:
...
13
votes
5answers
8k views
“Algorithmic Crush” problem hitting timeout errors
This is the HackerRank problem Algorithmic Crush:
You are given a list of size N, initialized with zeroes. You have to perform ...
13
votes
5answers
965 views
Array manipulation: add a value to each of the array elements between two given indices
This is a Hackerrank problem: https://www.hackerrank.com/challenges/crush/problem
You are given a list of size \$N\$, initialized with zeroes. You have
to perform \$M\$ operations on the list and ...
12
votes
3answers
3k views
Codewars: Reduce strings to one character
I am trying to solve a puzzle in a performant way. This is the puzzle.
Simply explained: you have a String and you must reduce it to one character with the given rules. This is the solution to the ...
7
votes
1answer
1k views
Python program to find a word ladder transforming “four” to “five”
I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform "four" to "five", forming a new four-letter word at each step, replacing one letter ...
6
votes
3answers
13k views
Cadbury problem solution in Python
Problem Statement
In a School, Chocolate bars have to be distributed to children waiting in a queue. Each Chocolate bar is rectangular in shape. Consider its side lengths are integer values.
The ...
5
votes
3answers
13k views
Diagonal difference
Given
You are given a square matrix of size \$N×N\$. Calculate the absolute difference of the sums across the two main diagonals.
Input Format
The first line contains a single integer N. The ...
5
votes
2answers
2k views
Project Euler problem 79: deducing a passcode
For one place that I interviewed at (for a Python developer position) I worked with one of the devs on two Project Euler problems, one being problem 79. We talked through different approaches and came ...
4
votes
3answers
1k views
Project Euler #5 (LCM of [1, 2, …, 20])
I have implemented a solution to Project Euler problem 5:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive ...
4
votes
4answers
12k views
HackerRank “Nested Lists” Code
I completed the "Nested Lists" challenge on HackerRank, and would love any feedback on my code.
My program is fed text with the number of students in a classroom, the name of a student, and their ...
3
votes
0answers
342 views
Python2.7 Some xor fun
After doing the Cryptopals challanges, which I found scrolling through codereview, and finally being able to solve set1 challenge 6. I decided to have a little xor fun, and make an automated xor ...
2
votes
3answers
2k views
Determine Collatz sequence length for given starting values
I am trying to get into the habit of solving programming puzzles in my spare time but am stuck on the first one (which I know can be for a large number of reasons, hence my posting for help). Shown ...
2
votes
1answer
150 views
Leetcode atoi (string to integer)
link here
I'll include a solution in Python and C++ and you can review one. I'm mostly interested in reviewing the C++ code which is a thing I recently started learning; those who don't know C++ can ...
25
votes
5answers
1k views
Count distinct primes, discarding palindromes, in under 2 seconds
Problem Statement
Generate as many distinct primes P such that reverse (P) is also prime
and is not equal to P.
Output:
Print per line one integer( ≤ 1015 ). Don't print more than
106 ...
18
votes
5answers
3k views
Flipping coins performance
This is the Flipping coins problem on CodeChef:
There are \$N\$ coins kept on the table, numbered from \$0\$ to \$N - 1\$. Initially, each coin is kept tails up. You have to perform two types of ...
14
votes
1answer
283 views
Recover flights from found tickets
I just found a whole bunch of plane tickets that only have a start and destination on them. I also know the route started in a certain city. I would like to recover the (alphabetically) first possible ...
8
votes
1answer
3k views
Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?
Project Euler problem 407:
If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1.
The largest value of a such that a2 mod 6 = a is 4.
Let's call M(n) the largest value of a < n ...
8
votes
2answers
271 views
Summation of primes for large inputs
I'm doing a problem from Project Euler to find the sum of all primes under two million.
My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it ...
7
votes
2answers
5k views
Decode the Morse Code
From Code Wars:
This kata is part of a series on the Morse code. After you solve this kata, you may move to the next one.
In this kata you have to write a simple Morse code decoder. While the ...
7
votes
1answer
307 views
Check consistency of a list of statements, with fuzzy rhyme matching
I made a program today that solves the following problem on a programming competition site (open.kattis.com): Check if all statements with the following format X is Y or X not Y are consistent. X and ...
7
votes
1answer
924 views
Befunge-93 interpreter in Python
I was doing some CodeFights and had alot of fun with this Befunge challange
Problem statement
While exploring the ruins of a golden lost city, you discovered an
ancient manuscript containing ...