Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
-2
votes
0answers
13 views
Runtime Error RE (SIGSEGV) [on hold]
Here is my code for finding the Σn/gcd(i,n) where i=1 to i=n and n have the range of 10^7. I have used totient-function for calculating the required sum.
...
3
votes
1answer
22 views
Collatz Sequence in Python
I'm trying to use Python to solve the Project Euler problem regarding the Collatz sequence. With some research online, I have come up with the code below. However, it still takes a long time to find ...
-1
votes
0answers
13 views
Project Euler Project 5 [on hold]
I have a problem which says :
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 ...
4
votes
3answers
56 views
The Odd-Even Challenge
After posting my first question on here, I got a lot of great feedback. I've decided to try another challenge and write it as cleanly as possible.
The rules of Odd-Even consists of the following ...
4
votes
0answers
33 views
Grooving Project Euler # 8
I recently watched a video course on groovy and started working on some of the Project euler problems to flex my groovy* muscle.
(This is problem #8)
The four adjacent digits in the 1000-digit ...
2
votes
1answer
109 views
Highest floor of a building from which to drop an egg without breaking it
Problem description:
You have two eggs, and need to find the maximum floor of a 100-floor building from which you can drop the eggs without them breaking. Do this with as few attempts as possible. ...
2
votes
2answers
46 views
Sum of proper divisors
Given a natural number \$n\$ (\$1 \le n \le 500000\$), please output the
summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is ...
7
votes
1answer
83 views
“Dungeon Game” solution
I was tackling this problem and I ended up with code that is functional, but times out with really large input (meaning it's poorly optimized). I'm a beginner in programming and working out a ...
2
votes
2answers
37 views
Block Art - IEEEXtreme 9.0
I attempted this problem from the ieeextreme, and I got timeout for just over 40% of the cases. Now that the competition is over, I was wondering what could be improved.
The problem is as follows:
...
6
votes
1answer
69 views
Check sum of all primes under two million
I'm exploring ruby by writing a code that checks the sum of all prime numbers under two million. As I am still in the process of learning ruby, I'm unfamiliar with all the standards and best ...
5
votes
3answers
438 views
Project Euler 92: Square digit chains
A number chain is created by continuously adding the square of the
digits in a number to form a new number until it has been seen before.
For example,
44 → 32 → 13 → 10 → 1 → 1
85 ...
6
votes
5answers
657 views
Longest running string
I came across this problem in a career cup. Below I have the questions and the Java solution. I was wondering if anyone could scrutinize my code and tell me if there are any improvements, or better ...
0
votes
0answers
10 views
Trouble with the fermat primality test in java [closed]
I am having trouble writing a successful algorithm that indicates whether a number is probably prime by fermat's primality test. I have searched for similar questions on this website but sadly I was ...
-1
votes
1answer
36 views
Optimize finding GCD of all pairs of divisors
I've come up with a solution for Euler Problem 530, but my code runs too slowly to actually get the answer (solving for 10^15). What can I do to optimize it to run faster?
...
3
votes
1answer
56 views
Generating the maximum number possible from an array
I have the following code in Scala as a solution to the problem:
Find the maximum number possible from the given Seq of Integers while keeping the individual numbers intact
e.g.
Seq(2,5,9,4) ...
4
votes
1answer
144 views
Counting ways to fit bottles in crates
I'm calculating how many possibilities there are to fit \$n\$ identical bottles inside \$k\$ crates of various capacities.
n = Number of bottles
k = Number of crates
K = List of the number of ...
5
votes
1answer
45 views
De Casteljau's Algorithm Tool for Khan Academy Contest
So I wrote this code for a contest going on over at Khan Academy known as "Pixar in a Program". The goal of the contest is to create an entry that uses one of the skills shown in the new "Pixar in a ...
2
votes
2answers
90 views
Solving for equilibrium index in an array
I did a sample on Codility and finished the test task.
The problem description is very short:
The equilibrium index of a sequence is an index such that the sum of elements at lower indexes is ...
1
vote
2answers
105 views
Determining if two strings are anagrams
Two strings are said to be anagrams of each other if the letters of
one string may be rearranged to make the other string. For example,
the words 'elvis' and 'lives' are anagrams.
In this ...
2
votes
1answer
46 views
Optimize program to test for divisibility of numbers 3.0
This is a follow up on my previous question.
JS1's answer suggested that I should use a precomputed table containing all permutations of the lowest valid number for each number between 1 and MAX. It ...
3
votes
1answer
60 views
Testing for divisibility of numbers - follow-up
(Here is the follow up question)
I had another go at trying to speed up my program described in my previous question.
JS1's answer was particulary helpful and now my code is only about 20% slower ...
5
votes
1answer
54 views
Project Euler no. 17: Counting letters to write the numbers from 1 to 1000
I'm very new to programming and am admittedly embarrassed sharing my code for critique. This code works and produces the correct answer to the Project Euler Problem 17, which asks how many letters ...
2
votes
2answers
76 views
Program to test for divisibility of numbers
(EDIT: here is the follow up qusetion)
Using this program to test for the smallest number where its permutations or itself is divisible by 10 or less numbers is twice as slow as the fastest program I ...
1
vote
1answer
37 views
Find permutation of a specified lexicographic rank
This is one result of my work on Project Euler to learn Java. I'm interested in how well this conforms to best practices as well as any recommendations on efficiency. (I'm pretty sure this code is a ...
2
votes
2answers
62 views
Waterloo Programming Contest: The Game of 31
Please review my program for the Game of 31.
The game of 31 was a favourite of con artists who rode the railroads in days of yore. The game
is played with a deck of 24 cards: four labelled each ...
2
votes
1answer
33 views
Project Euler Problem 2 in Java
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, ...
By ...
2
votes
2answers
67 views
Project Euler #85: Find the rectangular grid with closest to 2M rectangles
For one place that I interviewed at (for a Python developer position) I worked with one of the devs on two Project Euler problems, one being problem 85. We talked through different approaches and came ...
5
votes
2answers
103 views
Project Euler problem 79: deducing a passcode
For one place that I interviewed at (for a Python developer position) I worked with one of the devs on two Project Euler problems, one being problem 79. We talked through different approaches and came ...
3
votes
2answers
257 views
Project Euler #42 - Triangle Numbers
Here is the Euler problem referenced, it says:
The n\$^{th}\$ term of the sequence of triangle numbers is given by, t\$_n\$ =
½n(n+1); so the first ten triangle numbers are:
1, 3, 6, 10, ...
3
votes
2answers
47 views
Project Euler 62: cubic permutations, logic
Problem 62 of Project Euler goes
The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the
smallest cube which has ...
6
votes
3answers
643 views
Find total number of phone numbers formed by the movement of Knight and Bishop on keypad
I recently gave a test on HackerRank, and submitted my answer for the following question. I passed all the test cases but company told me that the answer is not efficient, and they are not moving ...
2
votes
1answer
42 views
Summations and products in F#
I was bored, and looking to do something that involved anonymous functions, and it was suggested by @Quill, that I create a summation function. I decided to also include a product function as well to ...
2
votes
2answers
88 views
Gluing pieces of scrambled text (challenge on CodeEval)
I'm trying to solve this challenge on CodeEval. Quoting:
For example, you can put pieces together and get the original text:
evil pl
vil pla
il plan
The answer is ‘evil plan’.
Your ...
2
votes
3answers
80 views
Palindrome numbers - Project Euler Problem 4
Project Euler Problem #4: Largest palindrome product:
A palindromic number reads the same both ways. The largest palindrome
made from the product of two 2-digit numbers is 9009 = 91 × 99.
...
5
votes
1answer
51 views
Project Euler 40: directly calculate digits of Champernowne's constant
I implemented Project Euler problem 40 in Java. It works correctly, producing the correct answer.
During the course of implementing this program, I wrote a method that directly calculates a digit of ...
5
votes
1answer
81 views
Project Euler: #36 Binary and Base 10 Palindromes
Here is the Euler problem referenced, it says:
The decimal number, 585 = 1001001001\$_2\$ (binary), is palindromic in both
bases.
Find the sum of all numbers, less than one million, which ...
9
votes
5answers
174 views
ASCII generator
Today I stumbled upon CodinGame, a site with programming challenges. I'll describe one of them.
ASCII art allows you to represent forms by using characters. To be precise, in our case, these forms ...
4
votes
2answers
76 views
Flowers Challenge on HackerRank
I worked through the Flowers challenge on hackerrank.com and would like to get feedback on solution and algorithm implementation. It was suggested by hackerrank to review greedy algorithm to solve ...
4
votes
4answers
90 views
“Tractor” Python implementation
This is the Tractor problem from the Kattis problems archive.
Problem Statement
Bessie the Cow has stolen Farmer John’s tractor and is running wild on the coordinate plane! She, however, is a ...
3
votes
2answers
81 views
“Cut the sticks” Python implementation
Problem Statement
You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the ...
1
vote
1answer
42 views
Euler #25 Scala
I usually write Euler solutions in Javascript. On problems requiring very large integers I have decided to learn Scala and take advantage of BigInt. I wrote a ...
6
votes
3answers
952 views
“Angry Professor” Python implementation
Problem Statement
The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there ...
2
votes
3answers
41 views
Project Euler 30 - Digit fifth powers in Rust
I am trying to move from Python to a systems programming language so this is a bit of a challenge for me.
...
4
votes
1answer
88 views
Ad-hoc lexical scanner
Challenge:
Build an ad-hoc scanner for a calculator language.
Specifications:
The tokens for the language are as follows:
assign → :=
plus → +
minus → -
times → *
div → /
...
7
votes
1answer
164 views
A more optimized way of finding prime factors
I've solved Project Euler #3, but solving the same in Hacker Rank which has time constraint of < 4 seconds doesn't work. I've tried using the square root solution for speeding up but it fails.
...
4
votes
1answer
52 views
Project Euler # 22: Names scores
Problem 22, here, asks the following:
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical ...
6
votes
2answers
71 views
Project Euler #19: Counting Sundays in the 20th century using Pandas
Project Euler #19 asks:
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
I'm hoping I wasn't too off course from the spirit of the ...
2
votes
2answers
45 views
“Time Conversion” Python implementation
Problem Statement
You are given time in AM/PM format. Convert this into a 24 hour format.
Note Midnight is \$ 12:00:00AM \$ or \$ 00:00:00 \$ and 12 Noon is \$ 12:00:00PM. \$
Input Format
...
3
votes
2answers
100 views
“Even Tree” Python implementation
Problem Statement
You are given a tree (a simple connected graph with no cycles). You have to remove as many edges from the tree as possible to obtain a forest with the condition that : Each ...
4
votes
3answers
123 views
Project Euler problem 2
This is a question about Project Euler number 2, a relatively easy one. The question is:
Each new term in the Fibonacci sequence is generated by adding the
previous two terms. By starting with ...