1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//! Facilitates answering to competitive programming problems.
//!
//! This crate is intended to be used with [cargo-equip], which is a tool to bundle code into single `.rs` file.
//!
//! # Examples
//!
//! ```no_run
//! use mic::{answer, solve};
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer]
//! fn main() -> _ {
//! 1
//! }
//! // 1 → println!("{}", 1)
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(yn("Yes", "No"))]
//! fn main() -> _ {
//! true
//! }
//! // true → "Yes"
//! // → println!("{}", "Yes")
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(tuple(" "))]
//! fn main() -> _ {
//! (42, "foo")
//! }
//! // (42, "foo") → "42 foo".to_owned()
//! // → println!("{}", "42 foo".to_owned())
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(join("\n"))]
//! fn main() -> _ {
//! 1..=3
//! }
//! // 1..=3 → "1\n2\n3".to_owned()
//! // → println!("{}", "1\n2\n3".to_owned())
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(matrix(" "))]
//! fn main() -> _ {
//! vec![vec![1, 2], vec![3, 4]]
//! }
//! // vec![vec![1, 2], vec![3, 4]] → "1 2\n3 4".to_owned()
//! // → println!("{}", "1 2\n3 4".to_owned())
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(join(" "), map(add(1)))]
//! fn main() -> _ {
//! vec![0, 2, 4] // 0-based graph node indices
//! }
//! // vec![0, 2, 4] → { impl Iterator } ([1, 3, 5])
//! // → "1 3 5".to_owned()
//! // → println!("{}", "1 3 5".to_owned())
//! ```
//!
//! ```
//! # use mic::solve;
//! # fn main() {
//! #[solve(join(" "))]
//! fn solve() -> _ {
//! 1..=3
//! }
//! // 1..=3 → "1 2 3".to_owned()
//!
//! assert_eq!("1 2 3", solve());
//! # }
//! ```
//!
//! # Quickstart
//!
//! ```no_run
//! use mic::answer;
//!
//! #[answer(std::convert::identity)]
//! fn main() -> _ {
//! 42
//! }
//! ```
//!
//! This `main` function is converted into:
//!
//! ```no_run
//! # use std::convert;
//! fn main() {
//! #[allow(unused_imports)]
//! use ::mic::__YouCannotRecurseIfTheOutputTypeIsInferred as main;
//!
//! let __mic_ans = (move || -> _ {
//! 42
//! })();
//! let __mic_ans = {
//! #[allow(unused_imports)]
//! use ::mic::filters::*;
//!
//! std::convert::identity(__mic_ans)
//! };
//! ::std::println!("{}", __mic_ans);
//! }
//! ```
//!
//! `#[answer]` takes 0 or more functions as arguments.
//! If multiple functions are given, they are composed in right associative.
//!
//! ```no_run
//! # use mic::answer;
//! #[answer]
//! fn main() -> _ {
//! 1
//! }
//! // 1 → println!("{}", 1)
//! ```
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(|ans| ans - 1, |ans| ans * 2, |ans| ans + 3)]
//! fn main() -> _ {
//! 1
//! }
//! // 1 → 4 (+ 3)
//! // → 8 (* 2)
//! // → 7 (- 1)
//! // → println!("{}", 7)
//! ```
//!
//! # Filters
//!
//! This crate provides some utility functions under the [`mic::filters`] module.
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(mic::filters::join("\n"))]
//! fn main() -> _ {
//! vec![1, 2, 3]
//! }
//! // vec![1, 2, 3] → "1\n2\n3".to_owned()
//! // → println!("{}", "1\n2\n3".to_owned())
//! ```
//!
//! `mic::filters::` prefixes can be omitted since the functions are `use`d inside.
//!
//! ```no_run
//! # use mic::answer;
//! #[answer(join("\n"))]
//! # fn main() -> _ {
//! # vec![1, 2, 3]
//! # }
//! ```
//!
//! # `#[solve]`
//!
//! [<code>#\[solve\]</code>] wraps the output in `ToString::to_string` instead of `println!`.
//!
//! ```no_run
//! use mic::solve;
//! use proconio::{input, source::once::OnceSource};
//! use std::io::{self, Read as _};
//!
//! fn main() {
//! let mut input = "".to_owned();
//! io::stdin().read_to_string(&mut input).unwrap();
//! println!("{}", solve(&input));
//! }
//!
//! #[solve(join(" "))]
//! fn solve(input: &str) -> _ {
//! input! {
//! from OnceSource::from(input),
//! mut xs: [u32],
//! }
//! xs.reverse();
//! xs
//! }
//!
//! #[cfg(test)]
//! mod tests {
//! use super::solve;
//!
//! #[test]
//! fn test() {
//! assert_eq!("3 2 1", solve("3\n1 2 3\n"));
//! }
//! }
//! ```
//!
//! [cargo-equip]: https://github.com/qryxip/cargo-equip
//! [`mic::filters`]: ./filters/index.html
//! [<code>#\[solve\]</code>]: ./attr.solve.html
pub use *;
;