Skip to content

Commit

Permalink
fix: use BigInt for integer value
Browse files Browse the repository at this point in the history
  • Loading branch information
sor4chi committed Jun 30, 2024
1 parent bf63d19 commit 6ea8259
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 359 deletions.
4 changes: 2 additions & 2 deletions src/bin/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use serde::{Deserialize, Serialize};
const API_URL: &str = "https://boundvariable.space/communicate";
const COMMAND: &str = "get lambdaman";
const SAVE_DIR: &str = "downloads";
const START_ID: usize = 9;
const END_ID: usize = 9;
const START_ID: usize = 21;
const END_ID: usize = 21;
// ==============================

struct Env {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ fn main() {
stdin().read_line(&mut buffer).unwrap();
buffer
};
println!("ENCRYPTED: S{}", deconvert_string(text.to_string()));
let text = text.trim();
println!("S{}", deconvert_string(text.to_string()));
}
1 change: 1 addition & 0 deletions src/bin/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use icfpc2024::{
},
node,
};
use num_bigint::BigInt;
use std::{collections::VecDeque, io::stdin, iter::repeat};

fn get_compress_collection(text: &str) -> VecDeque<(char, usize)> {
Expand Down
14 changes: 8 additions & 6 deletions src/icfp/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use num_bigint::BigInt;

use crate::icfp::util::STRING_ASCII;

use super::{
Expand Down Expand Up @@ -59,7 +61,7 @@ pub fn repeat_char() -> Node {
node!(Node::BinaryOperator(
">".to_string(),
node!(Node::Variable(1)),
node!(Node::Integer(BASE94)) // 1文字以上からじゃないと出力できないようにする(ICFPに空文字列が存在しないため)
node!(Node::Integer(BigInt::from(BASE94))) // 1文字以上からじゃないと出力できないようにする(ICFPに空文字列が存在しないため)
)),
node!(Node::BinaryOperator(
".".to_string(),
Expand All @@ -68,7 +70,7 @@ pub fn repeat_char() -> Node {
node!(Node::BinaryOperator(
"%".to_string(),
node!(Node::Variable(1)),
node!(Node::Integer(BASE94))
node!(Node::Integer(BigInt::from(BASE94)))
))
)),
node!(Node::BinaryOperator(
Expand All @@ -77,7 +79,7 @@ pub fn repeat_char() -> Node {
node!(Node::BinaryOperator(
"-".to_string(),
node!(Node::Variable(1)),
node!(Node::Integer(BASE94))
node!(Node::Integer(BigInt::from(BASE94)))
))
))
)),
Expand All @@ -90,7 +92,7 @@ pub fn repeat_char() -> Node {
pub fn repeat_char_operator(value: char, times: usize) -> Node {
assert!(times >= 1);
let value_id = STRING_ASCII.find(value).unwrap();
Node::Integer(BASE94 * times as isize + value_id as isize)
Node::Integer(BigInt::from(BASE94 * times as isize + value_id as isize))
}

#[cfg(test)]
Expand All @@ -108,7 +110,7 @@ mod tests {
node!(y_combinator()),
node!(repeat_char())
)),
node!(Node::Integer(BASE94 * 1 + 5))
node!(Node::Integer(BigInt::from(BASE94 * 20 + 5)))
));
node.dump_tree(0);
eprintln!("{}", node.to_string());
Expand All @@ -120,6 +122,6 @@ mod tests {
#[test]
fn test_repeat_operator() {
let node = repeat_char_operator('a', 3);
assert_eq!(node, Node::Integer(282));
assert_eq!(node, Node::Integer(BigInt::from(282)));
}
}
Loading

0 comments on commit 6ea8259

Please sign in to comment.