Skip to content

Instantly share code, notes, and snippets.

@pajaro5
Last active June 28, 2019 00:37
Show Gist options
  • Save pajaro5/1c55116b57edd23b81b33cc1090cdd96 to your computer and use it in GitHub Desktop.
Save pajaro5/1c55116b57edd23b81b33cc1090cdd96 to your computer and use it in GitHub Desktop.
Resuelve el problema 2 de project Euler
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Fibonacci Solver</title>
</head>
<body>
</body>
<script>
var sumaPares = 2;
const MAXIMO = 4000000;
var esPar = function(numero){
if (numero%2 === 0) {
return true;
} else {
return false;
}
}
var generadorFibonacci = function(anterior,ultimo){
if (anterior + ultimo > MAXIMO) {
return sumaPares;
} else {
nuevo = anterior + ultimo;
if(esPar(nuevo)){
sumaPares += nuevo;
}
return generadorFibonacci(ultimo,nuevo);
}
}
//Prueba con numeros de la serie menores a 100
//serie: 1,2,3,5,8,13,21,34,55,89
//suma pares: 44
console.log("suma de pares de serie Fibonacci: " + generadorFibonacci(1,2));
</script>
</html>
@anthony17guty
Copy link

  1. suma de los pares.
    yecto Euler problema 1Python
    numeroprevio=1
    numeroactual=2
    sumatotal=0
    while numeroactual<=4000000:
    if numeroactual%2==0:
    sumatotal+=numeroactual
    temporal=numeroactual
    numeroactual=numeroactual+numeroprevio
    numeroprevio=temporal
    print sumatotal
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    numeroprevio=1
    numeroactual=2
    sumatotal=0
    while numeroactual<=4000000:
    if numeroactual%2==0:
    sumatotal+=numeroactual
    temporal=numeroactual
    numeroactual=numeroactual+numeroprevio
    numeroprevio=temporal
    print sumatotal

  2. Array con los números pares de la serie.
    #include <stdio.h>
    int x,tabla[100];

         for (x=1;x<=100;x++)
         {
     tabla[x]=x;
    

    }

         for (x=1;x<=100;x++)
         {
     printf("%d\n",tabla[x]);
    

    }

    system("PAUSE");
    return 0;
    }

  3. Array con los números impares de la serie.
    int x,cont,z,i,tabla[100];

         i=0;
         for (x=1;x<=100;x++)
         {
     cont=0;
     if (x%2==1)
     {
        tabla[i]=x;
        i++;
     }
    

    }

         for (x=0;x<i;x++)
         {
     printf("%d\n",tabla[x]);
    

    }

    system("PAUSE");
    return 0;

}
4. Array con todos los elementos de la serie.
public class ArraySerie {

public static void main(String[] args) {
   
    Scanner teclado = new Scanner(System.in);
   
    int array [];
   
    System.out.print("Ingrese tamaño del array: ");
    int n = teclado.nextInt();
   
    array = new int [n];
   
    for (int i = 0; i < array.length; i++) {
        if((i+1) % 2 == 0) {
            array [i] = -(i+1);
        }else {
            array [i] = i+1;
        }
        System.out.println(array [i]);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment