Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
1
vote
1answer
38 views
“Flipping bits” Python implementation
Problem Statement
You will be given a list of 32 bits unsigned integers. You are required to output the list of the unsigned integers you get by flipping bits in its binary representation (i.e. ...
4
votes
1answer
35 views
“Lonely Integer” Python implementation
Problem Statement
There are N integers in an array A. All but one integer occur in pairs. Your task is to find the number that occurs only once.
Input Format
The first line of the input ...
4
votes
2answers
741 views
Funny String Java Solution
I'm a little rusty in Java, but I'm using it to get ready for interviews. Here's the problem description from HackerRank:
Problem Statement
Suppose you have a string \$S\$ which has length ...
3
votes
0answers
29 views
Simple diceroller: reddit.com/r/dailyprogrammer challenge #130
Original specification can be found here.
I've modified the specification slightly, the input is done via environment variable and has a default of 2d20 (fireball damage!). This is in keeping of ...
1
vote
2answers
53 views
Pangrams python implementation
Given
Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly, because it is a ...
3
votes
2answers
42 views
Project Euler #18: Maximum path sum I
Problem
I want to receive advice on my code, which takes 0.012 seconds.
...
3
votes
1answer
88 views
Project Euler #14: Longest Collatz sequence
Problem : source
Which starting number, under one million, produces the longest chain?
n → n/2 (n is even)
n → 3n + 1 (n is odd)
I want to receive advice on my code.
It is too slow... It ...
1
vote
1answer
34 views
Project Euler #12: Highly divisible triangular number
I want to receive advice on my code. It is too slow... The problem I am trying to solve is:
What is the value of the first triangle number to have over five hundred divisors?
...
4
votes
4answers
548 views
Plus Minus in Python
You're given an array containing integer values. You need to print the
fraction of count of positive numbers, negative numbers and zeroes to
the total numbers. Print the value of the fractions ...
5
votes
2answers
55 views
Printing octo-thorpes
Given a number, for example, \$6\$, this Python function should print hashes in the following format:
#
##
###
####
#####
######
This is the ...
1
vote
3answers
41 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 ...
9
votes
4answers
533 views
Optimizing Project Euler Solution #12
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it ...
1
vote
2answers
49 views
Project Euler #12 in Racket
Problem here.
It's not exactly the brute force approach but I'm not using any sort of pre-calculated primes table, and I'm definitely not using the coprimality trick shown in the PE pdf. I'm finding ...
4
votes
3answers
115 views
Calculating the distance between two letters
I completed a sample programming challenge and wanted to find out how I could make it more efficient. I'm trying to get better at writing more efficient code, so I would be interested in hearing ideas ...
2
votes
1answer
67 views
Project Euler 4 The Functional Way
I'm learning Scala (and functional programming). Is there a better way to solve Euler problem 4 than either of these two solutions.
Euler 4
I like this array comprehension solution, but it wastes so ...
-1
votes
0answers
23 views
Python :SPOJ problem (Prime generator) working on my pc but not on the website [closed]
I am solving a problem in SPOJ (Prime generator) I made the program it works perfectly fine on my computer but doesn't seem to work on the SPOJ and I absolutely don't know why I even double checked ...
3
votes
1answer
42 views
Multiplying over a matrix
The below code is a solution I put together for the Project Euler #11 question which asked to find the largest product of 4 numbers of any direction in a matrix (horiz, vertic, and diag all ...
3
votes
3answers
91 views
Project Euler #3 Largest prime factor
Given
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Solution
...
5
votes
3answers
87 views
Funny string python solution
Problem Statement
Suppose you have a string \$S\$ which has length \$N\$ and is indexed from \$0\$ to \$N−1\$. String \$R\$ is the reverse of the string \$S\$. The string \$S\$ is funny if the ...
2
votes
2answers
56 views
Project Euler #12 Java implementation
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, ...
3
votes
4answers
93 views
Project Euler #8 - Largest product in series
The problem
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
...
2
votes
4answers
221 views
Project Euler #2 - Even Fibonacci numbers
Given:
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 will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
...
6
votes
3answers
313 views
Project Euler #1 Sum of multiples of 3 and 5
Given:
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 3 or 5 below 1000.
...
9
votes
2answers
413 views
Project Euler #1 Sum of multiples of 3 and 5 python implementation
Given:
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 3 or 5 below 1000.
...
1
vote
1answer
47 views
Project Euler #11 Java implementation
Project Euler 11 Solution in Java.
The problem is at https://projecteuler.net/problem=11
package coderbyte;
public class Java {
...
5
votes
1answer
81 views
Minimum window substring which includes all the characters from substring
I recently came across this problem which is as follows:
Given a string S and a string T, find the minimum window in S which
will contain all the characters in T in complexity O(n).
For ...
7
votes
1answer
135 views
Finding happy numbers
This is a practice question:
A happy number is a number defined by the following process:
Starting with any positive integer, replace the number by the sum of
the squares of its digits, and ...
2
votes
1answer
46 views
Construct biggest stacked tower with restriction
Problem
The problem is to build the tallest tower made up of cylinders, respecting all the rules.
Will be arranged on the table, an amount of \$N\$ cylinders.
Each cylinder has one color: Red, ...
2
votes
1answer
38 views
Utopian Tree in F#
This is the Utopian Tree in F# (from HackerRank)
The Utopian tree goes through 2 cycles of growth every year. The first
growth cycle of the tree occurs during the monsoon, when it doubles in
...
3
votes
3answers
150 views
Storing and processing large arrays to compute dot products
Problem Statement (from HackerRank)
We have two arrays \$a\$ and \$b\$ of length \$N\$, initially all values equals to
zero. We have \$Q\$ operations. Let's define three types of operations on
...
2
votes
1answer
70 views
Reporting the longest lines in a file - in decreasing length order
So, I did the CodeEval 'Longest Lines' problem and it works fine for any input data I can devise. When I upload it to CodeEval, it says it's wrong.
Because it's a "moderate" problem, input data is ...
5
votes
2answers
223 views
Prime factorization for integers with up to 9-digit long prime factors
I've become interested prime factorization since solving Project Euler problem 3 (finding the largest prime factor of 600851475143). Learning here that initializing lists with many elements to later ...
11
votes
7answers
701 views
Find largest prime factor, but focus on optimizing computational efficiency
This is my first post ever. Below is my attempt at solving Project Euler problem 3. It works for test numbers up to 9 digits long, but overflows when I input the real 12-digit behemoth.
I've looked ...
7
votes
3answers
150 views
Given a set of points and pairs of lines, count the number of points that are between the pairs of lines
This is a contest problem. The entire description is here.
In resume:
The question gives a point simulating a light explosion that always has a negative x coordinate, a set of pairs line segments on ...
7
votes
3answers
119 views
Check a string for any occurrences of certain character classes
This is a warm-up programming exercise for learning string methods in Python from HackerRank:
You are given a string S.
Your task is to find if string ...
4
votes
2answers
140 views
Project Euler 18/67: Maximum Path Sum Solution
I wrote my solution to Project Euler #18 and #67 in C++ (which I'm relatively new to), and was just wondering what everyone else thinks of it. It executes in 3-4ms and works flawlessly (even for ...
6
votes
5answers
537 views
Temperature Converter
This is an implementation of a practice problem from cprogramming.com: Temperature Converter Challenge
The problem:
In this challenge, write a program that takes in three arguments, a start ...
4
votes
2answers
293 views
14
votes
6answers
2k 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 ...
12
votes
5answers
1k views
Finding the 10001st prime
I'm solving Project Euler problem 7, which says:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?
Here's the ...
8
votes
5answers
664 views
Reversing a number
I was working through a programming challenge I found on Reddit and it seemed easy enough:
Find all numbers less than \$10^n\$ where the number and its reverse (the reverse of \$123\$ is \$321\$) ...
8
votes
4answers
599 views
Project Euler #2 in Python
Here is my Python code for Project Euler #2:
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 will
be:
...
8
votes
2answers
101 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 ...
5
votes
2answers
77 views
Project Euler #10 - sum of primes below two million
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
...
3
votes
2answers
55 views
Calculate pairs in a Set (“Sherlock and Pairs” HackerRank challenge)
Here is my second attempt at writing clean code for "Sherlock and Pairs" challenge. For my previous thread please look here: Calculate pairs in a Set ("Sherlock and Pairs" HackerRank ...
7
votes
1answer
58 views
Project Euler #7 using Java streams
I haven't written any Java in years and I wanted to catch up a little, especially on newer features. I started looking at streams and aggregate operations and came up with the following solution to ...
3
votes
1answer
85 views
Solving Project Euler problem #60 in C++
I have implemented a solution to Project Euler problem #60. In summary, the problem asks to find the smallest sum of a set of five prime numbers such that the decimal strings of any two numbers in the ...
3
votes
1answer
52 views
Twisting words! (boustrophedon formatting)
I decided to implement properly the Code Golf challenge about twisting strings. I report the assignement verbatim for convenience:
Twisting Words!
Given a string and a positive integer. You ...
2
votes
2answers
54 views
Project Euler, Challenge #17 in Swift
Number letter counts, Problem 17:
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers ...
1
vote
3answers
119 views
Project Euler #9 implementation in Java
Question:
Special Pythagorean triplet, Euler Problem 9
A Pythagorean triplet is a set of three natural numbers, \$a<b<c\$, for which, $$a^2+b^2=c^2$$ For example, ...