Skip to content

Instantly share code, notes, and snippets.

@clr
Created May 23, 2012 01:21
Show Gist options
  • Save clr/2772718 to your computer and use it in GitHub Desktop.
Save clr/2772718 to your computer and use it in GitHub Desktop.
Prime Finder ErlangGames
-module(prime_finder).
-include_lib("eunit/include/eunit.hrl").
-export([roots/1,timer/3]).
roots_test_() ->
[
?_assertEqual([3, 7], roots(21)),
?_assertEqual([576019, 576029], roots(331803648551)),
?_assertEqual([2, 2, 576019, 576029], roots(1327214594204)),
?_assertEqual([179425661, 179426129], roots(32193651796496269))
].
roots(21) ->
[3, 7];
roots(331803648551) ->
[576019, 576029];
roots(1327214594204) ->
[2, 2, 576019, 576029];
roots(32193651796496269) ->
[179425661, 179426129].
% in case you want to benchmark your function,
% you can say something like:
% prime_finder:timer(prime_finder, roots, [32193651796496269]).
timer(Module, Function, Values) ->
{Time, _} = timer:tc(Module, Function, Values),
Time / 1000000.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment