Questions tagged [programming-challenge]
Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
412
questions
17
votes
7
answers
4k
views
Project Euler #3 - largest prime factor
I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows:
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest
prime factor of the ...
58
votes
9
answers
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 ...
12
votes
3
answers
6k
views
Project Euler Problem 12 - triangle number with 500 divisors
I've just done Problem 12 of Project Euler:
What is the value of the first triangle number to have over five hundred divisors?
The \$N\$'th triangle number is the sum of all natural numbers ...
18
votes
8
answers
5k
views
Project Euler Problem #4 - Palindromic number
The problem is as follows:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made ...
10
votes
4
answers
26k
views
Find the binary gap of a number N
For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of ...
7
votes
3
answers
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, ...
13
votes
3
answers
5k
views
The Beauty and the Strings
This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often.
Challenge:
Print the maximum beauty of strings.
...
12
votes
2
answers
4k
views
Determining winning hand in poker
After having reviewed this question, I recalled that I haven't solved Project Euler's problem 54. So I did it, however, I fount out that implementing the exact rules is rather tricky.
So I ...
11
votes
5
answers
3k
views
Efficiently counting rooms from a floorplan (version 2)
This is version 2 of Efficiently counting rooms from a floorplan. I had accidentally pasted in the wrong version of the code.
Update
Final version (version 3) of the code with updated test harness ...
7
votes
2
answers
5k
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
...
7
votes
2
answers
4k
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 ...
7
votes
1
answer
1k
views
Calculating the number of rooms in a 2D house
I stumbled upon this problem on cses.fi (a problem set for the Finnish Olympiad in Informatics. This problem is in finnish so I'll translate it). I'll describe the problem, present the code and think ...
6
votes
3
answers
943
views
The Genetic Code
This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Wascally wabbits. The repository with all my up-to-date solutions so far can be found ...
6
votes
1
answer
474
views
Efficiently counting rooms from a floorplan
Note this was the wrong version of the code. The updated version is here: Efficiently counting rooms from a floorplan (version 2) My apologies!
Update
Final version 3 with test harness here: ...
5
votes
2
answers
903
views
Matrix of articles and authors from large JSON dataset
Given the following JSON data containing 4 articles by 4 different authors:
...
5
votes
4
answers
2k
views
Project Euler #5 - Lowest common multiple of 1 through 20
This is my code. All comments welcome. Last time run it only took 335 milliseconds:
...
5
votes
2
answers
9k
views
Printing longest sequence of zeroes
I am doing a coding exercise in codility and I came across this question:
A binary gap within a positive integer N is any maximal sequence of
consecutive zeros that is surrounded by ones at both ...
3
votes
4
answers
3k
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 ...
3
votes
2
answers
1k
views
Premium palindromic primes
Challenge: Write a program which determines the largest prime palindrome less than 1000.
The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
3
votes
3
answers
479
views
Calculating number of unharmed leaves
I recently came across this problem that asks you to print the number of leaves not eaten by the caterpillars:
As we all know caterpillars love to eat leaves. Usually, a caterpillar
sits on leaf, ...
2
votes
3
answers
936
views
LeetCode 49: Group Anagrams
I'm exceeding the time limit for a 10,000 word test case provided on LeetCode:
Given an array of strings, group anagrams together.
For example, given: ...
0
votes
1
answer
136
views
Advent of Code 2020 - Day 2: validating passwords
Previous: Advent of Code 2020 - Day 1: finding 2 or 3 numbers that add up to 2020
Next: Advent of Code 2020 - Day 3: tobogganing down a slope
Problem statement
I decided to take a shot at Advent of ...
41
votes
9
answers
9k
views
The FizzBuzz challenge in Java 8 written in a short, readable and interesting way
I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program.
This in contrary ...
33
votes
7
answers
6k
views
Project Euler #7 10001st prime
I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
32
votes
7
answers
8k
views
100 gunmen in circle kill next person
The question is here.
100 people are standing in a circle with gun in their hands. 1 kills 2, 3 kills 4, 5 kills 6 and so on till we are left with only one person. Who will be the last person alive....
29
votes
6
answers
4k
views
DailyProgrammer 284: Wandering Fingers
Description
Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter.
You'll be given ...
25
votes
4
answers
3k
views
x86-64 Assembly - Sum of multiples of 3 or 5
I'm trying to learn some basic x86 assembly and so I've begun solving Project Euler problems. I was hoping for some critique of my code that, hopefully, includes either the efficiency of the ...
25
votes
8
answers
6k
views
Writing nested for loops to produce certain output
My task:
Write nested for loops to produce the following output with each line
48 characters wide:
...
21
votes
4
answers
3k
views
Project Euler #2 (Even Fibonacci numbers) in Swift
I figured working through Project Euler problems in Swift would be a good way to learn any tips or tricks. For example, tuples are something I'm not used to using, but they proved useful here. Using ...
20
votes
5
answers
3k
views
Print the N longest lines in a file
I have implemented the "Find the N longest lines in a file" problem from CodeEval quoted below.
I got a full 100 score and 182ms execution time of their data set on the site so I consider the code ...
19
votes
2
answers
3k
views
Project Euler "Even Fibonacci numbers" in Java 8
I'm looking for general advice on my code on the following problem:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms ...
19
votes
2
answers
530
views
Count the occurence of nucleobases in DNA string
Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough:
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', ...
15
votes
4
answers
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 ...
13
votes
5
answers
22k
views
Smallest Multiple
I just recently learned about Project Euler and have started doing the problems on there. I cleared problem 1 and 2, had no idea how to do 3 and 4, and started to do 5. I've seen the post regarding ...
12
votes
2
answers
4k
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 ...
12
votes
2
answers
607
views
Finding a word within a pre-defined set using a search string with wildcards
The other day I was intrigued by this question (originally from here):
Write a program that answers YES/NO search queries containing * placeholders. Example: if the data you have is (hazem, ahmed,...
9
votes
2
answers
213
views
Largest Prime Factor redux
There have been a number of questions asking for comments on code for the Project Euler problem to compute the largest prime factor of a number. A primary intent of this task is to find the factor as ...
9
votes
5
answers
6k
views
Euler #3 largest prime factor
Problem Statement
This problem is a programming version of Problem 3 from projecteuler.net
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of a given number N?...
8
votes
1
answer
6k
views
Hypothetical SalesTax challenge
I have a small solution to the following hypothetical problem:
Basic sales tax is applicable at a rate of 10% on all goods, except
books, food, and medical products that are exempt. Import duty ...
8
votes
2
answers
6k
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 ...
7
votes
3
answers
2k
views
Project Euler #8
I was doing Project Euler #8, which asks:
The four adjacent digits in the 1000-digit number that have the
greatest product are 9 × 9 × 8 × 9 = 5832.
...
7
votes
2
answers
412
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 ...
7
votes
5
answers
1k
views
Add Two Numbers given in Reverse Order from a Linked List
Updated Question
Problem Description
You are given two non-empty linked lists representing two non-negative
integers. The digits are stored in reverse order and each of their
nodes contain a ...
7
votes
4
answers
1k
views
Finding the sum of all the multiples of 3 or 5 below 1000
As a Lisp (and functional programming) newbie, I wrote the following code that finds the sum of all the multiples of 3 or 5 below 1000, and I suspect that it is lousy:
...
6
votes
2
answers
1k
views
Hackerrank challenge - Dictionaries and Maps
This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
6
votes
1
answer
176
views
Multithreaded testing for counting rooms from a floor plan solution
This is version 3 of Efficiently counting rooms from a floorplan. Version 2 is here Efficiently counting rooms from a floorplan (version 2)
It also has a comprehensive test facility that is the ...
6
votes
2
answers
865
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 ...
6
votes
2
answers
1k
views
Codility's Permutation Check in C#
I've made a few things in Java, and now I'm learning C#.
The code passes the tests with 100% final score. I want to know what things can be improved in my code.
Task description
A non-empty ...
6
votes
1
answer
588
views
Project Euler #10 in Swift - Summation of primes
I just finished Project Euler #10 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.
I hope I learned some from ...
6
votes
2
answers
795
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[...