Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed Dec 9, 2023
1 parent e83d0e5 commit c636928
Show file tree
Hide file tree
Showing 10 changed files with 1,471 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Rustfmt
run: cargo fmt --all -- --check
run: cargo fmt --all --exclude generator -- --check

- name: Build
run: cargo build --all
run: cargo build --all --exclude generator

# Don't currently test because many tests rely on the system having a CUDA GPU
# - name: Test
Expand All @@ -69,5 +69,5 @@ jobs:
- name: Clippy
env:
RUSTFLAGS: -Dwarnings
run: cargo clippy --all --tests
run: cargo clippy --all --tests --exclude generator

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ cuda_builder = "0.3.0"

[workspace]
members = [
"generator",
#"generator",
"gpu",
]
2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
[dependencies]
anyhow = "1.0.75"
aoc-client = "0.2.0"
regex = "1.7.1"
regex = "=1.7.1"
textwrap = "0.16.0"
25 changes: 19 additions & 6 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ fn generate_template(

// Read the puzzle markdown.
let puzzle_markdown = std::fs::read_to_string(puzzle_filename)?;
println!("Puzzle markdown: {}", puzzle_markdown);

// Clean up the puzzle markdown file.
std::fs::remove_file(puzzle_filename)?;

// Parse the puzzle markdown.
let puzzle = Puzzle::parse(&puzzle_markdown)?;
println!("Puzzle: {:#?}", puzzle);

let src_dir = working_dir.join("src");

Expand Down Expand Up @@ -275,6 +277,13 @@ fn trim_answer(comment: &str) -> Result<String> {
.trim()
.to_string();

let cleaned = cleaned
.split("To begin, get your puzzle")
.next()
.ok_or_else(|| anyhow::anyhow!("Missing comment"))?
.trim()
.to_string();

// Make sure the output width set correctly.
let markdown = replace_doc_links(&cleaned)?;

Expand Down Expand Up @@ -332,12 +341,16 @@ fn replace_old_comment(
lines.drain(comment_index..fn_index);

// Insert the new comments at the comment index.
let part_comment = format!(
"/// {}",
new_comment
.replace('\n', "\n/// ")
.replace("\n/// \n", "\n///\n")
);
let part_comment = if new_comment.is_empty() {
"/// Not yet unlocked.".to_string()
} else {
format!(
"/// {}",
new_comment
.replace('\n', "\n/// ")
.replace("\n/// \n", "\n///\n")
)
};
lines.insert(comment_index, &part_comment);

Ok(lines.join("\n"))
Expand Down
46 changes: 46 additions & 0 deletions gpu/src/day08.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! CUDA Kernel for day 08: Haunted Wasteland

use cuda_std::*;

/// Traverse the graph from nodes ending with A until all nodes reach nodes
/// ending with Z.
#[kernel]
#[allow(clippy::missing_safety_doc)]
pub unsafe fn graph_traversal(
graph: &[(u32, u32)],
start: &[u32],
goals: &[u32],
directions: &[bool], // true for left, false for right
nodes: *mut u32,
steps: *mut u64,
) {
let nodes_len = goals.len();
let mut items = start.to_vec();
for i in directions {
let idx = thread::index_1d() as usize;
let mut found = true;

if idx < nodes_len {
let mut node = items[idx];
if *i {
node = graph[node as usize].0;
} else {
node = graph[node as usize].1;
}

if found && !goals.contains(&node) {
found = false;
}

items.insert(idx, node);
let elem = &mut *nodes.add(idx);
*elem = node;
let elem = &mut *steps.add(idx);
*elem = 1;
}

if found {
break;
}
}
}
1 change: 1 addition & 0 deletions gpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
extern crate alloc;

pub mod add;
pub mod day08;
Loading

0 comments on commit c636928

Please sign in to comment.