Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
-4
votes
0answers
27 views
Return lexicographically earliest string [on hold]
Write a function called answer(chunk, word) that returns the shortest, lexicographically earliest string that can be formed by removing occurrences of word from ...
4
votes
2answers
95 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
517 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
272 views
12
votes
6answers
1k 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 ...
-5
votes
0answers
25 views
Ten Green Bottles please give me a hand i cant work it out [on hold]
This open a file given as filename for reading returns the String containing the contents of the file
...
12
votes
5answers
968 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
647 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
571 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
98 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
70 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
47 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
57 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
74 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
51 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
53 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
111 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, ...
4
votes
3answers
593 views
Project Euler #8 code implementation
Find the thirteen adjacent digits in the 1000-digit number that have
the greatest product." eg, the product of the first four adjacent
digits is 7 * 3 * 1 * 6 = 126
...
5
votes
1answer
117 views
Project Euler, Challenge #12 in Swift
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, ...
4
votes
1answer
54 views
HackerRank - Candies
Here is the solution I've written for Hacker Rank Candies challenge.
It uses dynamic programming (memoization in a boxed array).
I'm interested on what could be done to improve this code in term of ...
4
votes
1answer
60 views
Project Euler 91 (via HackerRank): Right triangles with integer coordinates
This is my code to solve HackerRank's version of Project Euler Problem 91: on an N × N grid, find the number of possible right triangles where one vertex is (0, 0) and the other two vertices are ...
1
vote
1answer
62 views
Project Euler Problem 50 in Haskell
The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred.
The ...
4
votes
1answer
41 views
Euler Problem 101 - Optimum polynomial
Here is my solution in Haskell for the Euler problem #101. It relies on building a specific base of polynomes given the values we want to fit (memories of my linear algebra courses from a long time ...
4
votes
1answer
106 views
2D Fenwick-tree with combinatorics and modular arithmetic
This is a contest problem;
Description:
In the winter, children started to build snowmen. The snowmen were becoming adorable, except for a detail: none of them had a nose. The king, touched, ...
7
votes
3answers
1k views
Project Euler, Challenge #5 in Swift
The problem:
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 number that is evenly divisible by all of ...
2
votes
0answers
34 views
Seeking 5 primes such that concatenating any two of them produces another prime
I have a program which solves Project Euler problem 60:
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 ...
2
votes
0answers
34 views
Code Chef problem COOKMACH
Firstly, I got the solution for this question in CodeChef, but I noticed one thing which still confuses me. This was the code which was accepted as correct.
...
4
votes
1answer
48 views
Prefix Sum in Ruby, Genomic Range Query from Codility
I'm currently going through some lessons on Codility. I've just spent a couple of hours with GenomicRangeQuery, which is intended to demonstrate the use of prefix sums.
The task description is here. ...
2
votes
0answers
50 views
Project Euler: Autorun problems
I've found that it's a huge pain to have to write the boilerplate code for each Project Euler problem I write (timing code, main method, what about running every problem instead of just one?). So I ...
3
votes
1answer
105 views
Solution to challenge of making a list
This is the answer to this challenge:
Description
Thanks for that list you made me, my thoughts are way more organised!
I've got a few problems though that I thought you might be able to
...
4
votes
4answers
99 views
Project Euler 42 - finding triangle number V2
This is my revised solution to Problem 42 from Project Euler, based on suggestions in this original post Project Euler 42 - Finding triangle numbers
...
0
votes
2answers
131 views
Codechef COOKMACH solution, exceeding time limit
I'm stuck on Codechef problem COOKMACH, which asks for the minimum number of operations needed to transform integer A into integer B, where each operation can be either doubling the number or halving ...
-2
votes
0answers
165 views
Codechef “Gravity Guy” challenge
This is my solution to https://www.codechef.com/AUG15/problems/GRGUY but I'm getting the time limit exceeded error. I'm only 14 so please help me understand.
I used Scanner first but got the same ...
3
votes
0answers
72 views
Matrix rotation algorithm - follow-up
In a response to this post I wrote a solution in Python. It passed all the test cases given, so I would like help making it more pythonic and reducing the almost repeated lines.
Link to the source of ...
-2
votes
1answer
56 views
“Finding possible candy permutations” HackerEarth challenge
Problem Statement
Shil, Aditya and Utkarsh go to a candy shop. There are N candies
present in the shop, which are indexed from 1 to N. All three of them
select one candy to eat.
...
6
votes
3answers
88 views
Number of Chocolates to Gluttonize in Clojure
I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters:
...
0
votes
4answers
106 views
Performing add/delete/count operations on a list
Problem Statement (HackerRank)
You have a list of integers, initially the list is empty.
You have to process Q operations of three kinds:
add s: Add integer s to your list, note ...
5
votes
2answers
160 views
Solution to the 0-1 knapsack
I'm using a one-dimensional array with length \$W(\text{weight capacity})\$. Is this is any better than the solutions with a two-dimensional array \$W, n\$ where \$n\$ is the number of items? I'm ...
0
votes
1answer
246 views
Print the lexicographically smallest permutation that satisfies the given formation
Problem Statement:
A DOTA game has N heroes, each with a distinct rank from [1..N]. In
DOTA every formation is characterized as a permutation [1...N] of
ranks of players. A formation is ...
2
votes
1answer
72 views
HackerRank Regex Challenge: Detect HTML Tags
Problem Statement
In this problem you will use regular expressions to help you detect
the various Tags used in an HTML document.
Here are a few examples of tags:
The "p" tag for ...
3
votes
1answer
280 views
Calculate pairs in a Set (“Sherlock and Pairs” HackerRank challenge)
I have started reading clean code and want to improve my coding practices. Here is my attempt at solving an online puzzle. Please review the code and let me know how could I have written it better in ...
7
votes
5answers
358 views
CodeEval Challenge: Remove specified characters from a string
Question
Write a program which removes specific characters from a string.
The first argument is a path to a file. The file contains the source
strings and the characters that need to be ...
2
votes
0answers
33 views
Optimizing a problem that test all permutations of 1 array with other fixed array
I'm trying to solve this question on a contest programming judge.
Description of the problem:
There are N birds in a forest, each in their respective tree. There are N tired crows in this forest, ...
-4
votes
1answer
55 views
Return a sum unless one of the values is illegal
Is there a way to make my code more concise?
Given 3 int values, a b c, return their ...
4
votes
1answer
108 views
Project Euler 42 - Finding triangle numbers
Here is my solution for Project Euler Problem 42, which is described in the following:
The \$n^{th}\$ term of the sequence of triangle numbers is given by, \$t_n = ½n(n+1)\$; so the first ten ...
4
votes
3answers
196 views
Confirming existence of lapindromes
The following description is taken from CodeChef.com's Lapindrome problem.
Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same ...
3
votes
1answer
191 views
Ugly_Numbers challenge
Here's the challenge:
Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, ...
1
vote
1answer
112 views
SPOJ - POWFIB (Fibo and non fibo) Time Limit Exceeds
Problem
Find (a^b)%M, where
a = Nth non-fibonacci number
b = Nth fibonacci number modulo M
M = 1000000007
Consider fibonacci series 1,1,2,3,.....
INPUT
First line ...
4
votes
1answer
113 views
Counting number of inversions
This is a HackerEarth Challenge Problem.
Question:
Puchi hates to carry luggage, but unfortunately he got a job to carry
the luggage of his N friends in office. Each day, one of his N
...
7
votes
2answers
209 views
Solving 'decent numbers' that follow specific division rules
HackerRank Problem Statement
I have to find the largest 'decent number' having N digits. A decent number has the following properties:
3, 5, or both as its ...