This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome(x): | |
x = str(x) | |
return x == x[::-1] | |
def find_palindromes(m, n): | |
for i in xrange(m, n): | |
for j in xrange(i, n): | |
x = i * j | |
if is_palindrome(x): | |
yield x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://projecteuler.net/problem=4 | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace LargestPalindromeProduct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(100..999).to_a.repeated_permutation(2).collect{|x| x[0] * x[1] if "#{x[0] * x[1]}" == "#{x[0] * x[1]}".reverse }.compact.max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(problem_4). | |
-export([solve/0]). | |
solve() -> | |
List = lists:seq(100, 999), | |
[H | L] = [X * Y || X <- List, | |
Y <- List, | |
integer_to_list(X * Y) =:= lists:reverse(integer_to_list(X * Y))], | |
solve(L, H). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace LargestPrimeFactor | |
{ | |
class Program | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace ConsolesTests | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Largest_prime_factor | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Sieve of Eratosthenes | |
# https://en.wikipedia.org/wiki/Generating_primes | |
import sys | |
def main(): | |
num = int(sys.argv[1]) | |
num_list = [[i,True] for i in range(num)] | |
num_list[0][1] = False | |
num_list[1][1] = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sieve(numbers, n): | |
for i in range(n * 2, len(numbers), n): | |
numbers[i] = False | |
def skip_to_next_prime(numbers, n): | |
n += 1 | |
while n < max and not numbers[n]: | |
n += 1 | |
return n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(l ,ss = 4000000, proc {|p, n, s| p >= l || n >= l ? s : n.even?? ss[n, n + p, s + n] : ss[n, n + p, s] })[1][1, 2, 0] |