Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posible solución en Haskell #19

Merged
merged 2 commits into from
Jun 7, 2017

Conversation

felixgomez
Copy link
Contributor

@felixgomez felixgomez commented May 8, 2017

Pois por aquí unha posible solución en Haskell. Pódese utilizar o Glasgow Haskell Compiler GHCi

O programa calcula todos os posibles subconxuntos que suman cero (ou o cero mesmo).

> ghci Reto.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Reto             ( Reto.hs, interpreted )
Ok, modules loaded: Reto.
*Reto> getSubsetsSumZero [-92474, -61685, -55348, -42019, -35902, -7815, -5579, 4490, 14778, 19399, 34202, 46624, 55800, 57719, 60260, 71511, 75665, 82754]
[[],[-92474,-42019,-35902,-7815,14778,34202,57719,71511]]

Para executar os tests:

> ghci Tests.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling Reto             ( Reto.hs, interpreted )
[2 of 2] Compiling Main             ( Tests.hs, interpreted )
Ok, modules loaded: Main, Reto.
*Main> runTestTT tests
Cases: 20  Tried: 20  Errors: 0  Failures: 0
Counts {cases = 20, tried = 20, errors = 0, failures = 0}

Farei probas de rendemento para ver canto da de sí.

@felixgomez
Copy link
Contributor Author

felixgomez commented May 15, 2017

Por cuestións de rendemento paso a utilizar subsequences do paquete Data.List.

Estou compilando con

ghc --make Reto.hs -O2 -fexcess-precision -optc-O3 -optc-ffast-math -fforce-recomp -threaded

e executando con

./Reto +RTS -N

A detección de núcleos disponibles funciona pero non consigo o rendemento que esperaba. É posible que sexa pola compilación no entorno do Mac. O rendemento da CPU debería ser maior.

reto_vigojug_2_haskell

Tratarei de facer novas probas e completar o reto ;)

@felixgomez
Copy link
Contributor Author

Despois de comprobar cunha máquina Docker o rendemento por forza bruta e equivalente a outras linguaxes que participaron no reto (aprox. 30 iteracións). Todavía non domino Haskell como para facer unha mellora importante no código en pouco tempo, polo que planto aquí ;)

@antonmry
Copy link
Member

Ten moi boa pinta e 30 está moi ben!

@tomasalmeida tomasalmeida merged commit 36b90cc into VigoTech:master Jun 7, 2017
@felixgomez felixgomez deleted the reto_vigojug_210705 branch June 18, 2017 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants