Created
August 8, 2021 00:47
-
-
Save AngelOnFira/972377921ed5887a29cb7f7dfa8450d8 to your computer and use it in GitHub Desktop.
[EFFICITENT] [NOT CLICKBAIT] [PROVEN INNO] Drunken bishop algorithm from https://www.jfurness.uk/the-drunken-bishop-algorithm/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{collections::HashMap, thread, time}; | |
| fn main() { | |
| let char_map = " .o+=*B0X@%&#/^".to_string(); | |
| // Couldn't figure out how to change hex to binary | |
| let text = "000010110101111000100011100111000101010001000000000011000100100010110010100010101000011111110101011000111010001000011110001001000101011001000101111110111111110100101010111111110001101110010110000011101110101011000101000001100100101011111000001101001110100010101001001101010011001011110000101101001010100010011000101010110111100011000001001100100000000000110010011100110110001011001101110100110110111011110101101110101011100110111010110011110010101101011000100000101100100000010001001011011000001101111101110101111111101011010010010111101101110001010011010011111000101010100011101110011011010100101000101110100110101100100001111101111011001101001000101110110100010010011100010010110111111101101000010001010000011110111001011001110000111111111000100100111000111001111111110000001011010000000011101001101000100011101101111011010000011110000111101000100111100100110110110101100001011000101101011010100100100111010100010111101111000011111001101110100011010010011001001110000001111010001111110011110111101100000011001011100101010000100100100100010101001101000001101011110101111010110010000110001001000101001100100000000001101000001011100000001011111010000111000001010110010000000110000110010101111110011110011010110011001001100110000100011010100011001001110101111111000110010101111001101011010010110101110011000011010001110101111101010100000111000110011000101100011100111101001111111100000010010011110010100010010001101101100111101110010100000011000101100000010101111001010000110101101111011100010111100101111000001000110010000111001100001001101011001101001010011100101100010001001100010010010010011011111011".to_string(); | |
| let mut map: HashMap<(i32, i32), i32> = HashMap::new(); | |
| let width = 17; | |
| let height = 17; | |
| let mut pos = ((width - 1) / 2 + 1, (height - 1) / 2 + 1); | |
| let mut counter = 0; | |
| for crumb in text.chars().collect::<Vec<char>>().chunks(2) { | |
| let dir = match &(crumb.iter().collect::<String>())[..] { | |
| "00" => (-1, -1), | |
| "01" => (1, -1), | |
| "10" => (-1, 1), | |
| "11" => (1, 1), | |
| _ => unimplemented!(), | |
| }; | |
| pos.0 += dir.0; | |
| pos.1 += dir.1; | |
| // wrap around if we go outside of width and height | |
| if pos.0 < 0 { | |
| pos.0 += width; | |
| } | |
| if pos.1 < 0 { | |
| pos.1 += height; | |
| } | |
| if pos.0 >= width { | |
| pos.0 -= width; | |
| } | |
| if pos.1 >= height { | |
| pos.1 -= height; | |
| } | |
| *map.entry(pos).or_insert(0) += 1; | |
| counter += 1; | |
| if counter % 10 == 0 { | |
| for y in 0..height { | |
| for x in 0..width { | |
| print!( | |
| "{}", | |
| char_map | |
| .chars() | |
| .nth(*map.get(&(x, y)).unwrap_or(&0) as usize) | |
| .unwrap() | |
| ); | |
| } | |
| print!("\n"); | |
| } | |
| } | |
| thread::sleep(time::Duration::from_millis(10)); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eb5115f0b3f0a13090f82bb34b87e88b