From 65161ec1a026ae4f53a05b1fe2a25e65bc8555b8 Mon Sep 17 00:00:00 2001 From: Guido Schweizer Date: Sat, 3 Dec 2022 11:47:03 +0100 Subject: [PATCH] added part2 impl --- aoc-helper-0.1.0.gem | Bin 5632 -> 6144 bytes lib/tasks/new_day.rb | 3 +-- lib/tasks/part_two.rb | 16 ++++++++++++++-- lib/tasks/templates.rb | 20 +++++++++++++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/aoc-helper-0.1.0.gem b/aoc-helper-0.1.0.gem index d6042c4a7454493f497334bad17c179bce539f10..095437213321cd9ded911c3f6fef1ab6e5cc3bd3 100644 GIT binary patch delta 1981 zcmV;u2SWIOEPybOjSx06G&3K z&IwK+g|(1sYfggL@7ulm@_Fyw8PBl6vuN!ho8R>P?RI<3w{8B{Z~5)DW^1z*Yz3{& z<~GR(?d|p&_-jjOMXtCcSH=UxfAkY_xAEr(_aAAsM~xzvjpIZ#P@IA+j?Y;Q`ZD_q zMVKp@h?6i)6iS|UK*<6bOOxYp#MJl+Y;aU#R8&c5q- zg~$g)<;f0@Hrl=3{+pe5AB*oPd`zQHe0vmH?Y>Ggi^bdJoMN7k9) zQWwOsG9KA=okKoEPy;k9xA`P!)tx%T8C-n0Fe(5aD44j8W>L`41j4oXrH(OD7+;yR z6xaD}z?C*~o)s|WLV?QY)!6{&5XZVJr{mMhUL1oS7zA2?TSl{Pe|=5*l@4~nFTE*e z%C$XiXr0olG@nyxmMW9EyFtf{ME}=+_mBUX#eINCa0~vM?O-1N?dJC83jbdl|CZRN z9A6=2R1_2u30(^UuA^``qG!x?-qxUB0E0wOn!dv0ut-&sCW0*NpK&sQR>G-!e`Fff z2GNxFNp3DMOyn)oe=(q>PC}sr#x6Mex%QF%Q}!p82{)!_i6oMvx<+v)^7Wep^ypp3 zm@q<@jhHL$+)*|m=Lk>~QVw1mJrBD-+)q*d#_KD@gYO}w&dz5Q1`qc@`{kyaZtk-2ctU*K*qBb{-3?uNai5mZE_7%YI&5l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5V=HOovW{Q|JQ7GR`371gTXrgKgW2tKU#yJ?|A5BJVSr>lu-S?`0sRjH}3zN>)-#L z=l8!F{EA720>)H%WSX4mBD5QwQB{X@3~$oN+`3CsY~hnZN-WD7Gpd?|kv=&NuUyVM zSL0a7;+9U=S-p(aJ3U7tmE7o7jwSMN)RZXmI7wiF90ip>z%vvJS~rCnBf?rL1$}mk zYIvlVOA{P*VlV95>+oKW^;nPfxO4mm009600|2sF8tniikr6PG5QP{tHvlm-Gc+`-)pW9?$2`exEw;^X13ykEhN^0$9ZW9XHO{3rKO} z60keox%KW8VY4X5Ohz1y2#u!8`((Y(uTS3T4UIy(!+I@T=0V;ySSf&{?r|UOe*utW z+*_sSWa|k>)%vS*1OBg*cN9A-6R%jbQ&gNoYrz2zL4pNtC`RlQyjq|uXG*OV5`<4y z5;_L0P9!YVErSPZ1XR$NyIg5oF#cx`VSh1EAVm?5;xq?o2YBd423HpRLT#TvRjxNH~oIKU>d)Z~a+nMp3E#~-pp PGRxEfvoRCT1d$*NZn2@} diff --git a/lib/tasks/new_day.rb b/lib/tasks/new_day.rb index 337010b..c4c8261 100644 --- a/lib/tasks/new_day.rb +++ b/lib/tasks/new_day.rb @@ -6,7 +6,6 @@ require_relative("templates") def new_day(prompt, day) input = prompt.multiline("Example input").join("") - print input result = prompt.ask("Example result") day_name = "day_#{day}" @@ -19,7 +18,7 @@ def new_day(prompt, day) TTY::File.replace_in_file "#{day_name}/run.rb", /%day_name%/, day_name TTY::File.replace_in_file "#{day_name}/test.rb", /%day_name%/, day_name - TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result%/, result + TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result_1%/, result TTY::File.replace_in_file "#{day_name}/test.rb", /%example_input%/, input puts "Done - run with:" diff --git a/lib/tasks/part_two.rb b/lib/tasks/part_two.rb index 0d6ecb0..010058b 100644 --- a/lib/tasks/part_two.rb +++ b/lib/tasks/part_two.rb @@ -1,5 +1,17 @@ require "tty-prompt" +require "tty-file" +require "ostruct" + +require_relative("templates") def part_two(prompt, day) - prompt.say("part two not yet supported") -end \ No newline at end of file + result = prompt.ask("Part two example result") + + day_name = "day_#{day}" + + TTY::File.copy_file("#{day_name}/impl.rb","#{day_name}/impl_2.rb") + TTY::File.replace_in_file "#{day_name}/test.rb", /example_result_2/, result + + puts "Done - run with:" + puts "ruby #{day_name}/test.rb 2" +end diff --git a/lib/tasks/templates.rb b/lib/tasks/templates.rb index 942f9f6..b59cd88 100644 --- a/lib/tasks/templates.rb +++ b/lib/tasks/templates.rb @@ -1,20 +1,25 @@ TEST_RB = <<~'TEST' -require_relative "impl" +if ARGV[0] == "2" + require_relative "impl_2" + RESULT = example_result_2 +else + require_relative "impl" + RESULT = %example_result_1% +end + INPUT = <<~IN %example_input% IN -RESULT = %example_result% - def test_example parsed = parse(INPUT) result = calculate(parsed) if result == RESULT puts "Test successful. Now run with real input" - puts "ruby %day_name%/run.rb" + puts "ruby %day_name%/run.rb #{ARGV[0]}" else puts "Test failed" puts "expected \"#{RESULT}\" got \"#{result}\"" @@ -25,7 +30,12 @@ test_example TEST RUN_RB = <<~'RUN' -require_relative "impl" +if ARGV[0] == "2" + require_relative "impl_2" +else + require_relative "impl" +end + def print(result) if result.is_a? Array