From 3aa75a89a388e7d4c05b9599bae1fe5ad015292d Mon Sep 17 00:00:00 2001 From: Viacheslav Slinko Date: Sat, 21 Dec 2024 23:56:18 +0300 Subject: [PATCH] day21 --- luts/day21_1.bin | Bin 0 -> 8000 bytes luts/day21_2.bin | Bin 0 -> 8000 bytes src/day21.rs | 286 ++--------------------------------------------- 3 files changed, 9 insertions(+), 277 deletions(-) create mode 100644 luts/day21_1.bin create mode 100644 luts/day21_2.bin diff --git a/luts/day21_1.bin b/luts/day21_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..adafed2b4f0f593769ffbe7bb09d6a3460f48b94 GIT binary patch literal 8000 zcmZ9Re^gs%8OLuKV;RdB>$1vN*JWMYu){8P*dk)RVyv+u;)aT>YOGkX=2TX(!-_Sl zwMN8>6*1O|v0{yg7?I7`gLsQr5pl+fl~b{%h&3YOwIX80>N$Qt_aFPur_b{~@AE#t z-uLFThM_-IFa%G*!ZrHKHRM|4c^HTJIWm}o7hv!P>5sucuH+;%Zj@XL$Kbj==|k9! zp!XuXkZtT{kcW_SUD`j6Jam)f6}bOq$p&1;ZZ2Q?Mi^w>=a#;di1bQ1L3uGU_#|0iNA$H`Ej$aAG;>>?RRLsX{}gsyJ&dC z3G~hEU%gZM6zg@Y*P*X|j@BdV#54>RNp5D{f(7jB!0rOH@atxu54%0kMn8{S%DxBg z(m5IOm?6$u^fUKp-L+mUDHf+Uh*!}YcS~M-uUN#seVmhk>z=FiAp5U-B^wWl*V#Y5 zQSx$$Xx%6F_{0VB86clH^|=5~5|8D?M?5ABbN&DS zXAtjB@{1zRlb08L0r4zsk{=KI3-Py9D!rTa1@aAY{><~VZsWI{{Ta^N%{jgB5Ps~3 zw67BXe)QQ#q_5p9_P}BEPTm>zZ`mfhEOv`qBwK#*M7dbJ`!-ewk>#M65!;f_)8jj?k|q>^;O=L_AT>Y2o}1&M$eT{5tu# zw@VJQuNeOc_RYf?;+dizUg8NmtdgHI(4=2Sse5vx*3;-M&Kr8Z^ktk|O+A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Oj56gKTGz^io0R_hmxZ|7t^r$kCJ1=H4km-SCXUiywqhMtmb@+`o^c^XJfwX zUBtEFZ_;=EL2SQ;^=pz3Qm1&H^!b06KJtCBm%basQ9UPp+Zl0kQZ&wrCXD@5vW0AL zU#@V!1H4m*V9}3dzlpeP>RCP`y_Y_XBNx(7n|PyxvfIl%_~~!Q4a%$buUdC8chOww zE10JY`knugU6#4e<32`CNncMrs)?_0QTjx&{58?KG&L)V711K911GUhYGR`LH}Xf0B61#^kr^e(6o(>LKnn z=G9Mp8SYOh^XR=@`^Jz9sbewo<6%A;pv8RW6899pe+qa{)94Q)55oca5|1g~F5b-+ z-jRdEo#Eb9T#;QPai_?`;Qgqkt{u$JNxoB7Li>6jR9?>eyTUt_d|3KM@|k0f$G1rz zT+#j+<|F0weH^_{`V9BlM?cE%mVQ6)Zj}BOJ|z7r`KIVcB&#?l$SX=-6})R+ z=4gUGdY_iPhxfp_$Lq=0!@L#I4?p*#1={FWkxlMN19g}o|6=EzV4f?vkEP_f4|;vd u>nd^??`sYHNOE5$sY9IKNdfXU`Cj{ZS69%_qPNh`URK_z3DNoYjsF7wZ>Bi_ literal 0 HcmV?d00001 diff --git a/luts/day21_2.bin b/luts/day21_2.bin new file mode 100644 index 0000000000000000000000000000000000000000..e1219a0e3745ed786dd18ab02345016894b2eff0 GIT binary patch literal 8000 zcmXAsc_7r?+r}qb)<_76$(CdpyCe+>NhKsj6Dp>7WXn>PNwTF<2}K&Bl!`KhMh#K+ zy|N|AmSiajsoraT@AJ>~oX8U+s3Njj10e1Jzn1ewOwM&{ehAX z`p5_^BM{7gP%8|e{D%UH4@2pzoLMKKtz}mdPD4rWrUmap1J`>q7*OhaT~AwRocX28 z_n=m7ReU;7S&GDmD5x!Qr79N(f#CGX`pr|U4M_!0r=dya_66qPT|9+9MzEHcaph3O zdg7*4>T#&WtyfPNP{Q9NQa*HGWKxtHN}~s8D{&GC?rZe~q@jh&_c05=6KZ@+ys@^O zZIGrwvuk+-zkp8{B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MQ90!F{se4nPkHE=@I*?S@2 z)_aL*i^!8^wORiv`kd6HeX|Ju@^U*FP;gd6-)c`>3)q4BJ>1%zVo(S9KZDXC z?01by721;VeJm2%&F+t?S$xTMtSx`_9;Tq;E9z+u~Xn8=l4xC z!_MY@N#!^6d!RftA{%ooI<3UR4Zk7F|6W>#{3dh;w{F5*xW+$u8IHLST&-EU9h_yZ zFX9J&RnM-d9NatE&FmcPwDawf7E#Caj#W$_^oO~Ja<~cKGu}LhUlO?YNq4^Rc${b1 zYO~Jad!DJ;c+e4?njte(18x%N>RHVG&Zqb5u>0xL)8M3!{fXyl<@?b0s`7!lVw@YO z;cH08?}e^grxg3%NM~0x-obsh2QNsSMSV_1l7T-^*W$*r0()VnSQI+>75j{h;wCfb zFVU#s({c1;>1@DIICOrm_pt)Zw@9^{WGd!ZC0<(I3H7NSk#d-F!0*7V2%X#LZ{h7U z0~z?GRh>7dW8Z`J`BV?)qLi1iq=h&t8NnWj;F4#Ai(}dSenI2yMgOgoa&;r{J)Tt! z-qMOVNeO-9>)k8Z3`Iu310ZOq;NUT%P+hxGs2o~%s52F Oe9;ewZ{A5H5dIH`MlnqQ literal 0 HcmV?d00001 diff --git a/src/day21.rs b/src/day21.rs index 58cadf5..ac72909 100644 --- a/src/day21.rs +++ b/src/day21.rs @@ -1,288 +1,20 @@ -const fn numeric_keypad_index(from: u8, to: u8) -> usize { - // 18 is minimum multiplier that provides a unique index for each pair of buttons - (from as usize) - 48 + ((to as usize) - 48) * 18 -} - -const LUT_SIZE: usize = numeric_keypad_index(b'A', b'A') + 1; - -const LUT1: [u64; LUT_SIZE] = { - let mut lut = [0; LUT_SIZE]; - - lut[numeric_keypad_index(b'0', b'0')] = 1; - lut[numeric_keypad_index(b'0', b'1')] = 25; - lut[numeric_keypad_index(b'0', b'2')] = 12; - lut[numeric_keypad_index(b'0', b'3')] = 19; - lut[numeric_keypad_index(b'0', b'4')] = 26; - lut[numeric_keypad_index(b'0', b'5')] = 13; - lut[numeric_keypad_index(b'0', b'6')] = 20; - lut[numeric_keypad_index(b'0', b'7')] = 27; - lut[numeric_keypad_index(b'0', b'8')] = 14; - lut[numeric_keypad_index(b'0', b'9')] = 21; - lut[numeric_keypad_index(b'0', b'A')] = 10; - lut[numeric_keypad_index(b'1', b'0')] = 21; - lut[numeric_keypad_index(b'1', b'1')] = 1; - lut[numeric_keypad_index(b'1', b'2')] = 10; - lut[numeric_keypad_index(b'1', b'3')] = 11; - lut[numeric_keypad_index(b'1', b'4')] = 12; - lut[numeric_keypad_index(b'1', b'5')] = 19; - lut[numeric_keypad_index(b'1', b'6')] = 20; - lut[numeric_keypad_index(b'1', b'7')] = 13; - lut[numeric_keypad_index(b'1', b'8')] = 20; - lut[numeric_keypad_index(b'1', b'9')] = 21; - lut[numeric_keypad_index(b'1', b'A')] = 22; - lut[numeric_keypad_index(b'2', b'0')] = 16; - lut[numeric_keypad_index(b'2', b'1')] = 18; - lut[numeric_keypad_index(b'2', b'2')] = 1; - lut[numeric_keypad_index(b'2', b'3')] = 10; - lut[numeric_keypad_index(b'2', b'4')] = 21; - lut[numeric_keypad_index(b'2', b'5')] = 12; - lut[numeric_keypad_index(b'2', b'6')] = 19; - lut[numeric_keypad_index(b'2', b'7')] = 22; - lut[numeric_keypad_index(b'2', b'8')] = 13; - lut[numeric_keypad_index(b'2', b'9')] = 20; - lut[numeric_keypad_index(b'2', b'A')] = 17; - lut[numeric_keypad_index(b'3', b'0')] = 21; - lut[numeric_keypad_index(b'3', b'1')] = 19; - lut[numeric_keypad_index(b'3', b'2')] = 18; - lut[numeric_keypad_index(b'3', b'3')] = 1; - lut[numeric_keypad_index(b'3', b'4')] = 22; - lut[numeric_keypad_index(b'3', b'5')] = 21; - lut[numeric_keypad_index(b'3', b'6')] = 12; - lut[numeric_keypad_index(b'3', b'7')] = 23; - lut[numeric_keypad_index(b'3', b'8')] = 22; - lut[numeric_keypad_index(b'3', b'9')] = 13; - lut[numeric_keypad_index(b'3', b'A')] = 16; - lut[numeric_keypad_index(b'4', b'0')] = 22; - lut[numeric_keypad_index(b'4', b'1')] = 16; - lut[numeric_keypad_index(b'4', b'2')] = 17; - lut[numeric_keypad_index(b'4', b'3')] = 18; - lut[numeric_keypad_index(b'4', b'4')] = 1; - lut[numeric_keypad_index(b'4', b'5')] = 10; - lut[numeric_keypad_index(b'4', b'6')] = 11; - lut[numeric_keypad_index(b'4', b'7')] = 12; - lut[numeric_keypad_index(b'4', b'8')] = 19; - lut[numeric_keypad_index(b'4', b'9')] = 20; - lut[numeric_keypad_index(b'4', b'A')] = 23; - lut[numeric_keypad_index(b'5', b'0')] = 17; - lut[numeric_keypad_index(b'5', b'1')] = 21; - lut[numeric_keypad_index(b'5', b'2')] = 16; - lut[numeric_keypad_index(b'5', b'3')] = 17; - lut[numeric_keypad_index(b'5', b'4')] = 18; - lut[numeric_keypad_index(b'5', b'5')] = 1; - lut[numeric_keypad_index(b'5', b'6')] = 10; - lut[numeric_keypad_index(b'5', b'7')] = 21; - lut[numeric_keypad_index(b'5', b'8')] = 12; - lut[numeric_keypad_index(b'5', b'9')] = 19; - lut[numeric_keypad_index(b'5', b'A')] = 18; - lut[numeric_keypad_index(b'6', b'0')] = 22; - lut[numeric_keypad_index(b'6', b'1')] = 22; - lut[numeric_keypad_index(b'6', b'2')] = 21; - lut[numeric_keypad_index(b'6', b'3')] = 16; - lut[numeric_keypad_index(b'6', b'4')] = 19; - lut[numeric_keypad_index(b'6', b'5')] = 18; - lut[numeric_keypad_index(b'6', b'6')] = 1; - lut[numeric_keypad_index(b'6', b'7')] = 22; - lut[numeric_keypad_index(b'6', b'8')] = 21; - lut[numeric_keypad_index(b'6', b'9')] = 12; - lut[numeric_keypad_index(b'6', b'A')] = 17; - lut[numeric_keypad_index(b'7', b'0')] = 23; - lut[numeric_keypad_index(b'7', b'1')] = 17; - lut[numeric_keypad_index(b'7', b'2')] = 18; - lut[numeric_keypad_index(b'7', b'3')] = 19; - lut[numeric_keypad_index(b'7', b'4')] = 16; - lut[numeric_keypad_index(b'7', b'5')] = 17; - lut[numeric_keypad_index(b'7', b'6')] = 18; - lut[numeric_keypad_index(b'7', b'7')] = 1; - lut[numeric_keypad_index(b'7', b'8')] = 10; - lut[numeric_keypad_index(b'7', b'9')] = 11; - lut[numeric_keypad_index(b'7', b'A')] = 24; - lut[numeric_keypad_index(b'8', b'0')] = 18; - lut[numeric_keypad_index(b'8', b'1')] = 22; - lut[numeric_keypad_index(b'8', b'2')] = 17; - lut[numeric_keypad_index(b'8', b'3')] = 18; - lut[numeric_keypad_index(b'8', b'4')] = 21; - lut[numeric_keypad_index(b'8', b'5')] = 16; - lut[numeric_keypad_index(b'8', b'6')] = 17; - lut[numeric_keypad_index(b'8', b'7')] = 18; - lut[numeric_keypad_index(b'8', b'8')] = 1; - lut[numeric_keypad_index(b'8', b'9')] = 10; - lut[numeric_keypad_index(b'8', b'A')] = 19; - lut[numeric_keypad_index(b'9', b'0')] = 23; - lut[numeric_keypad_index(b'9', b'1')] = 23; - lut[numeric_keypad_index(b'9', b'2')] = 22; - lut[numeric_keypad_index(b'9', b'3')] = 17; - lut[numeric_keypad_index(b'9', b'4')] = 22; - lut[numeric_keypad_index(b'9', b'5')] = 21; - lut[numeric_keypad_index(b'9', b'6')] = 16; - lut[numeric_keypad_index(b'9', b'7')] = 19; - lut[numeric_keypad_index(b'9', b'8')] = 18; - lut[numeric_keypad_index(b'9', b'9')] = 1; - lut[numeric_keypad_index(b'9', b'A')] = 18; - lut[numeric_keypad_index(b'A', b'0')] = 18; - lut[numeric_keypad_index(b'A', b'1')] = 26; - lut[numeric_keypad_index(b'A', b'2')] = 21; - lut[numeric_keypad_index(b'A', b'3')] = 12; - lut[numeric_keypad_index(b'A', b'4')] = 27; - lut[numeric_keypad_index(b'A', b'5')] = 22; - lut[numeric_keypad_index(b'A', b'6')] = 13; - lut[numeric_keypad_index(b'A', b'7')] = 28; - lut[numeric_keypad_index(b'A', b'8')] = 23; - lut[numeric_keypad_index(b'A', b'9')] = 14; - lut[numeric_keypad_index(b'A', b'A')] = 1; - - lut -}; +use std::mem::transmute; -const LUT2: [u64; LUT_SIZE] = { - let mut lut = [0; LUT_SIZE]; - - lut[numeric_keypad_index(b'0', b'0')] = 1; - lut[numeric_keypad_index(b'0', b'1')] = 31420065369; - lut[numeric_keypad_index(b'0', b'2')] = 14752615084; - lut[numeric_keypad_index(b'0', b'3')] = 24095973437; - lut[numeric_keypad_index(b'0', b'4')] = 31420065370; - lut[numeric_keypad_index(b'0', b'5')] = 14752615085; - lut[numeric_keypad_index(b'0', b'6')] = 24095973438; - lut[numeric_keypad_index(b'0', b'7')] = 31420065371; - lut[numeric_keypad_index(b'0', b'8')] = 14752615086; - lut[numeric_keypad_index(b'0', b'9')] = 24095973439; - lut[numeric_keypad_index(b'0', b'A')] = 14287938116; - lut[numeric_keypad_index(b'1', b'0')] = 27052881363; - lut[numeric_keypad_index(b'1', b'1')] = 1; - lut[numeric_keypad_index(b'1', b'2')] = 14287938116; - lut[numeric_keypad_index(b'1', b'3')] = 14287938117; - lut[numeric_keypad_index(b'1', b'4')] = 14752615084; - lut[numeric_keypad_index(b'1', b'5')] = 24095973437; - lut[numeric_keypad_index(b'1', b'6')] = 24095973438; - lut[numeric_keypad_index(b'1', b'7')] = 14752615085; - lut[numeric_keypad_index(b'1', b'8')] = 24095973438; - lut[numeric_keypad_index(b'1', b'9')] = 24095973439; - lut[numeric_keypad_index(b'1', b'A')] = 27052881364; - lut[numeric_keypad_index(b'2', b'0')] = 20790420654; - lut[numeric_keypad_index(b'2', b'1')] = 22411052532; - lut[numeric_keypad_index(b'2', b'2')] = 1; - lut[numeric_keypad_index(b'2', b'3')] = 14287938116; - lut[numeric_keypad_index(b'2', b'4')] = 28154654777; - lut[numeric_keypad_index(b'2', b'5')] = 14752615084; - lut[numeric_keypad_index(b'2', b'6')] = 24095973437; - lut[numeric_keypad_index(b'2', b'7')] = 28154654778; - lut[numeric_keypad_index(b'2', b'8')] = 14752615085; - lut[numeric_keypad_index(b'2', b'9')] = 24095973438; - lut[numeric_keypad_index(b'2', b'A')] = 22778092491; - lut[numeric_keypad_index(b'3', b'0')] = 27622800565; - lut[numeric_keypad_index(b'3', b'1')] = 22411052533; - lut[numeric_keypad_index(b'3', b'2')] = 22411052532; - lut[numeric_keypad_index(b'3', b'3')] = 1; - lut[numeric_keypad_index(b'3', b'4')] = 28154654778; - lut[numeric_keypad_index(b'3', b'5')] = 28154654777; - lut[numeric_keypad_index(b'3', b'6')] = 14752615084; - lut[numeric_keypad_index(b'3', b'7')] = 28154654779; - lut[numeric_keypad_index(b'3', b'8')] = 28154654778; - lut[numeric_keypad_index(b'3', b'9')] = 14752615085; - lut[numeric_keypad_index(b'3', b'A')] = 20790420654; - lut[numeric_keypad_index(b'4', b'0')] = 27052881364; - lut[numeric_keypad_index(b'4', b'1')] = 20790420654; - lut[numeric_keypad_index(b'4', b'2')] = 22778092491; - lut[numeric_keypad_index(b'4', b'3')] = 22778092492; - lut[numeric_keypad_index(b'4', b'4')] = 1; - lut[numeric_keypad_index(b'4', b'5')] = 14287938116; - lut[numeric_keypad_index(b'4', b'6')] = 14287938117; - lut[numeric_keypad_index(b'4', b'7')] = 14752615084; - lut[numeric_keypad_index(b'4', b'8')] = 24095973437; - lut[numeric_keypad_index(b'4', b'9')] = 24095973438; - lut[numeric_keypad_index(b'4', b'A')] = 27052881365; - lut[numeric_keypad_index(b'5', b'0')] = 20790420655; - lut[numeric_keypad_index(b'5', b'1')] = 27622800565; - lut[numeric_keypad_index(b'5', b'2')] = 20790420654; - lut[numeric_keypad_index(b'5', b'3')] = 22778092491; - lut[numeric_keypad_index(b'5', b'4')] = 22411052532; - lut[numeric_keypad_index(b'5', b'5')] = 1; - lut[numeric_keypad_index(b'5', b'6')] = 14287938116; - lut[numeric_keypad_index(b'5', b'7')] = 28154654777; - lut[numeric_keypad_index(b'5', b'8')] = 14752615084; - lut[numeric_keypad_index(b'5', b'9')] = 24095973437; - lut[numeric_keypad_index(b'5', b'A')] = 22778092492; - lut[numeric_keypad_index(b'6', b'0')] = 27622800566; - lut[numeric_keypad_index(b'6', b'1')] = 27622800566; - lut[numeric_keypad_index(b'6', b'2')] = 27622800565; - lut[numeric_keypad_index(b'6', b'3')] = 20790420654; - lut[numeric_keypad_index(b'6', b'4')] = 22411052533; - lut[numeric_keypad_index(b'6', b'5')] = 22411052532; - lut[numeric_keypad_index(b'6', b'6')] = 1; - lut[numeric_keypad_index(b'6', b'7')] = 28154654778; - lut[numeric_keypad_index(b'6', b'8')] = 28154654777; - lut[numeric_keypad_index(b'6', b'9')] = 14752615084; - lut[numeric_keypad_index(b'6', b'A')] = 20790420655; - lut[numeric_keypad_index(b'7', b'0')] = 27052881365; - lut[numeric_keypad_index(b'7', b'1')] = 20790420655; - lut[numeric_keypad_index(b'7', b'2')] = 22778092492; - lut[numeric_keypad_index(b'7', b'3')] = 22778092493; - lut[numeric_keypad_index(b'7', b'4')] = 20790420654; - lut[numeric_keypad_index(b'7', b'5')] = 22778092491; - lut[numeric_keypad_index(b'7', b'6')] = 22778092492; - lut[numeric_keypad_index(b'7', b'7')] = 1; - lut[numeric_keypad_index(b'7', b'8')] = 14287938116; - lut[numeric_keypad_index(b'7', b'9')] = 14287938117; - lut[numeric_keypad_index(b'7', b'A')] = 27052881366; - lut[numeric_keypad_index(b'8', b'0')] = 20790420656; - lut[numeric_keypad_index(b'8', b'1')] = 27622800566; - lut[numeric_keypad_index(b'8', b'2')] = 20790420655; - lut[numeric_keypad_index(b'8', b'3')] = 22778092492; - lut[numeric_keypad_index(b'8', b'4')] = 27622800565; - lut[numeric_keypad_index(b'8', b'5')] = 20790420654; - lut[numeric_keypad_index(b'8', b'6')] = 22778092491; - lut[numeric_keypad_index(b'8', b'7')] = 22411052532; - lut[numeric_keypad_index(b'8', b'8')] = 1; - lut[numeric_keypad_index(b'8', b'9')] = 14287938116; - lut[numeric_keypad_index(b'8', b'A')] = 22778092493; - lut[numeric_keypad_index(b'9', b'0')] = 27622800567; - lut[numeric_keypad_index(b'9', b'1')] = 27622800567; - lut[numeric_keypad_index(b'9', b'2')] = 27622800566; - lut[numeric_keypad_index(b'9', b'3')] = 20790420655; - lut[numeric_keypad_index(b'9', b'4')] = 27622800566; - lut[numeric_keypad_index(b'9', b'5')] = 27622800565; - lut[numeric_keypad_index(b'9', b'6')] = 20790420654; - lut[numeric_keypad_index(b'9', b'7')] = 22411052533; - lut[numeric_keypad_index(b'9', b'8')] = 22411052532; - lut[numeric_keypad_index(b'9', b'9')] = 1; - lut[numeric_keypad_index(b'9', b'A')] = 20790420656; - lut[numeric_keypad_index(b'A', b'0')] = 22411052532; - lut[numeric_keypad_index(b'A', b'1')] = 31420065370; - lut[numeric_keypad_index(b'A', b'2')] = 28154654777; - lut[numeric_keypad_index(b'A', b'3')] = 14752615084; - lut[numeric_keypad_index(b'A', b'4')] = 31420065371; - lut[numeric_keypad_index(b'A', b'5')] = 28154654778; - lut[numeric_keypad_index(b'A', b'6')] = 14752615085; - lut[numeric_keypad_index(b'A', b'7')] = 31420065372; - lut[numeric_keypad_index(b'A', b'8')] = 28154654779; - lut[numeric_keypad_index(b'A', b'9')] = 14752615086; - lut[numeric_keypad_index(b'A', b'A')] = 1; - - lut -}; - -#[rustfmt::skip] -unsafe fn parse_num(n: &[u8]) -> u64 { - (*n.get_unchecked(0) as u64) * 100 + - (*n.get_unchecked(1) as u64) * 10 + - (*n.get_unchecked(2) as u64) - 5328 -} +const LUT1: [u64; 1000] = unsafe { transmute(*include_bytes!("../luts/day21_1.bin")) }; +const LUT2: [u64; 1000] = unsafe { transmute(*include_bytes!("../luts/day21_2.bin")) }; #[rustfmt::skip] -unsafe fn calculate_code(moves: &[u64; LUT_SIZE], code: &[u8]) -> u64 { - parse_num(code) * ( - moves.get_unchecked(numeric_keypad_index(b'A', *code.get_unchecked(0))) + - moves.get_unchecked(numeric_keypad_index(*code.get_unchecked(0), *code.get_unchecked(1))) + - moves.get_unchecked(numeric_keypad_index(*code.get_unchecked(1), *code.get_unchecked(2))) + - moves.get_unchecked(numeric_keypad_index(*code.get_unchecked(2), b'A')) - ) +unsafe fn parse_num(n: &[u8]) -> usize { + (*n.get_unchecked(0) as usize) * 100 + + (*n.get_unchecked(1) as usize) * 10 + + (*n.get_unchecked(2) as usize) - 5328 } pub fn part1(input: &str) -> u64 { unsafe { input .lines() - .map(|code| calculate_code(&LUT1, code.as_bytes())) + .map(|code| LUT1.get_unchecked(parse_num(code.as_bytes()))) .sum() } } @@ -291,7 +23,7 @@ pub fn part2(input: &str) -> u64 { unsafe { input .lines() - .map(|code| calculate_code(&LUT2, code.as_bytes())) + .map(|code| LUT2.get_unchecked(parse_num(code.as_bytes()))) .sum() } }