Exemplo n.º 1
0
def problem_4():
  print("\nVous avez sélectionné le problème suivant :")
  print("-----------------------------------")
  print("Quel est le plus grand palindrome que l'on peut obtenir en multipliant un nombre de x chiffres avec un nombre de y chiffres ?")
  print("===================================\n")
  
  digit1 = utilities.check_input("Veuillez entrer le premier nombre de chiffres : ")
  digit2 = utilities.check_input("Veuillez entrer le deuxième nombre de chiffres : ")

  # Get the greatest number in the range of the digit (example : if digit = 3, max = 999)
  greatest1 = utilities.greatest_number(digit1)
  greatest2 = utilities.greatest_number(digit2)

  palindrome = 0

  # Multiplication till a palindrome is found
  for number1 in range(greatest1, -1, -1):
    for number2 in range(greatest2, -1, -1):
      resultat = number1*number2

      # Check if it's a palindrome
      if(utilities.is_palindrome(resultat)):
        if(resultat > palindrome):
          palindrome = resultat

  print("Le nombre suivant est un palindrome : {}".format(palindrome))
Exemplo n.º 2
0
def main():
    n = 0
    for i in range(100, 1000):
        for j in range(i, 1000):
            sum = i * j
            if utilities.is_palindrome(sum) and sum > n:
                n = sum
    return n
Exemplo n.º 3
0
 def test_palindrome(self):
     self.assertTrue(is_palindrome('kayak'))
     self.assertFalse(is_palindrome('not a palindrome'))
Exemplo n.º 4
0
# 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.
from utilities import is_palindrome

products = []

for x in range(100, 1000):
    for y in range(100, 1000):
        products.append(x * y)

products.sort()
products = reversed(products)

for product in products:
    if is_palindrome(product):
        print(product)
        exit(0)
Exemplo n.º 5
0
from utilities import is_palindrome

palindromes = [(x*y, x, y)
    for x in range(1000) 
    for y in range(1000) 
    if is_palindrome(x*y)]

print sorted(palindromes)
Exemplo n.º 6
0
# The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.
#
# Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
#
# (Please note that the palindromic number, in either base, may not include leading zeros.)
from utilities import is_palindrome, to_binary_string

cumulative_sum = 0

for i in range(1000000):
    if is_palindrome(i):
        if is_palindrome(to_binary_string(i)):
            cumulative_sum += i

print(cumulative_sum)
Exemplo n.º 7
0
#
# Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is 4994.
#
# How many Lychrel numbers are there below ten-thousand?
#
# NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.

from utilities import is_palindrome

num_lychrel = 0


def reverse_int(num: int) -> int:
    str_num = str(num)
    return int(str_num[::-1])


for i in range(1, 10000):
    candidate = i
    lychrel = True
    for j in range(50):
        candidate = candidate + reverse_int(candidate)
        if is_palindrome(candidate):
            # This is not a Lychrel number
            lychrel = False
            break
    if lychrel:
        num_lychrel += 1

print(num_lychrel)