Forked from RealLogical/IJustWantedToPlayMinecraft.py
Last active
January 17, 2021 15:47
-
-
Save Alex4386/701cff54d72537bd392771db3109ac88 to your computer and use it in GitHub Desktop.
Editted IJustWantedToPlayMinecraft using Recursion
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
| # DP ์จ๋ ๋๊ธด ํ๋๋ฐ ๊ทธ๋ฅ | |
| # Recursive ๋ก ์ธ์์ | |
| # ์๊น ์ฝ๋ | |
| # A B C D E | |
| colors = [ 0, 0, 0, 0, 0 ] | |
| # ์กฐ๊ฑด์ ์ถฉ์กฑํ๋ ์ง ํ์ธํ๋ ์ฝ๋ | |
| def check_condition(colors): | |
| return ( | |
| colors[0] != colors[1] and # A๋ B๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[0] != colors[2] and # A๋ C๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[0] != colors[3] and # A๋ D๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[0] != colors[4] and # A๋ E๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[1] != colors[2] and # B๋ C๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[2] != colors[3] and # C๋ D๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| colors[3] != colors[4] # D๋ E๋ ์๊น์ด ๊ฐ์ ์ ์๋ค. | |
| ) | |
| # idx ๋ฒ์งธ ์นธ์ ์๊น์ ์น ํฉ๋๋ค | |
| def coloring_it(colors, idx): | |
| # ์กฐ๊ฑด ๋ง์กฑํ๋ ๊ฑฐ ์ธ๋๊ฑฐ๋... | |
| count = 0 | |
| # ์ ์ฒด ์ธ๋ ๊ฑฐ ๋ณ์ ์ ์ | |
| total_count = 0 | |
| # ์ผ๋จ ๋ณต์ฌ๋ ํด์ค์. C๋ก ์น๋ฉด ํฌ์ธํฐ๊ฐ ๊ฐ๊ธฐ ๋๋ฌธ์. | |
| # ์ฌ์ค ์ํด์ค๋ ์๊ด์ ์๋๋ฐ, ํ์คํ๊ฒ ํ๊ธฐ ์ํด์. | |
| colors_tmp = colors.copy() | |
| # ์ ์นธ๋ค์ ์น ํ ์ ์๋ ์๊น์ ์ต๋ ๊ฐ์ง์๋ | |
| # ์์ ์น ํ ์ ์๋ ์นธ์ ์! | |
| # | |
| # ์๊น์ ํ๋์ฉ ์น ํด๋ณธ๋ค. | |
| for color in range(len(colors_tmp)): | |
| this_count = 0 | |
| this_total_count = 0 | |
| # ์๊น์ ์น ํ๊ณ , | |
| colors_tmp[idx] = color | |
| # ๋ง์ง๋ง ๊น์ง ์น ํ๋ค๋ฉด? | |
| if (len(colors_tmp) - 1) == idx: | |
| # ์กฐ๊ฑด์ ๋ง๋์ง ํ์ธํด ๋ณด๊ณ | |
| if check_condition(colors_tmp): | |
| # ์กฐ๊ฑด์ ๋ง๋ ๊ฑฐ ์ธ๋ ๋ณ์์ ํ๋ ๋ํ๊ธฐ | |
| this_count += 1 | |
| # ์กฐ๊ฑด์ ์ ๋ง์๋ ์ ์ฒด ๋ณ์์๋ ์ฌ๋ฆฌ๊ธฐ | |
| this_total_count += 1 | |
| else: | |
| # ์๋๋ผ๋ฉด ๋ค์๋ฒ์งธ ๊ตฌํ๊ธฐ | |
| this_count, this_total_count = coloring_it(colors_tmp, idx+1) | |
| # ์ด๋ฒ ์๊น ์น ํ ๊ฒ์ ์ ์ฒด ๊ฐ์ง์์ ๋ํ๊ธฐ | |
| count += this_count | |
| total_count += this_total_count | |
| # ์ด๋ฒ ํ์์ ์๊น ์น ํ๊ฒ์ ์ ์ผ์ด์ค๋ก ๋ด๋ฑ๊ธฐ, ํท! | |
| return (count, total_count) | |
| # ์๊น~ ์น ํ๊ธฐ~ ๋์ด~ ์คํํธ~ | |
| count, total_count = coloring_it(colors, 0) | |
| print("์ ์ฒด ๊ฒฝ์ฐ์ ์: " + str(total_count) + "\n์กฐ๊ฑด๊ณผ ์ผ์นํ๋ ๊ฒฝ์ฐ์ ์: " + str(count)) | |
| print("๋ต: " + str(count)) |
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
| /* | |
| ๋ฌ์คํธ๋ก ์ฝ๋ ์ง๊ธฐ~ | |
| ๊ฒ์ ๋ฌ์คํธ ์๋๋ค. | |
| */ | |
| // ์ด๊ฑด ์ฃผ์ ์ ๊ธฐ ๊ท์ฐฎ์์~ | |
| fn check_condition(colors: Vec<i32>) -> bool { | |
| colors[0] != colors[1] && | |
| colors[0] != colors[2] && | |
| colors[0] != colors[3] && | |
| colors[0] != colors[4] && | |
| colors[1] != colors[2] && | |
| colors[2] != colors[3] && | |
| colors[3] != colors[4] | |
| } | |
| fn color_it(colors: &mut Vec<i32>, i: i32) -> i32 { | |
| let mut count: i32 = 0; | |
| let max_color_count = colors.len(); | |
| for color_id in 0..max_color_count { | |
| colors[i as usize] = color_id as i32; | |
| if i == (colors.len() - 1) as i32 { | |
| if check_condition((&colors).to_vec()) { | |
| count += 1; | |
| } | |
| } else { | |
| count += color_it(colors, i+1); | |
| } | |
| } | |
| return count | |
| } | |
| fn main() { | |
| let mut vec: Vec<i32> = vec!(0,0,0,0,0); | |
| let count = color_it(&mut vec, 0); | |
| println!("{}", count); | |
| } |
Author
Author
Author
2021-01-05: Rust ์ธ์ด ๊ตฌํ์ฒด ์ถ๊ฐ.
์ฌ๋ฌ๋ถ๋ Rust ํ์ธ์
์ฅํฉํ ์ฝ๋๋ฅผ ๋ณด๊ณ ์ค๋ง ํฌํฌ๊ฐ ์๊ฒ ์ด... ์ถ์ด ๋ค์ด์๋๋ฐ ๋๋ฌด๋ ๊ณ ํ๋ฆฌํฐ ์ฃผ์์ด ํจ์ ๋ ์ฝ๋๋ค์. ์ฌ์ง์ด ์ ํ ์๊ฐ์ง๋ ์์๋ Recursive ๊ตฌํ๋ฒ๊น์ง ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค. ๐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

P.S. ์ PS ๋ชปํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ผ๋ถ๋ฌ ์ต์ ํ ์ํ๊ฑฐ์์.