heh
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs183
1 files changed, 141 insertions, 42 deletions
diff --git a/src/main.rs b/src/main.rs
index c9c3c67..1c62f4c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,7 +5,8 @@
internal_features,
mixed_script_confusables,
static_mut_refs,
- incomplete_features
+ incomplete_features,
+ redundant_semicolons
)]
#![feature(
stdarch_x86_avx512,
@@ -47,52 +48,150 @@ type u32x3 = Simd<u32, 3>;
#[no_mangle]
pub fn p1(x: &'static str) -> impl Display {
- let boss = [104, 8, 1];
- const HP: usize = 0;
- const DAMAGE: usize = 1;
- const ARMOR: usize = 2;
-
- let weapons =
- [[8, 4, 0], [10, 5, 0], [25, 6, 0], [40, 7, 0], [74, 8, 0]].map(u32x3::from_array);
- let armors =
- [[13, 0, 1], [31, 0, 2], [53, 0, 3], [75, 0, 4], [102, 0, 5]].map(u32x3::from_array);
- let rings = [
- [25, 1, 0],
- [50, 2, 0],
- [100, 3, 0],
- [20, 0, 1],
- [40, 0, 2],
- [80, 0, 3],
- ]
- .map(u32x3::from_array);
-
+ #[derive(Clone, Copy, PartialEq, Eq, Debug)]
+ enum Effect {
+ Shield,
+ Poison,
+ Recharge,
+ }
+ #[derive(Clone, Debug)]
+ struct Game {
+ effects: Vec<(Effect, u32)>,
+ player: [u32; 3],
+ boss: [u32; 2],
+ }
+ use Effect::*;
+ static mut min: u64 = !0;
+ fn mini(x: u64) {
+ unsafe {
+ if min > x {
+ println!("{x}");
+ min = x;
+ }
+ }
+ }
#[apply(saturating)]
- fn wins(mut boss: [u32; 3], mut player: [u32; 3]) -> bool {
- loop {
- boss[HP] = boss[HP] - (player[DAMAGE] - boss[ARMOR]);
- if boss[HP] == 0 {
- return true;
+ fn go(mut game: Game, player: bool, spent: u64) {
+ if spent > unsafe { min } {
+ return;
+ }
+
+ for (e, _) in &mut game.effects {
+ match e {
+ Effect::Shield => game.player[1] = 7,
+ Effect::Poison => game.boss[0] -= 3,
+ Effect::Recharge => game.player[2] += 101,
+ }
+ }
+ game.effects
+ .iter_mut()
+ .for_each(|(_, x)| *x = x.saturating_sub(1));
+ game.effects
+ .extract_if(.., |x| x.1 == 0)
+ .for_each(|(e, _)| match e {
+ Effect::Shield => game.player[1] = 0,
+ _ => (),
+ });
+
+ if game.boss[0] == 0 {
+ // win
+ return mini(spent);
+ }
+
+ // play boss turn
+ if !player {
+ // player[hp] -= boss[damage] - player[armor]
+ game.player[0] = game.player[0] - (game.boss[1] - game.player[1]);
+ if game.player[0] == 0 {
+ // ded
+ return;
+ }
+ return go(game, true, spent);
+ }
+
+ // game.player[0] -= 1;
+ // if game.player[0] == 0 {
+ // // ded
+ // return;
+ // }
+
+ if game.player[2] < 53 {
+ // ded
+ return;
+ }
+
+ if game.player[2] >= 53 {
+ // missile
+ let mut game = game.clone();
+ game.player[2] -= 53;
+ game.boss[0] -= 4;
+ if game.boss[0] == 0 {
+ return mini(spent + 53);
}
- player[HP] = player[HP] - (boss[DAMAGE] - player[ARMOR]);
- if player[HP] == 0 {
- return false;
+ go(game, false, spent + 53);
+ }
+
+ if game.player[2] >= 73 {
+ // drain
+ let mut game = game.clone();
+ game.player[2] -= 73;
+ game.player[0] += 2;
+ game.boss[0] -= 2;
+ if game.boss[0] == 0 {
+ return mini(spent + 73);
}
+ go(game, false, spent + 73);
}
+
+ if game.player[2] >= 113 && !game.effects.iter().l().contains(&Shield) {
+ // shield
+ let mut game = game.clone();
+ game.effects.push((Shield, 6));
+ game.player[2] -= 113;
+ go(game, false, spent + 113);
+ }
+
+ if game.player[2] >= 173 && !game.effects.iter().l().contains(&Poison) {
+ // poison
+ let mut game = game.clone();
+ game.effects.push((Poison, 6));
+ game.player[2] -= 173;
+ go(game, false, spent + 173);
+ }
+
+ if game.player[2] >= 229 && !game.effects.iter().l().contains(&Recharge) {
+ // recharge
+ let mut game = game.clone();
+ game.effects.push((Recharge, 5));
+ game.player[2] -= 229;
+ go(game, false, spent + 229);
+ }
+
+ // Magic Missile costs 53 mana. It instantly does 4 damage.
+ // Drain costs 73 mana. It instantly does 2 damage and heals you for 2 hit points.
+ // Shield costs 113 mana. It starts an effect that lasts for 6 turns. While it is active, your armor is increased by 7.
+ // Poison costs 173 mana. It starts an effect that lasts for 6 turns. At the start of each turn while it is active, it deals the boss 3 damage.
+ // Recharge costs 229 mana. It starts an effect that lasts for 5 turns. At the start of each turn while it is active, it gives you 101 new mana.
}
- iproduct!(
- weapons,
- armors.into_iter().chain(once(Simd::splat(0))),
- chain(rings, twice(Simd::splat(0)))
- .into_iter()
- .combinations(2)
- .map(|rings| rings.into_iter().sum())
- )
- .map(|x| x.array().sum())
- .map(u32x3::to_array)
- .filter(|&[_, d, a]| wins(boss, [100, d, a]))
- .map(|[x, ..]| x)
- .min()
- .ψ()
+ // go(
+ // Game {
+ // effects: vec![],
+ // player: [10, 0, 250],
+ // boss: [14, 8],
+ // },
+ // true,
+ // 0,
+ // );
+ go(
+ Game {
+ effects: vec![],
+ player: [50, 0, 500],
+ boss: [55, 8],
+ },
+ true,
+ 0,
+ );
+ unsafe { min }
}
fn main() {