+1
rust/code.golf/golf/.gitignore
+1
rust/code.golf/golf/.gitignore
···
1
+
/target
+75
rust/code.golf/golf/Cargo.lock
+75
rust/code.golf/golf/Cargo.lock
···
1
+
# This file is automatically @generated by Cargo.
2
+
# It is not intended for manual editing.
3
+
version = 3
4
+
5
+
[[package]]
6
+
name = "atty"
7
+
version = "0.2.14"
8
+
source = "registry+https://github.com/rust-lang/crates.io-index"
9
+
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
10
+
dependencies = [
11
+
"hermit-abi",
12
+
"libc",
13
+
"winapi",
14
+
]
15
+
16
+
[[package]]
17
+
name = "colored"
18
+
version = "2.0.0"
19
+
source = "registry+https://github.com/rust-lang/crates.io-index"
20
+
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
21
+
dependencies = [
22
+
"atty",
23
+
"lazy_static",
24
+
"winapi",
25
+
]
26
+
27
+
[[package]]
28
+
name = "golf"
29
+
version = "0.1.0"
30
+
dependencies = [
31
+
"colored",
32
+
]
33
+
34
+
[[package]]
35
+
name = "hermit-abi"
36
+
version = "0.1.19"
37
+
source = "registry+https://github.com/rust-lang/crates.io-index"
38
+
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
39
+
dependencies = [
40
+
"libc",
41
+
]
42
+
43
+
[[package]]
44
+
name = "lazy_static"
45
+
version = "1.4.0"
46
+
source = "registry+https://github.com/rust-lang/crates.io-index"
47
+
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
48
+
49
+
[[package]]
50
+
name = "libc"
51
+
version = "0.2.140"
52
+
source = "registry+https://github.com/rust-lang/crates.io-index"
53
+
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
54
+
55
+
[[package]]
56
+
name = "winapi"
57
+
version = "0.3.9"
58
+
source = "registry+https://github.com/rust-lang/crates.io-index"
59
+
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
60
+
dependencies = [
61
+
"winapi-i686-pc-windows-gnu",
62
+
"winapi-x86_64-pc-windows-gnu",
63
+
]
64
+
65
+
[[package]]
66
+
name = "winapi-i686-pc-windows-gnu"
67
+
version = "0.4.0"
68
+
source = "registry+https://github.com/rust-lang/crates.io-index"
69
+
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
70
+
71
+
[[package]]
72
+
name = "winapi-x86_64-pc-windows-gnu"
73
+
version = "0.4.0"
74
+
source = "registry+https://github.com/rust-lang/crates.io-index"
75
+
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+9
rust/code.golf/golf/Cargo.toml
+9
rust/code.golf/golf/Cargo.toml
+385
rust/code.golf/golf/src/main.rs
+385
rust/code.golf/golf/src/main.rs
···
1
+
use std::env; // to access arguments
2
+
3
+
// code.golf functions begin here:
4
+
5
+
//fn twelve_days() {}
6
+
//fn bottles_of_beer() {}
7
+
8
+
fn abundant() {
9
+
for i in 0..201 {
10
+
if (1..i).into_iter().filter(|x| i % x == 0).sum::<u64>() > i {
11
+
println!("{i}");
12
+
}
13
+
}
14
+
}
15
+
16
+
fn abundant_long() {
17
+
for i in 0..1001 {
18
+
if (1..i).into_iter().filter(|x| i % x == 0).sum::<u64>() > i {
19
+
println!("{i}");
20
+
}
21
+
}
22
+
}
23
+
24
+
//fn arabic_roman() {}
25
+
//fn arrows() {}
26
+
//fn ascii_table() {}
27
+
//fn bf() {}
28
+
//fn catalan_numbers() {}
29
+
//fn catalan_const() {}
30
+
//fn christmas_tree() {}
31
+
32
+
fn collatz() {
33
+
fn calculator(n: u64, iteration: &mut u64) -> u64 {
34
+
*iteration += 1;
35
+
match n {
36
+
0 | 1 => 1,
37
+
n if n % 2 == 0 => calculator(n / 2, iteration),
38
+
_ => calculator(n * 3 + 1, iteration),
39
+
};
40
+
*iteration - 1
41
+
}
42
+
43
+
for i in 1..1001 {
44
+
let mut count: u64 = 0;
45
+
println!("{}", calculator(i, &mut count));
46
+
}
47
+
}
48
+
49
+
//fn css_colors() {}
50
+
//fn cubes() {}
51
+
//fn diamonds() {}
52
+
53
+
fn divisors() {
54
+
for i in 1u64..101 {
55
+
(1..=i)
56
+
.into_iter()
57
+
.filter(|&x| i % x == 0)
58
+
.for_each(|m| print!("{m} "));
59
+
println!();
60
+
}
61
+
}
62
+
63
+
fn emirp() {
64
+
fn prime(n: u64) -> bool {
65
+
(1..n / 2)
66
+
.into_iter()
67
+
.filter(|x| n % x == 0)
68
+
.collect::<Vec<u64>>()
69
+
.len()
70
+
< 2
71
+
}
72
+
for i in 1..1001 {
73
+
let rv: u64 = i
74
+
.to_string()
75
+
.chars()
76
+
.rev()
77
+
.collect::<String>()
78
+
.parse()
79
+
.unwrap();
80
+
81
+
if rv != i && prime(i) && prime(rv) {
82
+
println!("{i}");
83
+
}
84
+
}
85
+
}
86
+
87
+
fn emirp_long() {
88
+
fn prime(n: u64) -> bool {
89
+
(1..n / 2)
90
+
.into_iter()
91
+
.filter(|&x| n % x == 0)
92
+
.collect::<Vec<u64>>()
93
+
.len()
94
+
< 2
95
+
}
96
+
for i in 1..10001 {
97
+
let rv: u64 = i
98
+
.to_string()
99
+
.chars()
100
+
.rev()
101
+
.collect::<String>()
102
+
.parse()
103
+
.unwrap();
104
+
105
+
if rv != i && prime(i) && prime(rv) {
106
+
println!("{i}");
107
+
}
108
+
}
109
+
}
110
+
111
+
//fn emojify() {}
112
+
113
+
fn evil() {
114
+
for i in 1u8..51 {
115
+
if i.count_ones() % 2 == 0 {
116
+
println!("{i}")
117
+
}
118
+
}
119
+
}
120
+
121
+
fn evil_long() {
122
+
for i in 1u64..1001 {
123
+
if i.count_ones() % 2 == 0 {
124
+
println!("{i}")
125
+
}
126
+
}
127
+
}
128
+
129
+
fn fibonacci() {
130
+
fn fib(n: u32) -> u32 {
131
+
match n {
132
+
0 => 0,
133
+
1 => 1,
134
+
_ => fib(n - 1) + fib(n - 2),
135
+
}
136
+
}
137
+
for i in 0..31 {
138
+
println!("{}", fib(i));
139
+
}
140
+
}
141
+
142
+
fn fizzbuzz() {
143
+
for i in 1u16..101 {
144
+
let mut out = String::new();
145
+
146
+
if i % 3 == 0 {
147
+
out += "Fizz"
148
+
}
149
+
if i % 5 == 0 {
150
+
out += "Buzz"
151
+
}
152
+
153
+
if out.is_empty() {
154
+
println!("{i}")
155
+
} else {
156
+
println!("{out}")
157
+
}
158
+
}
159
+
}
160
+
161
+
fn foofizzbuzzbar() {
162
+
for i in 1u16..1001 {
163
+
let mut out = String::new();
164
+
165
+
if i % 2 == 0 {
166
+
out += "Foo"
167
+
}
168
+
if i % 3 == 0 {
169
+
out += "Fizz"
170
+
}
171
+
if i % 5 == 0 {
172
+
out += "Buzz"
173
+
}
174
+
if i % 7 == 0 {
175
+
out += "Bar"
176
+
}
177
+
178
+
if out.is_empty() {
179
+
println!("{i}")
180
+
} else {
181
+
println!("{out}")
182
+
}
183
+
}
184
+
}
185
+
186
+
//fn fractions() {}
187
+
//fn g_o_l() {}
188
+
189
+
fn happy() {
190
+
fn dc(n: u32, vec: Vec<u32>) -> Vec<u32> {
191
+
n.to_string()
192
+
.chars()
193
+
.map(|d| d.to_digit(10).unwrap().pow(2))
194
+
.fold(0, |acc, elem| acc * 10 + elem)
195
+
}
196
+
for i in 1u32..201 {
197
+
let mut ints = vec![i];
198
+
println!("{}", dc(i, &mut ints));
199
+
}
200
+
}
201
+
202
+
//fn happy_long() {}
203
+
//fn hexdump() {}
204
+
//fn intersection() {}
205
+
//fn inventory() {}
206
+
//fn isbn() {}
207
+
//fn jacobi() {}
208
+
//fn kolakoski() {}
209
+
//fn kolakoski_seq() {}
210
+
//fn leap() {}
211
+
//fn levenshtein() {}
212
+
//fn leyland() {}
213
+
//fn looknsay() {}
214
+
//fn lucky_numbers() {}
215
+
//fn lucky_tickets() {}
216
+
//fn maze() {}
217
+
//fn morse_dec() {}
218
+
//fn morse_enc() {}
219
+
//fn music_chords() {}
220
+
//fn niven() {}
221
+
//fn niven_long() {}
222
+
//fn num_spiral() {}
223
+
//fn odious() {}
224
+
//fn odious_long() {}
225
+
//fn ordinal() {}
226
+
//fn pangram() {}
227
+
//fn pascal_triangle() {}
228
+
//fn pernicious_numbers() {}
229
+
//fn pernicious_long() {}
230
+
//fn poker() {}
231
+
//fn prime() {}
232
+
//fn prime_long() {}
233
+
//fn proximity_grid() {}
234
+
//fn qr_decoder() {}
235
+
//fn quine() {}
236
+
//fn recaman() {}
237
+
//fn repeating_decimals() {}
238
+
//fn reverse_polish() {}
239
+
//fn rpssp() {}
240
+
//fn roman_arabic() {}
241
+
//fn rule_110() {}
242
+
//fn seven_segment() {}
243
+
//fn sierpinski() {}
244
+
//fn smith() {}
245
+
//fn spelling() {}
246
+
//fn star_wars() {}
247
+
//fn sudoku() {}
248
+
//fn sudoku_v2() {}
249
+
//fn time_distance() {}
250
+
//fn tongue() {}
251
+
//fn us() {}
252
+
//fn vampire() {}
253
+
//fn van_eck() {}
254
+
//fn zodiac() {}
255
+
//fn gamma() {}
256
+
//fn lambda() {}
257
+
//fn pi() {}
258
+
//fn tau() {}
259
+
//fn phi() {}
260
+
//fn root2() {}
261
+
//fn euler() {}
262
+
263
+
fn main() {
264
+
let args: Vec<String> = env::args().collect();
265
+
let hole_labels: Vec<(&str, fn())> = vec![
266
+
//("12days", twelve_days),
267
+
//("99bottles", bottles_of_beer),
268
+
("abundant", abundant),
269
+
("abundant-long", abundant_long),
270
+
//("arabic-to-roman", arabic_roman),
271
+
//("arrows", arrows),
272
+
//("ascii-table", ascii_table),
273
+
//("brainfuck", bf),
274
+
//("Catalan-numbers", catalan_numbers),
275
+
//("Catalan-constant", catalan_const),
276
+
//("christmas-tree", christmas_tree),
277
+
("collatz", collatz),
278
+
//("css", css_colors),
279
+
//("cubes", cubes),
280
+
//("diamonds", diamonds),
281
+
("divisors", divisors),
282
+
("emirp", emirp),
283
+
("emirp-long", emirp_long),
284
+
//("emojify", emojify),
285
+
("evil", evil),
286
+
("evil-long", evil_long),
287
+
("Fibonacci", fibonacci),
288
+
("FizzBuzz", fizzbuzz),
289
+
("FooFizzBuzzBar", foofizzbuzzbar),
290
+
//("fractions", fractions),
291
+
//("game-of-life", g_o_l),
292
+
("happy", happy),
293
+
//("happy-long", happy_long),
294
+
//("hexdump", hexdump),
295
+
//("intersection", intersection),
296
+
//("inventory-sequence", inventory),
297
+
//("ISBN", isbn),
298
+
//("Jacobi-symbol", jacobi),
299
+
//("Kolakoski-constant", kolakoski),
300
+
//("Kolakoski-sequence", kolakoski_seq),
301
+
//("leap", leap),
302
+
//("Levenshtein", levenshtein),
303
+
//("Leyland", leyland),
304
+
//("look-and-say", looknsay),
305
+
//("lucky-numbers", lucky_numbers),
306
+
//("lucky-tickets", lucky_tickets),
307
+
//("maze", maze),
308
+
//("morse-decoder", morse_dec),
309
+
//("morse-encoder", morse_enc),
310
+
//("musical-chords", music_chords),
311
+
//("Niven", niven),
312
+
//("Niven-long", niven_long),
313
+
//("number-spiral", num_spiral),
314
+
//("odious", odious),
315
+
//("odious-long", odious_long),
316
+
//("ordinal-numbers", ordinal),
317
+
//("pangram-grep", pangram),
318
+
//("Pascal-triangle", pascal_triangle),
319
+
//("pernicious-numbers", pernicious_numbers),
320
+
//("pernicious-long", pernicious_long),
321
+
//("poker", poker),
322
+
//("prime", prime),
323
+
//("prime-long", prime_long),
324
+
//("proximity-grid", proximity_grid),
325
+
//("QR-decoder", qr_decoder),
326
+
//("Quine", quine),
327
+
//("Recaman", recaman),
328
+
//("repeating-decimals", repeating_decimals),
329
+
//("reverse-polish", reverse_polish),
330
+
//("rock-papers-scissors-spock", rpssp),
331
+
//("roman-to-arabic", roman_arabic),
332
+
//("rule110", rule_110),
333
+
//("seven-segment", seven_segment),
334
+
//("Sierpinski-triangle", sierpinski),
335
+
//("Smith-numbers", smith),
336
+
//("spelling-numbers", spelling),
337
+
//("Star-Wars-crawl", star_wars),
338
+
//("sudoku", sudoku),
339
+
//("sudokuv2", sudoku_v2),
340
+
//("time-distance", time_distance),
341
+
//("tongue-twister", tongue),
342
+
//("US", us),
343
+
//("vampire-numbersr", vampire),
344
+
//("Van-Eck-sequence", van_eck),
345
+
//("zodiac-signs", zodiac),
346
+
//("Euler-Mascheroni", gamma),
347
+
//("Conway", lambda),
348
+
//("pi", pi),
349
+
//("tau", tau),
350
+
//("golden-ratio", phi),
351
+
//("Pythagoras", root2),
352
+
//("Euler", euler),
353
+
];
354
+
if args.len() == 1 {
355
+
println!("Error: No hole specified.");
356
+
println!("The holes available are:\n");
357
+
for i in &hole_labels {
358
+
println!("\t{}", i.0);
359
+
}
360
+
panic!("To view a hole: golf {{HOLE}}");
361
+
}
362
+
363
+
if args.len() == 2 {
364
+
let index = hole_labels
365
+
.iter()
366
+
.position(|&r| {
367
+
return r.0
368
+
== args
369
+
.get(1)
370
+
.expect("This literally shouldn't be possible")
371
+
.as_str();
372
+
})
373
+
.expect("Hole not found");
374
+
hole_labels
375
+
.get(index)
376
+
.expect("Error indexing hole tuples array")
377
+
.1();
378
+
}
379
+
// "-h" | "--help" | "help" => {
380
+
// println!("");
381
+
// println!("The holes available are:\n");
382
+
// for i in &hole_labels {
383
+
// println!("\t{}", i.0)
384
+
// }
385
+
}
+18
rust/code.golf/golf/src/neovide_backtraces.log
+18
rust/code.golf/golf/src/neovide_backtraces.log
···
1
+
2023-03-10 15:48:41 - Neovide panicked with the message 'Resize failed: DecodeError(ReaderError(Custom { kind: UnexpectedEof, error: "EOF" }), "nvim_ui_try_resize")'. (File: src/bridge/ui_commands.rs; Line: 139, Column: 18)
2
+
0: <unknown>
3
+
1: <unknown>
4
+
2: <unknown>
5
+
3: <unknown>
6
+
4: <unknown>
7
+
5: <unknown>
8
+
6: <unknown>
9
+
7: <unknown>
10
+
8: <unknown>
11
+
9: <unknown>
12
+
10: <unknown>
13
+
11: <unknown>
14
+
12: <unknown>
15
+
13: <unknown>
16
+
14: <unknown>
17
+
15: <unknown>
18
+