Skip to content

Instantly share code, notes, and snippets.

@johannesE
Last active December 13, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johannesE/0cbbb93b3e509846fc600cf3331a5e8c to your computer and use it in GitHub Desktop.
Save johannesE/0cbbb93b3e509846fc600cf3331a5e8c to your computer and use it in GitHub Desktop.
elixir meetup input string
237369991482346124663395286354672985457326865748533412179778188397835279584149971999798512279429268727171755461418974558538246429986747532417846157526523238931351898548279549456694488433438982744782258279173323381571985454236569393975735715331438256795579514159946537868358735936832487422938678194757687698143224139243151222475131337135843793611742383267186158665726927967655583875485515512626142935357421852953775733748941926983377725386196187486131337458574829848723711355929684625223564489485597564768317432893836629255273452776232319265422533449549956244791565573727762687439221862632722277129613329167189874939414298584616496839223239197277563641853746193232543222813298195169345186499866147586559781523834595683496151581546829112745533347796213673814995849156321674379644323159259131925444961296821167483628812395391533572555624159939279125341335147234653572977345582135728994395631685618135563662689854691976843435785879952751266627645653981281891643823717528757341136747881518611439246877373935758151119185587921332175189332436522732144278613486716525897262879287772969529445511736924962777262394961547579248731343245241963914775991292177151554446695134653596633433171866618541957233463548142173235821168156636824233487983766612338498874251672993917446366865832618475491341253973267556113323245113845148121546526396995991171739837147479978645166417988918289287844384513974369397974378819848552153961651881528134624869454563488858625261356763562723261767873542683796675797124322382732437235544965647934514871672522777378931524994784845817584793564974285139867972185887185987353468488155283698464226415951583138352839943621294117262483559867661596299753986347244786339543174594266422815794658477629829383461829261994591318851587963554829459353892825847978971823347219468516784857348649693185172199398234123745415271222891161175788713733444497592853221743138324235934216658323717267715318744537689459113188549896737581637879552568829548365738314593851221113932919767844137362623398623853789938824592
defmodule Day1 do
@input "36743676522426214741687639282183216978128565594112364817283598621384839756628424146779311928318383597235968644687665159591573413233616717112157752469191845757712928347624726438516211153946892241449523148419426259291788938621886334734497823163281389389853675932246734153563861233894952657625868415432316155487242813798425779743561987563734944962846865263722712768674838244444385768568489842989878163655771847362656153372265945464128668412439248966939398765446171855144544285463517258749813731314365947372548811434646381595273172982466142248474238762554858654679415418693478512641864168398722199638775667744977941183772494538685398862344164521446115925528534491788728448668455349588972443295391385389551783289417349823383324748411689198219329996666752251815562522759374542652969147696419669914534586732436912798519697722586795746371697338416716842214313393228587413399534716394984183943123375517819622837972796431166264646432893478557659387795573234889141897313158457637142238315327877493994933514112645586351127139429281675912366669475931711974332271368287413985682374943195886455927839573986464555141679291998645936683639162588375974549467767623463935561847869527383395278248952314792112113126231246742753119748113828843917812547224498319849947517745625844819175973986843636628414965664466582172419197227695368492433353199233558872319529626825788288176275546566474824257336863977574347328469153319428883748696399544974133392589823343773897313173336568883385364166336362398636684459886283964242249228938383219255513996468586953519638111599935229115228837559242752925943653623682985576323929415445443378189472782454958232341986626791182861644112974418239286486722654442144851173538756859647218768134572858331849543266169672745221391659363674921469481143686952478771714585793322926824623482923579986434741714167134346384551362664177865452895348948953472328966995731169672573555621939584872187999325322327893336736611929752613241935211664248961527687778371971259654541239471766714469122213793348414477789271187324629397292446879752673" |> String.graphemes() |> Enum.map(&String.to_integer/1)
def addFirstToList(list = [first | _rest]), do: list ++ [first]
# def do_the_magic([], sum) do
# sum
# end
def do_the_magic([_x], sum) do
sum
end
def do_the_magic([e1, e1| rest], sum) do
do_the_magic([e1|rest], sum + e1)
end
def do_the_magic([_e1| list], sum) do
do_the_magic(list, sum)
end
def run() do
@input |> addFirstToList() |> Day1.do_the_magic(0)
end
end
@stoch
Copy link

stoch commented Dec 13, 2017

Solution Erlang:

-module(day1).
-compile([export_all]).

calc(Text) -> calculate(Text ++ [hd(Text)],0).

calculate([], Sum) -> Sum;
calculate([], Sum) -> Sum;
calculate([H1,H1|Rest], Sum) -> calculate([H1|Rest], Sum+H1-$0);
calculate([
|Rest], Sum) -> calculate(Rest, Sum).

% timer:tc(fun() -> [ day1:calc(T)|| _ <- lists:seq(1,1000000)] end).

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