Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
0
votes
2answers
63 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 ...
-3
votes
0answers
18 views
How to make a batch code to process form inputs from websites? [on hold]
I was wondering whether it would be possible to make a batch file that could be used to process form inputs and even be used to create a database and respond to the form input on the webpage like.If ...
-2
votes
0answers
82 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
46 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
47 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
79 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
102 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
155 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
241 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
62 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
247 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
353 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 ...
3
votes
0answers
28 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
53 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
55 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 ...
1
vote
3answers
173 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
168 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
85 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
105 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
183 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 ...
10
votes
2answers
202 views
You need to diversify your strings
Challenge:
Write a program which prints all the permutations of a string in alphabetical order.
Specifications:
Your program should accept a file as its first argument.
The file contains ...
5
votes
3answers
72 views
Project Euler problem 92 (sequences formed by the sum of squares of digits) in Haskell
I made the following program in Haskell to solve Project Euler's problem 92. The program works (i.e. the solution it yields is correct), but it's not exactly the fastest in the world.
The problem is:
...
3
votes
1answer
81 views
Detecting cycles
This is a challenge question from codeeval.com:
Given a
sequence, write a program to detect cycles within it. Input sample:
Your program should accept as its first argument a path to a ...
7
votes
2answers
170 views
Complete “Is it simple or is it hard?” challenge from Code Golf
Having written C# for half a year now, I decided to take on a fairly complex first challenge for C++: the Is it simple or it is hard? challenge from Code Golf Stack Exchange. (This is only practice, ...
8
votes
2answers
345 views
These words are so dirty
Challenge:
Write a program that will clean up the words from extra numbers and symbols.
Specifications:
The first argument is a path to a file.
Each line includes a test case with a list ...
8
votes
2answers
81 views
Summing all numbers that can be formed from a list of integers
Following a challenge on HackerRank, I want to find the sum of all numbers that have no more than x 4's, y 5's, and ...
4
votes
2answers
33 views
Matasano CryptoPals Problem 8: Detecting ECB encryption
For the Matasano CryptoPals Challenges Set 1 Problem 8, which states:
In this file are a bunch of hex-encoded ciphertexts.
One of them has been encrypted with ECB.
Detect it.
...
4
votes
2answers
51 views
Longest lines of file descending
This is a challenge question from codeeval.com:
Write a program which reads a file and prints to stdout the specified
number of the longest lines that are sorted based on their length in
...
8
votes
5answers
626 views
Find longest lines from a file
This is a challenge question from codeeval.com:
Write a program which reads a file and prints to stdout the specified
number of the longest lines that are sorted based on their length in
...
3
votes
3answers
67 views
Matrix class with lots of tiny methods
I have been following the advice to make tiny methods that does just one thing and does it well. I also have been keen on reducing or eliminating duplication as much as possible.
But when a very ...
5
votes
2answers
45 views
The Geppy String: Regex vs Iteration
We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the g's in the given string are happy.
...
2
votes
2answers
66 views
ProjectEuler Problem #3
I'm working on projecteuler.net problems, and I made this for problem #3:
...
11
votes
2answers
350 views
Project Euler # 7 in C++
I attempted the Project Euler question #7 in C++ ("What is the 10 001st prime number?").
I took into account what I've been told about primes in order to create the most efficient algorithm I could ...
4
votes
1answer
82 views
Hackerrank regex solution
I solved the following problem on Hackerrank.
The challenge is to:
Parse HTML input and display the tags and attributes in lexicographically ascending order.
This is the input format:
...
4
votes
4answers
871 views
Staircase problem solved using recursion
Problem
Question taken from here.
I want to go up a flight of stairs that has n steps. I can either take 1 or 2 steps each time. How many different ways can I go up this flight of stairs? Write a ...
5
votes
1answer
63 views
Balancing words
A word is balanced at the index if the sum of the alphabet positions of all the chars multiplied by the distance to the index is zero.
This description is equivalent to the one given by ...
2
votes
2answers
81 views
DailyProgrammer Balancing Words Challenge
I'm hoping for someone to help me use the best practices and further make my code better that I used to accomplish the DailyProgrammer Challenge "Balancing Words".
The challenge is to check if a word ...
4
votes
2answers
174 views
Program to solve variations of the seven thieves & diamonds riddle
I answered a question yesterday on SO based on this riddle, but the code was so hard to read/follow to actually understand what was going on it was easier to write my own code to test the scenario and ...
4
votes
2answers
213 views
Project Euler Problem 5
I wrote up a small script to calculate the answer 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 ...
6
votes
2answers
101 views
Project Euler #3
I wrote some code to solve this question and I was wondering if it was efficient or not.
I just started learning code last week and I would like to get some input so I can get in the habit of writing ...
11
votes
2answers
359 views
Word Morph (changing one letter at a time)
Below is my implementation of Word Morph solver in Python.
The challenge consists of transforming one word into another word by changing one letter at a time. Each word in the chain should be an ...
5
votes
2answers
131 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 ...
7
votes
1answer
161 views
GCD using Euclid algorithm
Below is the problem taken from here.
Question 10: GCD*
The greatest common divisor of two positive integers a and b is the largest integer which evenly divides both numbers (with no ...
5
votes
2answers
97 views
Text justification
This is the Text Justification challenge at LeetCode:
Given an array of words and a length \$L\$, format the text such that each
line has exactly \$L\$ characters and is fully (left and right) ...
3
votes
0answers
24 views
Project Euler #2 in Go
I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
2
votes
1answer
59 views
Concurrency Bank exercise with multiple accounts
I am doing an exercise in Java concurrency. The problem statement is as follows:
Bank holds an array of Accounts. Client do (in a loop) the following
operations: (1) work, then sleep for random ...
4
votes
2answers
93 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 ...
4
votes
2answers
100 views
Even Fibonacci numbers under 4,000,000 (Project Euler #2)
Prompt:
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, ...
3
votes
2answers
113 views
Euler 357 solution efficiency
I have a Ruby program which should solve the following problem:
Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that
for every divisor d of 30, d+30/d is prime.
Find the sum ...
5
votes
2answers
92 views
Finding the sum of all the multiples of 3 or 5 below any given number
I wrote the following simple function in JavaScript that finds the sum of all the multiples of 3 or 5 below a value, given from a text-box.
I have used \$\dfrac{n}{2(a_1 + a_n)}\$ (sum of arithmetic ...