project-euler

Beginner syntax issues

SO has frozen for the nth time now trying to ask this question, so third time is a charm? I'm trying to write a rubyish solution to problem 6 in Project Euler, because I have the propensity to write C in other languages. However, this code: sqrsum, sumsqr = 0, 0 (1..100).each { |x| sqrsum, sumsqr += x, x**2 } p (sumsqr - (sqrsum ** 2)) ...

Calculate to sum of 2^1000 without using BigInt

As some of you may notice this question is problem 16 from Project Euler. I have solved it using the new "bigInt" feature of C# 4.0 which was fairly straightforward but which is also not really learning everything I should. I am assuming that since it is 2 ^ 1000 there would be some sort of bit shifting solutions but I can't figure out h...

Finding the largest palindrome of the product of two three digit numbers problem.

Hi, So on Project Euler the Problem 4 states the following: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product of two 3-digit numbers. I have tried the following: #include <stdio.h> ...

How to refactor F# code to not use a mutable accumulator?

The following F# code gives the correct answer to Project Euler problem #7: let isPrime num = let upperDivisor = int32(sqrt(float num)) // Is there a better way? let rec evaluateModulo a = if a = 1 then true else match num % a with | 0 -> false | _ -> evaluateModu...

Fibonacci under 4 millions!

Possible Duplicate: Python program to find fibonacci series. More Pythonic way. Hey, i was trying to write a script which sums all the even terms in "Fibonacci Sequence" under 4 millions. Fibonacci1 = 1 Fibonacci2 = 2 a = 2 i = 4 for i in range(1,4000000): Fibonacci1 = Fibonacci1 + Fibonacci2 if Fibonacci1 % 2 == 0: a = a...

Performance of "all" in haskell

I got nearly no knowledge of haskell and tried to solve some Project Euler Problems. While solving Number 5 I wrote this solution (for 1..10) --Check if n can be divided by 1..max canDivAll :: Integer -> Integer -> Bool canDivAll max n = all (\x -> n `mod` x == 0) [1..max] main = print $ head $ filter (canDivAll 10) [1..] Now I fo...

Understanding some math relating to Euler #12

Note that this question contains some spoilers. A solution for problem #12 states that "Number of divisors (including 1 and the number itself) can be calculated taking one element from prime (and power) divisors." The (python) code that it has doing this is num_factors = lambda x: mul((exp+1) for (base, exp) in factorize(x)) (whe...

C++ - How to work with BIG numbers?

Possible Duplicates: BigInt in C? How to implement big int in C++ How do we work with big numbers without making use of external libraries and functions? Some problems are as follows: What is the sum of the digits of the number 21000? Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. ...

Delete an item from a list

Hey, I was trying to delete an item form a list (without using set): list1 = [] for i in range(2,101): for j in range(2,101): list1.append(i ** j) list1.sort() for k in range(1,len(list1) - 1): if (list1[k] == list1[k - 1]): list1.remove(list1[k]) print "length = " + str(len(list1)) The set function works fine,...

Algorithmic Issue in MIPS

I'm rewriting my answer(s) to Project Euler questions in MIPS assembly, and I can't get this one to output the correct answer. I've gone over the code for the past hour, and I can't figure out what's wrong with my approach (as I am getting 33165 when the answer is a cool 200,00+ higher than that), so I figure the problem must be my shaki...

Subroutines in MIPS and other beginner silliness

I'm using Project Euler to learn MIPS, specifically using Problem 6 to learn how to use a subroutine. Unfortunately, I am doing something very wrong because my answer that I'm getting is far too large in magnitude. Is my problem here with how I am using the subroutine, or is it something else entirely? ## p6.asm ## ## Andrew Levenson, 2...

Making solution for Project Euler more efficient.

Hey everyone, Originally, I was having some issues getting this code to function, but after a little tweaking I got it debugged and ready to go. I have gone through several revisions of this program. I started with integer values only to find that the number was too large to fit into an int. I then changed to BigIntegers, which proved ...

Project euler problem in python (problem 53)

So I'm learning python so I'm going through some project euler problems. And I'm not sure if this is a python problem I'm having, or just me being retarded, but I seem to be getting the wrong answer for problem 53. Here's a link to the problem http://projecteuler.net/index.php?section=problems&amp;id=53 and this is my code: from math...

I've heard that some "break"s aren't bad practice. What about this one?

Hey everyone, I have often heard that using breaks in Java is considered bad practice, but after reading some threads on Stack Overflow, I've seen otherwise. Many say that it is acceptable in certain cases. I'm a little confused as to what is/isn't bad practice in this case. For Project Euler: Problem 7, I've constructed the code belo...

Project Euler: Problem 1 (Possible refactorings and run time optimizations)

I have been hearing a lot about Project Euler so I thought I solve one of the problems in C#. The problem as stated on the website is as follows: 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 of 3 or 5 be...

Memoization & Project Euler Problem 15 in Haskell

I've been learning some Haskell, and doing project Euler problems as I go. I'm not really bothered about the answer to the Euler Problem (which I can happily brute force, or do it in some other language), but the method. I'm stuck on doing Problem 15 in reasonable time. It asks for the number of non-backtracking routes from top-left to ...

[Python/Project Euler]Problem 41

Hey, I am trying to solve problem 41, but i don't know why my code stops at 987654319: def IsPandigital(No): a = sorted(str(No)) for i in range(1,10): if a[i - 1] != str(i): return False return True def IsPrime(No): i = 2 while i < No: if No % i == 0: return False i += 1 return True i = 987654321 while i > 0: print i ...

Need help optimizing solution for Project Euler problem #12.

Hey everyone, I've been having my fun with Project Euler challenges again and I've noticed that my solution for number 12 is one of my slowest at ~593.275 ms per runthrough. This is second to my solution for number 10 at ~1254.593 ms per runthrough. All of my other answers take less than 3 ms to run with most well under 1 ms. My Java s...

Haskell doubt: how to transform a Matrix represented as: [String] to a Matrix Represented as [[Int]] ?

Im trying to solve Problem 11 of Project Euler in haskell. I almost did it, but right now im stuck, i want to transform a Matrix represented as [String] to a Matrix represented as [[Int]]. I "drawed" the matrices: What i want: "08 02 22 97 38 15 00 40 [ ["08","02","22","97","38","15","00","40"], [[08,02...

Double precision in C++ (or pow(2, 1000))

I'm working on Project Euler to brush up on my C++ coding skills in preparation for the programming challenge(s) we'll be having this next semester (since they don't let us use Python, boo!). I'm on #16, and I'm trying to find a way to keep real precision for 2¹°°° For instance: int main(){ double num = pow(2, 1000); printf("...