Project Euler 52: Ruby

Filed under:
|
|
ruby

In my attempt to learn Ruby out in the open, here’s my solution for Project Euler Problem 52

Compared to Problem 51, this problem was a snap. Brute force and pretty quick…

As always, any feedback is welcome.

```# Euler 52
# http://projecteuler.net/index.php?section=problems&id=52
# It can be seen that the number, 125874, and its double,
# 251748, contain exactly the same digits, but in a
# different order.
#
# Find the smallest positive integer, x, such that 2x, 3x,
# 4x, 5x, and 6x, contain the same digits.
timer_start = Time.now

def contains_same_digits?(n)
value = (n*2).to_s.split(//).uniq.sort.join
3.upto(6) do |i|
return false if (n*i).to_s.split(//).uniq.sort.join != value
end

true
end

i = 100_000

i+=1
end

puts "Elapsed Time: #{(Time.now - timer_start)*1000} milliseconds"
```

© Johnny Coder or respective owner

• Programming languages, positional languages and natural languages

as seen on Programmers - Search for 'Programmers'
Some programming languages are modeled on machine code, like assembly languages. Other languages are modeled on a natural language, the English language. Others are not modeled on either machine code or natural language. Languages such as PROLOG, for example, don't follow either model. I came across… >>> More

• Dynamic type languages versus static type languages

as seen on Stack Overflow - Search for 'Stack Overflow'
What are the advantages and limitations of dynamic type languages compared to static type languages? See also: whats with the love of dynamic languages (a far more argumentative thread...) >>> More

• Are Mark Up languages considered programming languages?

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi Are all those markup languages programming languages? For example XML or HTML are programming languages? >>> More

• Managed Languages vs Compiled Language difference?

as seen on Programmers - Search for 'Programmers'
I get confused when people try to make a distinction between compiled languages and managed languages. From experience, I understand that most consider compiled languages to be C,C++ while managed languages are Java,C# (There are obviously more, but these are just few examples). But what exactly is… >>> More

• Advantages of compilers for functional languages over compilers for imperative languages

as seen on Stack Overflow - Search for 'Stack Overflow'
As a follow up to this question What are the advantages of built-in immutability of F# over C#?--am I correct in assuming that the F# compiler can make certain optimizations knowing that it's dealing with largely immutable code? I mean even if a developer writes "Functional C#" the compiler wouldn't… >>> More

• VS2010: Warning on add project reference to Silverlight project from .NET project

as seen on Stack Overflow - Search for 'Stack Overflow'
In VS2010, Silverlight 4, .NET 4, I've got a WCF service and a Silverlight app, and Silverlight is accessing the class not with Add Service Reference but by sharing the contract. Naturally, this means I have the contract in a Silverlight class library, and the service has a project reference to that… >>> More

• Ant calling child project parent project ivy.xml overriding child project ivy.xml

as seen on Stack Overflow - Search for 'Stack Overflow'
We've got a parent project and a child project java builds using ant and ivy. The child project needs to be able to build independently. When the parent project calls the child project the antfile command - the parent project's ivy.xml overrides the child project's ivy.xml Does anyone know how… >>> More

• Project-Based ERP - The Evolution of Project Managemen

as seen on Oracle Blogs - Search for 'Oracle Blogs'
Fred Studer speaks with Ray Wang, Principal Analyst at Forrester Research and Ted Kempf, Senior Director for Oracle's Project Management Solutions about trends in the project management market, where enterprise project management is heading in the next 2 - 3 years and highlights from Ray's new line… >>> More

• How can I setup dependencies for Axis2 / Axiom on Maven2

as seen on Stack Overflow - Search for 'Stack Overflow'
I've tried the following settings on pom.xml to use Axis2 wsdl2code: <dependencies> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>1.5.1</version> </dependency> </dependencies> ... <build> … >>> More

• Project Euler Question 14 (Collatz Problem)

as seen on Stack Overflow - Search for 'Stack Overflow'
The following iterative sequence is defined for the set of positive integers: n -n/2 (n is even) n -3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing… >>> More