Jump to content

The Greplin Programming Challenge


Lukas S.

Recommended Posts

Bem tava a ver um site e vi lá desafio para programadores criando programas que sejam capazes de eles próprios resolverem os problemas deste site

http://challenge.greplin.com/

Gostaria que ao resolvessem colocassem aqui Feito e enviassem as respostas por pm .... E que venham aqui dizer se conseguiram ou não

Edited by Lukas S.

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

isto foi quase tudo à brute force ... pode ser que apareça alguém com tempo para implementar algoritmos mais eficientes

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void printSubString(char * string, int index, int size)
{
   int i;
   for (i = 0; i < size; i++)
       printf("%c", string[i+index]);
}

int fibonacci(int x1, int x2)
{
   return x1 + x2;
}

int isprime(int x) {
   int i;

   for (i = 2; i <= sqrt(x); i++)
   {
       if ((x % i) == 0)
           return 0;
   }
   return 1;
}

int dfs(int array[], int size, int target, int sum, int index)
{
   int i, count = 0;

   for (i = index; i >= 0; i--)
   {
       if (sum + array[i] == target)
           count++;
       else if (sum + array[i] < target)
           count += dfs(array, size, target, sum + array[i], i - 1);
   }

   return count;
}

void exec1()
{
   char * source = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth";
   char * target = NULL;
   int size = strlen(source);
   int s, i, j;

   target = malloc(size + 1);
   for (i = size - 1; i > 0; i--)
       target[size - i] = source[i];
   target[size] = '\0';

   for (s = 10; s > 0; s--)
   {
       for (i = size - s; i > 0; i--)
       {
           for (j = size - s; j > 0; j--)
           {
               if (strncmp(&(source[i]), &(target[j]), s) == 0)
               {
                   printf("exec1 >> found : ");
                   printSubString(source, i, s);
                   printf("\n");
                   free(target);
                   return;
               }
           }
       }
   }

   free(target);
}

void exec2()
{
   int x1 = 0;
   int x2 = 1;

   int s, d, i, found = 0;

   while (!found)
   {
       i = fibonacci(x1, x2);
       x1 = x2;
       x2 = i;

       if (isprime(i) && i > 227000)
           found = 1;
   }

   i += 1;

   s = 0;
   d = 2;
   while (i != 1)
   {
       if (isprime(d) && i % d == 0)
       {
           s += d;
           while (i % d == 0)
               i /= d;
       }
       else
           ++d;
   }

   printf("exec2 >> found : %d\n", s);
}

void exec3()
{
   int array[] = {3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99};
   int size = sizeof(array) / sizeof(int);
   int s, i;

   s = 0;
   for (i = size - 1; i >= 2; i--)
       s += dfs(array, size, array[i], 0, i - 1);

   printf("exec3 >> found : %d\n", s);
}

int main() {
   exec1();
   exec2();
   exec3();
   return 0;
}
Edited by HappyHippyHippo
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Esse código no primeiro nivel e um bocado malsito .... deixo aqui uma solução mais fácil

GfCq8.png

easy

Edited by Lukas S.

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

Já vi.... Alguma vez tinhas exprimentado fazer usando Download da string para uma var?

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

Já vi.... Alguma vez tinhas exprimentado fazer usando Download da string para uma var?

download ?? eu fiz copy paste do que eles apresentaram

estar agora a abrir ligações tcp/ip para pedir um recurso a um servidor http ... uff que trabalheira

Esse código no primeiro nivel e um bocado malsito .... deixo aqui uma solução mais fácil

GfCq8.png

easy

tu não deves estar bem acordado, o código que apresentas-te é exatamente igual ao meu só que em VB ou C# (uma .net qualquer) ... vai dormir antes de dizer esse tipo de coisas ...

Edited by HappyHippyHippo
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

download ?? eu fiz copy paste do que eles apresentaram

estar agora a abrir ligações tcp/ip para pedir um recurso a um servidor http ... uff que trabalheira

tu não deves estar bem acordado, o código que apresentas-te é exatamente igual ao meu só que em VB ou C# (uma .net qualquer) ... vai dormir antes de dizer esse tipo de coisas ...

LooooooooooooL desculpa não tinha visto bem ... sorry é mesmo sono 😉

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.