mirror of
https://github.com/danbulant/adventOfCode
synced 2026-06-22 15:31:43 +00:00
update
This commit is contained in:
parent
5a88d559b5
commit
83c5e51a6e
4 changed files with 7 additions and 171 deletions
7
2023/8/Cargo.lock
generated
7
2023/8/Cargo.lock
generated
|
|
@ -1,7 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "eight"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "eight"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
|
|
@ -9,43 +9,16 @@ for line in open("./input2"):
|
||||||
instructions = [(0 if x == "L" else 1) for x in line.strip()]
|
instructions = [(0 if x == "L" else 1) for x in line.strip()]
|
||||||
continue
|
continue
|
||||||
if line == "\n": continue
|
if line == "\n": continue
|
||||||
name = line.split(" ")[0].strip()
|
nodes[line.split(" ")[0].strip()] = line.split("(")[1].split(")")[0].split(", ")
|
||||||
leftnode = line.split("(")[1].split(",")[0].strip()
|
|
||||||
rightnode = line.split("(")[1].split(",")[1].split(")")[0].strip()
|
|
||||||
nodes[name] = (leftnode, rightnode)
|
|
||||||
|
|
||||||
# count = 0
|
def node_value(node):
|
||||||
current = [(node, []) for node in nodes.keys() if node.endswith("A")]
|
|
||||||
|
|
||||||
for i, node in enumerate(current):
|
|
||||||
instructionsc = cycle(instructions)
|
instructionsc = cycle(instructions)
|
||||||
instruction_offset = 0
|
|
||||||
nnode = node[0]
|
|
||||||
zets = []
|
|
||||||
steps = 0
|
steps = 0
|
||||||
while not nnode.endswith("Z"):
|
while not node.endswith("Z"):
|
||||||
nnode = nodes[nnode][next(instructionsc)]
|
node = nodes[node][next(instructionsc)]
|
||||||
steps += 1
|
steps += 1
|
||||||
# if not steps - 1 in zets:
|
return steps
|
||||||
# zets.append(steps - 1)
|
|
||||||
current[i] = (node[0], steps)
|
|
||||||
print(node[0], steps)
|
|
||||||
|
|
||||||
print(current)
|
current = [node_value(node) for node in nodes.keys() if node.endswith("A")]
|
||||||
|
|
||||||
values = [node[1] for node in current]
|
print(math.lcm(*current))
|
||||||
|
|
||||||
print(values)
|
|
||||||
|
|
||||||
# num = 0
|
|
||||||
# lowest_value = min(value[1] for value in values)
|
|
||||||
# print("low", lowest_value)
|
|
||||||
|
|
||||||
# while True:
|
|
||||||
# num += lowest_value
|
|
||||||
# # print(num)
|
|
||||||
# if all([num % value[1] == value[0] for value in values]):
|
|
||||||
# print("Found", num)
|
|
||||||
# break
|
|
||||||
|
|
||||||
print(math.lcm(*[node for node in values]))
|
|
||||||
|
|
@ -1,122 +0,0 @@
|
||||||
use std::{io::{BufReader, BufRead}, fs::File, ops::Index};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::sync::mpsc;
|
|
||||||
|
|
||||||
struct Node {
|
|
||||||
left: String,
|
|
||||||
right: String
|
|
||||||
}
|
|
||||||
enum Instruction {
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let values = [[18156, 36313], [11652, 23305], [21408, 42817], [12736, 25473], [14362, 28725], [15988, 31977]];
|
|
||||||
let lowest_value = values.iter().map(|v| v[1]).min().unwrap();
|
|
||||||
let mut num: i64 = values[1][0];
|
|
||||||
let mut printcount = 0;
|
|
||||||
dbg!(lowest_value);
|
|
||||||
|
|
||||||
'main: loop {
|
|
||||||
num += lowest_value;
|
|
||||||
for value in &values {
|
|
||||||
if num % value[1] != value[0] {
|
|
||||||
printcount += 1;
|
|
||||||
if printcount % 100000000 == 0 {
|
|
||||||
dbg!(num);
|
|
||||||
}
|
|
||||||
// if value[0] != 18156 {
|
|
||||||
// dbg!(num, value[1], value[0], num % value[1]);
|
|
||||||
// }
|
|
||||||
continue 'main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbg!(num);
|
|
||||||
|
|
||||||
// let file = BufReader::new(File::open("./input2").unwrap());
|
|
||||||
// let mut instructions = vec![];
|
|
||||||
// let mut nodes = HashMap::new();
|
|
||||||
|
|
||||||
// for line in file.lines() {
|
|
||||||
// let line = line.unwrap();
|
|
||||||
// if instructions.is_empty() {
|
|
||||||
// let chars = line.chars().collect::<Vec<char>>();
|
|
||||||
// // L = Left, R = Right
|
|
||||||
// for c in chars {
|
|
||||||
// match c {
|
|
||||||
// 'L' => instructions.push(Instruction::Left),
|
|
||||||
// 'R' => instructions.push(Instruction::Right),
|
|
||||||
// _ => ()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if line.is_empty() {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// let name = line.split(" ").next().unwrap();
|
|
||||||
// let left = line.split("(").nth(1).unwrap().split(",").next().unwrap();
|
|
||||||
// let right = line.split("(").nth(1).unwrap().split(",").nth(1).unwrap().strip_suffix(")").unwrap().trim();
|
|
||||||
|
|
||||||
// nodes.insert(name.to_string(), Node { left: left.to_string(), right: right.to_string() });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let mut instruction_pointer = 0;
|
|
||||||
// let mut current_nodes = nodes.keys().filter(|k| k.ends_with("A")).collect::<Vec<&String>>();
|
|
||||||
// /// Array of arrays corresponding to current_nodes, with each value in the array being the step in which the node reaches Z node
|
|
||||||
// let mut z_values = Arc::new(RwLock::new(vec![Mutex::new(vec![]); current_nodes.len()]));
|
|
||||||
|
|
||||||
// dbg!(¤t_nodes);
|
|
||||||
|
|
||||||
// let mut count = 0;
|
|
||||||
|
|
||||||
// let z_values2 = z_values.clone();
|
|
||||||
// let main_join_thread = thread::spawn(move || {
|
|
||||||
// // If there's a common number between z_values, stop and return
|
|
||||||
// loop {
|
|
||||||
// let z_values = z_values2.read().unwrap();
|
|
||||||
// let mut common_values = z_values.get(0).unwrap().lock().unwrap().clone();
|
|
||||||
// for i in 1..z_values.len() {
|
|
||||||
// let values = z_values.get(i).unwrap().lock().unwrap().clone();
|
|
||||||
// common_values = common_values.iter().filter(|v| values.contains(v)).collect::<Vec<&usize>>();
|
|
||||||
// }
|
|
||||||
// if !common_values.is_empty() {
|
|
||||||
// return common_values[0].clone();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// let mut offset = 0;
|
|
||||||
// for node in current_nodes {
|
|
||||||
// thread::spawn(move || {
|
|
||||||
// let mut node = node;
|
|
||||||
// let offset = offset;
|
|
||||||
// });
|
|
||||||
// offset += 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let val = main_join_thread.join().unwrap();
|
|
||||||
// dbg!(val);
|
|
||||||
|
|
||||||
// while !current_nodes.iter().all(|n| n.ends_with("Z")) {
|
|
||||||
// let mut next_nodes = vec![];
|
|
||||||
// for node in current_nodes {
|
|
||||||
// let node = nodes.get(node).unwrap();
|
|
||||||
// match instructions[instruction_pointer] {
|
|
||||||
// Instruction::Left => next_nodes.push(&node.left),
|
|
||||||
// Instruction::Right => next_nodes.push(&node.right)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// instruction_pointer += 1;
|
|
||||||
// instruction_pointer %= instructions.len();
|
|
||||||
// count += 1;
|
|
||||||
// current_nodes = next_nodes;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// dbg!(count);
|
|
||||||
// println!("{count}");
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue