# Tag Info

Accepted

### Project Euler #7 10001st prime

bool isPrime = true; for (int j = 2; j < i / 2; j++) { if (i%j != 0) continue; isPrime = false; break; } if (!isPrime) continue; This is one of the ...
• 25.2k
Accepted

### 100 gunmen in a circle kill next person

1. Encapsulate Writing code at the top level of a module makes it hard to test the code and hard to measure its performance. It's best to encapsulate code in a function. Accordingly, I'd write: <...
• 49.2k
Accepted

### Project Euler Problem 45

Arithmetic Project Euler questions are meant to educate you about both mathematics and programming. It would be a good idea to understand what these triangular, pentagonal, and hexagonal numbers ...
• 142k

### Writing nested for loops to produce certain output

You're not breaking up the patterns in the most logical way. Each line just consists of repeating blocks of three characters. ...
• 142k
Accepted

### Determining if the kangaroos will land in the same position

Closed form solution A better approach is to calculate the intercept point directly and then check whether or not it is an integer. The time of intercept is: $$t = \frac{x_2 - x_1}{v_1 - v_2}$$ ...
• 2,242
Accepted

### Finding pairs of Amicable Numbers, up to 10000

printf("|---------- PROGRAM FOR AMICABLE NUMBERS.----------|"); This kind of banner message makes it harder to use the output of your program in a ...
• 57.9k

### Beehive numbers - using goto in C++

Your use of goto is wholly unjustified, not just because goto is taboo, but because your code has flow-of-control that is hard ...
• 142k
Accepted

### Project Euler Problem #4 - Palindromic number

The other answers are all giving you different ways to reorganize your loops. They're all not bad in their own way, but the better solution in C# is to not write any loops in the first place. Your ...
• 14.6k
Accepted

### Checking for balanced brackets in Python

Review Your implementation is quite good, but ofcourse there are always some things that can be improved upon. Use a if __name__ == '__main__' guard, see what ...
• 11.4k
Accepted

### Project Euler 001 in C++

constexpr everything Apart from the #define, your code is quite good. But you miss on a really simple optimization by not using ...
• 5,687
Accepted

### Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R

TL;DR: Just use PyPy; it gets you to about 10x the time of C++. If you really want to use CPython, a lot of clever optimizations (not algorithm changes) gets you as fast as PyPy and then using Numpy ...
• 9,533
Accepted

### Printing 1,000,000 numbers in 1 sec. in Python

Nice solution, few suggestions: Printing the numbers one by one might be the issue. Generate the list of numbers first and then call print only once. The case <...
• 5,487

### Project Euler 001 in C++

I am not focussing on the algorithm, but more on C++ idioms. Very good statement of what you want out of this. Great! I suggest you familiarize yourself with the Core Guidelines being cataloged by ...
• 11.1k
Accepted

### Prime numbers that are also a prime number when reversed

Name Classes properly. What is a "Back Wards Prime"? I have no idea. I can guess what a Backward Prime is; perhaps you need to change the capitalization of the class! I'm told that name is ...
• 30.7k
Accepted

### "Longest Collatz sequence" in C slower than in Python 3

Assuming int is 32 bit long on your system, an integer overflow occurs on c with upper = 1000000. The multiplication in ...
• 376
Accepted

### What does the Bob say?

Avoid if chains with enumerations You are using an enumeration for all the possible responses of Bob. This is a great idea, and you can take it a step further. ...
• 9,195
Accepted

### Check if a string has all unique characters

People are very eager to present their own solutions, so let me attempt an actual review of your code: Your names could be clearer. Strings is not very descriptive,...
• 4,452
Accepted

### HackerRank Implement Queue using two stacks Solution

Algorithmic complexity for combined operations Containers are interesting elements in most programming languages: they have an internal state, namely their elements and therefore their size. This ...
• 18.8k
Accepted

### LOL'ing-Up Project Euler One

Same Guy, Same Language, same criticism? Let me start by (again) critzising your variable casing choice of SHOUTCASE It's so darn hard to tell what's a variable and what's not :( But your names got ...
• 25k
Accepted

### Google Foobar Challenge: Lucky Triples

1. Testing Let's take a look at your second problem: I've tested it on rather trivial cases, but have no way of knowing [...] if it returns the correct answer in more intricate examples A good ...
• 49.2k
Accepted

### Perm-Missing-Elem: 100% functional score, but only 60% performance

@chillworld is correct in his observation that the issue is related to the int overflow causing the problems in the performance tests. The more accurate solution to this is to use a ...
• 96.7k
Accepted

### Duplicate like a weapon, arrays like heaven

@tim suggested a way to do this with less memory by sorting the array. There's another way to do it with less memory without needing to sort. Let's say that $k$ is the duplicate value in the array. ...
• 16.1k
Accepted

### Find the next multiple of N that is a perfect square number

I'm afraid we need to use… math. Take any square number and look at its prime factorization. For example, $100 = 2^2·5^2$; $144 = 2^4·3^2$; $729 = 3^6$. The thing that's common to all of ...
• 49.2k

### Python 3 function to rotate an image 90°

You can use NumPy module that's good with arrays and matrices. It has a built-in for exactly that purpose - ...
• 886
Accepted

### Project Euler #1 in C++

The code is basically fine. The if condition is perhaps a little complicated though. To interpret it you have to read "if not ((i is not a multiple of 3) and (i is not a multiple of 5))", ...
• 11k
Accepted

### Project Euler -problem 1

This is not a hack. if( ( i % 3 == 0 ) || ( i % 5 == 0 ) || ( ( i % 3 == 0 ) && ( i % 5 == 0 ) ) ) What you have here is essentially: ...
• 58.1k

### Project Euler #1: Multiples of 3 and 5

You don't need iteration at all for this problem. Consider; the sum of all numbers from 1 to n is equal to n*(n+1)/2. Also the sum of all numbers less than n that divides d equals d times the sum of ...
• 990
Accepted

### Find largest prime factor

The problem is: What is the largest prime factor of the number 600851475143? Your solution has a function named lpf, which computes the complete prime ...
• 18.3k