Skip to content

Commit 94dda8e

Browse files
committed
removing all the unecessary box stuff(still not finished)
1 parent 1c79864 commit 94dda8e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

2015/7/src/main.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs::read_to_string;
33

44
#[derive(Clone, Copy, Debug)]
55
enum NumOrVar<'a> {
6-
Num(i16),
6+
Num(u16),
77
Var(&'a str),
88
}
99

@@ -25,12 +25,12 @@ enum Instruction<'a> {
2525
},
2626
LShift {
2727
opnd0: &'a str,
28-
shift: i16,
28+
shift: u16,
2929
ans: &'a str,
3030
},
3131
RShift {
3232
opnd0: &'a str,
33-
shift: i16,
33+
shift: u16,
3434
ans: &'a str,
3535
},
3636
Assignment {
@@ -42,8 +42,8 @@ enum Instruction<'a> {
4242
fn evaluate<'a>(
4343
search: &'a str,
4444
instructions: &'a [Instruction],
45-
cache: &mut HashMap<&'a str, Option<i16>>,
46-
) -> i16 {
45+
cache: &mut HashMap<&'a str, Option<u16>>,
46+
) -> u16 {
4747
let mut ending_value = 0;
4848
for instruction in instructions {
4949
match instruction {
@@ -77,8 +77,8 @@ fn evaluate<'a>(
7777
let entry2 = cache.entry(opnd1);
7878
entry2.or_insert(None);
7979

80-
let v1: i16;
81-
let v2: i16;
80+
let v1: u16;
81+
let v2: u16;
8282

8383
if let Some(o0) = cache[opnd0] {
8484
v1 = o0;
@@ -103,8 +103,8 @@ fn evaluate<'a>(
103103
let entry2 = cache.entry(opnd1);
104104
entry2.or_insert(None);
105105

106-
let v1: i16;
107-
let v2: i16;
106+
let v1: u16;
107+
let v2: u16;
108108

109109
if let Some(o0) = cache[opnd0] {
110110
v1 = o0;
@@ -126,7 +126,7 @@ fn evaluate<'a>(
126126
let entry1 = cache.entry(opnd0);
127127
entry1.or_insert(None);
128128

129-
let v1: i16;
129+
let v1: u16;
130130

131131
if let Some(o0) = cache[opnd0] {
132132
v1 = o0;
@@ -142,7 +142,7 @@ fn evaluate<'a>(
142142
let entry1 = cache.entry(opnd0);
143143
entry1.or_insert(None);
144144

145-
let v1: i16;
145+
let v1: u16;
146146

147147
if let Some(o0) = cache[opnd0] {
148148
v1 = o0;
@@ -158,7 +158,7 @@ fn evaluate<'a>(
158158
let entry1 = cache.entry(opnd0);
159159
entry1.or_insert(None);
160160

161-
let v1: i16;
161+
let v1: u16;
162162

163163
if let Some(o0) = cache[opnd0] {
164164
v1 = o0;
@@ -177,10 +177,10 @@ fn evaluate<'a>(
177177

178178
fn main() {
179179
let file = read_to_string("input.txt");
180-
let mut cache: Box<HashMap<&str, Option<i16>>> = Box::default();
180+
let mut cache: HashMap<&str, Option<u16>> = HashMap::new();
181181

182182
if let Ok(file) = file {
183-
let mut instructions: Box<Vec<Instruction>> = Box::default();
183+
let mut instructions: Vec<Instruction> = Vec::new();
184184

185185
for line in file.lines() {
186186
let instruction: Instruction;
@@ -228,7 +228,7 @@ fn main() {
228228
} else {
229229
// 123 -> x
230230
// 0 1 2
231-
if let Ok(i) = split[0].parse::<i16>() {
231+
if let Ok(i) = split[0].parse::<u16>() {
232232
instruction = Instruction::Assignment {
233233
value: NumOrVar::Num(i),
234234
var: split[2],
@@ -244,7 +244,7 @@ fn main() {
244244
instructions.push(instruction);
245245
}
246246

247-
let answer = Box::new(evaluate("x", &instructions, &mut cache));
247+
let answer = evaluate("a", &instructions, &mut cache);
248248
println!("{}", answer);
249249
} else {
250250
println!("input.txt not found")

0 commit comments

Comments
 (0)