Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
10
votes
2answers
369 views
Project Euler #22 - Names Scores
I programmed Problem #22 from Project Euler in Python. It works but I want to know if it really is pythonic enough.
Using names.txt (right click and 'Save Link/Target As...'), a 46K text
file ...
11
votes
1answer
74 views
First four Project Euler in Scala
I was working on teaching myself some Scala and decided to tackle some Project Euler problems. The first four of these turned out to be one liners.
...
1
vote
0answers
32 views
“Restaurant” HackerRank challenge in C
I don't write C all that often, so things to look for would be memory leaks and such. I also recognize that I'm not validating the user input as well as I could - I could use some feedback on how I ...
5
votes
4answers
69 views
Summing Divisors
Definition: A proper divisor of a natural number is the divisor that
is strictly less than the number.
e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor
summation is: 1 ...
4
votes
0answers
44 views
“The Ministry Of Truth” challenge at CodeEval.com
I am working on another challenge from CodeEval.com and this is a bit harder. I would like to get some feedback on my logic of solving the challenge. Also there is probably one edge case that I ...
4
votes
1answer
58 views
UVA 10474 - “Where is the marble?”
I have been solving the problem from UVA 10474. In this problem, there will be marbles with numbers written on them. For example suppose five marbles with numbers 50 , 43, 43, 43, 2, 90, 44. There ...
5
votes
4answers
83 views
Project Euler #3 In C++
The question for reference:
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?
answer: 6857
I'm looking for general feedback as to ...
5
votes
1answer
37 views
Reverse Groups challenge at CodeEval.com
I am working through challenges at CodeEval.com and wanted to get your input on my code for this challenge.
Given a list of numbers and a positive integer k, reverse the elements of the list, k ...
0
votes
1answer
108 views
Project Euler - Problem #11 - Ruby
As a beginning Ruby programmer I implemented a solution for Project Euler, Problem #11. (The problem is described in the comment below.) I'll be grateful for any suggestions for improvement ...
4
votes
3answers
196 views
Length of the longest sequence of repeating characters
I have been going through some CodingBat exercises and I came across this problem. "Given a string, return the length of the largest "block" in the string. A block is a run of adjacent chars that are ...
4
votes
1answer
75 views
Speed up lights-out variant solver in pure Python
I'm doing some challenges to learn new and interesting concepts, this one is about a Lights out variant, instead of toggling only the adjacent tiles, it toggles the whole row and col.
It must be ...
-3
votes
1answer
45 views
3
votes
2answers
97 views
Finding string roots
This is the following Python code that I have coded for an algorithmic problem online. For each line of input, the goal is to find the greatest number of repeating blocks into which the string can be ...
3
votes
2answers
66 views
Clojure solution to HackerRank Challenge 'Restaurant' under Number Theory
My main concern is how messy the min-number-of-slices function is. I would appreciate help finding good ways to clean that up since it has a lot of nesting/scope.
...
0
votes
0answers
32 views
Haskell version of HackerRank problem solution “NumberTheory/Restaurant”
Link to the challenge:
https://www.hackerrank.com/challenges/restaurant
Rip this code apart and embarrass me. I want to know about anything and everything you find wrong with it.
The problem is ...
3
votes
1answer
92 views
Minimum Scalar Product
Here's the problem statement for Minimum Scalar Product
You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as ...
3
votes
2answers
95 views
Count of Maximum - CodeChef
I'm doing an easy problem in codechef. Here's the problem statement for maxcount:
Given an array A of length N, your task is to find the element which
repeats in A maximum number of times as ...
5
votes
4answers
430 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
680 views
TopCoder problem “Lottery” - SRM 144 (Division I Level Two)
The problem statement
Summary:
The rules of a lottery are defined by two integers (choices and blanks) and two boolean variables (sorted and unique). choices represents the highest valid number ...
3
votes
1answer
43 views
Time limit exceeded for SPOJ problem Prime generator
Input
The input begins with the number t of test cases in a single line
(t<=10). In each of the next t lines there are two numbers m and n (1
<= m <= n <= 1000000000, ...
4
votes
2answers
148 views
TapeEquilibrium implementation, performance issue
So, I took a test at Codility called TapeEquilibrium. The task description that I recieved can be seen here.
I came up with a solution that worked, and I was pretty happy with. However, the ...
0
votes
2answers
106 views
Multiples of 3 and 5
Project Euler problem #1:
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 ...
1
vote
2answers
46 views
Codility AbsDistinct: Why is this solution not O(n)?
This is part of a series of algorithmic lessons and tests by Codility.
For copyright reasons, I cannot reproduce the question, which asks to compute the number of distinct absolute values in a given ...
5
votes
1answer
110 views
Codility MaxCounters Peformance in Python capping out at 77% performance
My problem is quite similar to the question found here, except I am attempting to answer the question in Python.
Given an array of N counters, all initialized to 0, and an array ...
6
votes
2answers
105 views
Generating non-repeating random integers in a fixed range
I was working on the "Robot Name" exercise over on exercism.io (neat site, by the way), the gist of which is: Generate random, unique strings that match ...
1
vote
1answer
59 views
MinCostMaxFlow implementation is not fast enough
I'm trying to solve this problem:
A root tree is a directed acyclic graph that contains one node (root),
from which there is exactly one path to any other node.
A root tree is binary if ...
2
votes
2answers
52 views
SPOJ problem: Life, the Universe, and Everything
Your program is to use the brute-force approach in order to find the answer to Life, the Universe, and Everything. More precisely, rewrite small numbers from input to output. Stop processing input ...
2
votes
0answers
56 views
Time Limit Exceeded for Code Chef problem Rendezvous
I am trying to solve a problem Rendezvous in code chef.
Problem Statement:
Given number of cities and routes between them resembling tree, consider there are two people who are put into ...
2
votes
2answers
93 views
Computing pairwise bitwise OR in a list of bit-strings
I am trying to solve this problem using Clojure:
You are given a list of \$N\$ people who are attending ACM-ICPC World
Finals. Each of them are either well versed in a topic or they are
not. ...
0
votes
4answers
47 views
Finding powers of multiple array pairs
I'm doing a challenge on TalentBuddy that requires you to find the powers of multiple array pairs. Since I got the solution right, but not fast enough, I decided I'd ask for help here.
...
0
votes
1answer
55 views
Project Euler 3 in F#
I'm looking for some general feedback on my solution to Project Euler challenge 3
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest
prime factor of the number 600851475143 ?
...
4
votes
2answers
82 views
Bats Challenge from CodeEval.com
I am going through coding challenges and I would like to get feedback on one of them.
I am not sure if i can post the link to the challenge but here it is. CodeEval Challenge
Outside of your ...
2
votes
1answer
102 views
Permutations of any given numbers
I have solved one programming problem where we have to find all the permutations of given numbers.
For example, \$[1,2,3]\$ have the following permutations:
$$[1,2,3], [1,3,2], [2,1,3], [2,3,1], ...
1
vote
2answers
79 views
Project Euler #45 - Triangular, pentagonal, and hexagonal
Project Euler Problem 45
Triangle, pentagonal, and hexagonal numbers are generated by the
following formulae:
Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ... Pentagonal
Pn=n(3n−1)/2 ...
12
votes
4answers
925 views
O(N) vs O(N * N) for Word Frequency Algorithm
I am trying to come up with a better solution to the following problem:
Statement
You are supposed to write a function which takes the contents of a document in string format and also a whole ...
2
votes
2answers
64 views
Project Euler #2 in F#
Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million.
My first attempt at this problem using functional programming with F#. I would've liked to use some kind of ...
2
votes
2answers
96 views
Finding a sum of unique triplet that is close to a given number in an array
I asked one question on code review yesterday about my code style, logic and readability of code. Hence, today I kept all those suggestions in mind while solving a new problem question.
The question ...
4
votes
2answers
441 views
Project Euler Problem 1 - Functional approach?
I'm trying to learn F# right now coming from C# and I'm finding it a great difficulty to "reconfigure" my mind to the functional programming mindset. So I'm going to attempt a few Project Euler ...
6
votes
5answers
339 views
Finding unique triplets adding up to 0
I am working on a problem "3Sum", in which, given an array S of n integers, are there elements ...
4
votes
2answers
74 views
Reflection and Project Euler
I have made a Project Euler runner in order to facilitate the running of the various problems. I have never used reflection before, and I believe that I have found a good use for reflection within ...
2
votes
2answers
110 views
Project Euler #3 - checking only up to sqrt(input)
I know it's possible for the largest factor of a number to be greater than the sqrt (e.g., for 14, 7 is the largest). Why then does almost every solution for the problem check only up to the square ...
1
vote
2answers
103 views
Count all unique subsets with Sum S
Team 7 faces a horrible foe. He can only be defeated with a special
quadruple combination attack of strength (\$1 <=S <= 10^9\$). Naruto,
Sasuke, Sakura and Kakashi must attack ...
6
votes
7answers
614 views
Project Euler #5 - Lowest Multiple of 1 through 20
I was trying to solve problem 5 of Project Euler, and this was I needed to do:
2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.
...
5
votes
2answers
106 views
Quadratic Primes - Project Euler 27
Project Euler Problem 27
Euler discovered the remarkable quadratic formula:
\$n^2 + n + 41\$
It turns out that the formula will produce \$40\$ primes for the
consecutive values \$n = ...
6
votes
2answers
114 views
Generating 'Decent' numbers
While solving a problem from HackerRank, though it's aneasy one, I wrote this big program. Not sure if recursion is applicable and hold good but to me it looked like it isn't. However when I run the ...
1
vote
2answers
84 views
“The Love Letter Mystery” - storing and comparison of strings
The problem goes like this.
Change the strings provided by user to form palindromes. To do this, 2
rules are:
(a) Reduce the value of a letter, e.g. Change 'd' to 'c',
but cannot change ...
4
votes
1answer
129 views
Sum of numbers which are not sum of two abundant numbers
The following program is a solution to Project Euler Problem 23. That problem defines an abundant number to be one whose sum of proper divisors is greater than it, tells us that all integers at least ...
2
votes
2answers
68 views
Summing all parameters, except the last, which should be subtracted instead
Working on some python koans and got one which states:
...
11
votes
1answer
696 views
Memory-Test for Soldiers
I am solving the following problem on code chef:
\$N\$ Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are \$M\$ rounds. In each ...
0
votes
1answer
37 views
Finding Largest Integer Palindrome within a Set
I've "solved" Project Euler Question 4 and I was wondering if I could make my answer more efficient (I'm using Project Euler to help me learn Haskell).
The problem reads:
Find the largest ...