【随時更新】主要プログラミング言語8種チートシート


# はじめに

- 個人的に主要言語と思う8言語＆スクリプト（python, JavaScript, Rust, Haskell, C++, C#, bash, PowerShell)のチートシートです
- インデントのために全角空白を含んでます。コピペする場合は気を付けて下さい
- ChatGPT(GPT-4)に書かせたコードなので一部変なコードがあるかもしれません
 - 動かない場合はChatGPTにコードと一緒に"＜プログラミング名＞で＜大分類名＞の＜小分類名＞をやろうと思うんだけど、このコードを修正して。"的なことを書けば大抵の場合修正してくれます

# チートシート

## スプレッドシート版（こちらのほうが見やすいです）
https://1drv.ms/x/s!AqxcPJT01sLlgdx8vuzZMu37vlSaaQ?e=OxJADc


## 記事版(中身はスプレッドシート版と同じです)

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 基礎 | 変数定義(ミュータブル) | `a=1` | `let a=1` | `let mut a=1` | `let a=1` | `int a=1` | `int a=1` | `$a=1` | `$a=1` |
↓↓↓↓↓↓↓ あなたの記事の内容
| 基礎 | 変数定義(イミュータブル) | -- | `const x = 1` | `let x = 1` | `let x = 1` | `const int x = 1` | `const int x = 1` | `readonly x=1` | `$x = 1` |
───────
| 基礎 | 変数定義(イミュータブル) | `X = 1` | `const x = 1` | `let x = 1` | `let x = 1` | `const int x = 1` | `const int x = 1` | `readonly x=1` | `$x = 1` |
↑↑↑↑↑↑↑ 編集リクエストの内容
| 計算 | 二項演算子 | `result = 1 + 2` | `const result = 1 + 2;` | `let result = 1 + 2;` | `result = 1 + 2` | `int result = 1 + 2;` | `int result = 1 + 2;` | `result=$((1 + 2))` | `$result = 1 + 2` |
| 計算 | 論理演算子 | `result = True and False` | `const result = true && false;` | `let result = true && false;` | `result = True && False` | `bool result = true && false;` | `bool result = true && false;` | `result=$(true && false)` | `$result = $true -and $false` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 比較演算子 | 等価 | `result = 1 == 2` | `const result = 1 == 2;` | `let result = 1 == 2;` | `result = 1 == 2` | `bool result = 1 == 2;` | `bool result = 1 == 2;` | `result=$((1 == 2))` | `$result = 1 -eq 2` |
| 比較演算子 | 不等価 | `result = 1 != 2` | `const result = 1 != 2;` | `let result = 1 != 2;` | `result = 1 /= 2` | `bool result = 1 != 2;` | `bool result = 1 != 2;` | `result=$((1 != 2))` | `$result = 1 -ne 2` |
| 比較演算子 | 大小比較 | `result = 1 < 2` | `const result = 1 < 2;` | `let result = 1 < 2;` | `result = 1 < 2` | `bool result = 1 < 2;` | `bool result = 1 < 2;` | `result=$((1 < 2))` | `$result = 1 -lt 2` |
| 条件分岐 | if 文 | `if a > b:`<br/>　　`print("a > b")`<br/>`else:`<br/>　　`print("a <= b")` | `if (a > b) {`<br/>　　`console.log("a > b");`<br/>`} else {`<br/>　　`console.log("a <= b");`<br/>`}` | `if a > b {`<br/>　　`println!("a > b");`<br/>`} else {`<br/>　　`println!("a <= b");`<br/>`}` | `if a > b then`<br/>　　`putStrLn "a > b"`<br/>`else`<br/>　　`putStrLn "a <= b"` | `if (a > b) {`<br/>　　`std::cout << "a > b" << std::endl;`<br/>`} else {`<br/>　　`std::cout << "a <= b" << std::endl;`<br/>`}` | `if (a > b)`<br/>`{`<br/>　　`Console.WriteLine("a > b");`<br/>`}`<br/>`else`<br/>`{`<br/>　　`Console.WriteLine("a <= b");`<br/>`}` | `if [ $a -gt $b ]; then`<br/>　　`echo "a > b"`<br/>`else`<br/>　　`echo "a <= b"`<br/>`fi` | `if ($a -gt $b) {`<br/>　　`Write-Host "a > b"`<br/>`} else {`<br/>　　`Write-Host "a <= b"`<br/>`}` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 繰り返し | for 文 | `for i in range(5):`<br/>　　`print(i)` | `for (let i = 0; i < 5; i++) {`<br/>　　`console.log(i);`<br/>`}` | `for i in 0..5 {`<br/>　　`println!("{}", i);`<br/>`}` | `forM_ [0..4] $ \i ->`<br/>　　`print i` | `for (int i = 0; i < 5; i++) {`<br/>　　`std::cout << i << std::endl;`<br/>`}` | `for (int i = 0; i < 5; i++)`<br/>`{`<br/>　　`Console.WriteLine(i);`<br/>`}` | `for i in {0..4}; do`<br/>　　`echo $i`<br/>`done` | `for ($i = 0; $i-lt 5; $i++) {`<br/>　　`Write-Host $i`<br/>`}` |
| 繰り返し | while 文 | `i = 0`<br/>`while i < 5:`<br/>　　`i += 1` | `let i = 0`<br/>`while (i < 5) {`<br/>　　`i++;`<br/>`}` | `let mut i = 0;`<br/>`while i < 5 {`<br/>　　`i += 1;`<br/>`}` | `i <- 0`<br/>`while (i < 5) $ do`<br/>　　`i <- i + 1` | `int i = 0;`<br/>`while (i < 5) {`<br/>　　`i++;`<br/>`}` | `int i = 0;`<br/>`while (i < 5) {`<br/>　　`i++;`<br/>`}` | `i=0`<br/>`while [ $i -lt 5 ]; do`<br/>　　`((i++))`<br/>`done` | `$i = 0`<br/>`while ($i -lt 5) {`<br/>　　`$i++`<br/>`}` |
| 関数 | 関数定義 | `def add(a, b):`<br/>　　`return a + b` | `function add(a, b) {`<br/>　　`return a + b;`<br/>`}` | `fn add(a: i32, b: i32) -> i32 {`<br/>　　`a + b`<br/>`}` | `add a b = a + b` | `int add(int a, int b) {`<br/>　　`return a + b;`<br/>`}` | `int Add(int a, int b)`<br/>`{`<br/>　　`return a + b;`<br/>`}` | `add() {`<br/>　　`echo $(($1 + $2))`<br/>`}` | `function Add($a, $b) {`<br/>　　`return $a + $b`<br/>`}` |
| 関数 | 関数呼び出し | `result = add(2, 3)`<br/>`print(result)` | `let result = add(2, 3);`<br/>`console.log(result);`<br/>`}` | `let result = add(2, 3);`<br/>`println!("{}", result);`<br/>`}` | `let result = add 2 3`<br/>`print result` | `int result = add(2, 3);`<br/>`std::cout << result << std::endl;`<br/>`}` | `int result = Add(2, 3);`<br/>`Console.WriteLine(result);`<br/>`}` | `result=$(add 2 3)`<br/>`echo $result` | `$result = Add(2, 3)`<br/>`Write-Host $result` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 関数 | 関数の引数 | `def greet(name):`<br/>　　`return f"Hello, {name}!"` | `function greet(name) {`<br/>　　`return Hello, ${name}!;`<br/>`}` | `fn greet(name: &str) -> String {`<br/>　　`format!("Hello, {}!", name)`<br/>`}` | `greet :: String -> String`<br/>`greet name = "Hello, " ++ name ++ "!"` | `std::string greet(std::string name) {`<br/>　　`return "Hello, " + name + "!";`<br/>`}` | `public static string Greet(string name) {`<br/>　　`return $"Hello, {name}!";`<br/>`}` | `greet() {`<br/>　　`echo "Hello, $1!"`<br/>`}` | `function Greet($name) {`<br/>　　`return "Hello, $name!"`<br/>`}` |
| 関数 | ラムダ関数 | `add = lambda x, y: x + y` | `const add = (x, y) => x + y;` | `let add = \|x: i32, y: i32\| x + y;` | `add = \x y -> x + y` | `auto add = [](int x, int y) { return x + y; };` | `Func<int, int, int> add = (x, y) => x + y;` | `add() {`<br/>　　`echo $(($1 + $2))`<br/>`}` | `$add = { param($x, $y) return $x + $y }` |
| 関数 | ジェネレータ関数 | `def gen_func():`<br/>　　`yield 1`<br/>　　`yield 2`<br/>　　`yield 3` | `function* gen_func() {`<br/>　　`yield 1;`<br/>　　`yield 2;`<br/>　　`yield 3;` }` | `fn gen_func() -> impl Iterator<Item=i32> {`<br/>　　`vec![1, 2, 3].into_iter()`<br/>`}` | `gen_func = [1, 2, 3]` | `std::vector<int> gen_func() {`<br/>　　`return {1, 2, 3};`<br/>`}` | `IEnumerable<int> GenFunc() {`<br/>　　`yield return 1;`<br/>　　`yield return 2;`<br/>　　`yield return 3;` }` | `gen_func() {`<br/>　　`echo 1`<br/>　　`echo 2`<br/>　　`echo 3`<br/>`}` | `function Gen-Func {`<br/>　　`1, 2, 3`<br/>`}` |
| ファイル | ファイルの読み込み | `with open('file.txt', 'r') as f:`<br/>　　`content = f.read()` | `fs = require('fs');`<br/>`content = fs.readFileSync('file.txt', 'utf8');`<br/>`}` | `use std::fs;`<br/>`let content = fs::read_to_string("file.txt").unwrap();`<br/>`}` | `content <- readFile "file.txt"` | `std::ifstream file("file.txt");`<br/>`std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());`<br/>`}` | `using (StreamReader sr = new StreamReader("file.txt"))`<br/>`{`<br/>　　`string content = sr.ReadToEnd();`<br/>`}` | `content=$(cat file.txt)` | `$content = Get-Content -Path 'file.txt' -Raw`<br/>`}` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| ファイル | ファイルの書き込み | `with open('file.txt', 'w') as f:`<br/>　　`f.write('Hello, World!')` | `fs = require('fs');`<br/>`fs.writeFileSync('file.txt', 'Hello, World!', 'utf8');`<br/>`}` | `use std::fs::File;`<br/>`use std::io::Write;`<br/>`let mut file = File::create("file.txt").unwrap();`<br/>`file.write_all(b"Hello, World!").unwrap();`<br/>`}` | `writeFile "file.txt" "Hello, World!"` | `std::ofstream file("file.txt");`<br/>`file << "Hello, World!";`<br/>`file.close();`<br/>`}` | `using (StreamWriter sw = new StreamWriter("file.txt"))`<br/>`{`<br/>　　`sw.Write("Hello, World!");`<br/>`}` | `echo 'Hello, World!' > file.txt` | `Set-Content -Path 'file.txt' -Value 'Hello, World!'`<br/>`}` |
| リスト | リストの生成 | `lst = [1, 2, 3]` | `let lst = [1, 2, 3];` | `let lst = vec![1, 2, 3];` | `lst = [1, 2, 3]` | `std::vector<int> lst = {1, 2, 3};` | `List<int> lst = new List<int> { 1, 2, 3 };` | `lst=(1 2 3)` | `$lst = @(1, 2, 3)` |
| リスト | リストの要素追加 | `lst.append(4)` | `lst.push(4);` | `lst.push(4);` | `lst = lst ++ [4]` | `lst.push_back(4);` | `lst.Add(4);` | `lst+=("4")` | `$lst += 4` |
| リスト | リストの要素削除 | `lst.remove(2)` | `lst.splice(lst.indexOf(2), 1);` | `lst.retain(\|&x\| x != 2);` | `lst = filter (/=2) lst` | `lst.erase(std::remove(lst.begin(), lst.end(), 2), lst.end());` | `lst.Remove(2);` | `lst=("${lst[@]/2}")` | `$lst = $lst -ne 2` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| リスト | リストの長さ取得 | `len([1, 2, 3])` | `[1, 2, 3].length;` | `vec![1, 2, 3].len()` | `length [1, 2, 3]` | `std::vector<int> v = {1, 2, 3};`<br/>`v.size();` | `int[] arr = {1, 2, 3};`<br/>`arr.Length;` | `array=(1 2 3)`<br/>`echo ${#array[@]}` | `@(1, 2, 3).Count` |
| リスト | リストのスライス | `my_list = [1, 2, 3, 4, 5] `<br/> `sliced_list = my_list[1:4] ` | `const my_list = [1, 2, 3, 4, 5]; `<br/> `const sliced_list = my_list.slice(1, 4); ` | `let my_list = vec![1, 2, 3, 4, 5]; `<br/> `let sliced_list = &my_list[1..4]; ` | `my_list = [1, 2, 3, 4, 5] `<br/> `sliced_list = take 3 (drop 1 my_list) ` | `std::vector<int> my_list{1, 2, 3, 4, 5}; `<br/> `std::vector<int> sliced_list(my_list.begin() + 1, my_list.begin() + 4); ` | `List<int> my_list = new List<int> {1, 2, 3, 4, 5}; `<br/> `List<int> sliced_list = my_list.GetRange(1, 3); ` | `my_list=(1 2 3 4 5) `<br/> `sliced_list=("${my_list[@]:1:3}") ` | `$my_list = @(1, 2, 3, 4, 5) `<br/> `$sliced_list = $my_list[1..3] ` |
| リスト | ソート | `s=['a','d','c']`<br/>`s.sorted()` | `let numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];`<br/>`numbers.sort((a, b)=>(a - b));` | `let mut numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];`<br/>`numbers.sort();` | `let numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]`<br/>`let sortedNumbers = sort numbers` | `int numbers[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5};`<br/>`int n = sizeof(numbers) / sizeof(numbers[0]);`<br/>`std::sort(numbers, numbers + n);` | `int[] numbers = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 };`<br/>`Array.Sort(numbers);` | `numbers=(3 1 4 1 5 9 2 6 5 3 5)`<br/>`sorted=($(echo "${numbers[@]}" \| tr ' ' '\n' \| sort -n))` | `$numbers = 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5`<br/>`$sorted = $numbers \| Sort-Object` |
| 文字列 | 文字列の結合 | `s1 = 'hello'`<br/>`s2 = 'world'`<br/>`s3 = s1 + ' ' + s2` | `let s1 = 'hello';`<br/>`let s2 = 'world';`<br/>`let s3 = s1 + ' ' + s2;` | `let s1 = String::from("hello");`<br/>`let s2 = String::from("world");`<br/>`let s3 = format!("{} {}", s1, s2);` | `s1 = "hello"`<br/>`s2 = "world"`<br/>`s3 = s1 ++ " " ++ s2` | `std::string s1 = "hello";`<br/>`std::string s2 = "world";`<br/>`std::string s3 = s1 + " " + s2;` | `string s1 = "hello";`<br/>`string s2 = "world";`<br/>`string s3 = s1 + " " + s2;` | `s1="hello"`<br/>`s2="world"`<br/>`s3="${s1} ${s2}"` | `$s1 = "hello"`<br/>`$s2 = "world"`<br/>`$s3 = $s1 + " " + $s2` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 文字列 | 文字列の分割 | `s = 'a,b,c'`<br/>`lst = s.split(',')` | `let s = 'a,b,c';`<br/>`let lst = s.split(',');` | `let s = "a,b,c";`<br/>`let lst: Vec<&str> = s.split(',').collect();` | `s = "a,b,c"`<br/>`lst = splitOn "," s` | `std::string s = "a,b,c";`<br/>`std::vectorstd::string lst;`<br/>`std::istringstream ss(s);`<br/>`std::string token;`<br/>`while (std::getline(ss, token, ',')) {`<br/>　　`lst.push_back(token);`<br/>`}` | `string s = "a,b,c";`<br/>`string[] lst = s.Split(',');` | `s="a,b,c"`<br/>`IFS=',' read -ra lst <<< "$s"` | `$s = "a,b,c"`<br/>`$lst = $s -split ','` |
| 文字列 | 文字列長取得 | `len("hello")` | `"hello".length;` | `"hello".len()` | `length "hello"` | `std::string s = "hello";`<br/>`s.length();` | `"hello".Length;` | `echo -n "hello" \| wc -c` | `("hello").Length` |
| 文字列 | 文字列置換 | `"hello world".replace("world", "everyone")` | `"hello world".replace("world", "everyone");` | `"hello world".replace("world", "everyone")` | `substitute "world" "everyone" "hello world"` | `std::string s = "hello world";`<br/>`std::replace(s.begin(), s.end(), "world", "everyone");` | `"hello world".Replace("world", "everyone");` | `echo "hello world" \| sed 's/world/everyone/'` | `"hello world".Replace("world", "everyone")` |
| 文字列 | 文字列の大文字化 | `s = "hello"`<br/>`upper_s = s.upper()` | `let s = "hello";`<br/>`let upper_s = s.toUpperCase();` | `let s = "hello".to_string();`<br/>`let upper_s = s.to_uppercase();` | `s = "hello"`<br/>`upper_s = map toUpper s` | `std::string s = "hello";`<br/>`std::transform(s.begin(), s.end(), s.begin(), ::toupper);` | `string s = "hello";`<br/>`string upper_s = s.ToUpper();` | `s="hello"`<br/>`upper_s="${s^^}"` | `$s = "hello"`<br/>`$upper_s = $s.ToUpper()` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 文字列 | 文字列の小文字化 | `s = "HELLO"`<br/>`lower_s = s.lower()` | `let s = "HELLO";`<br/>`let lower_s = s.toLowerCase();` | `let s = "HELLO".to_string();`<br/>`let lower_s = s.to_lowercase();` | `s = "HELLO"`<br/>`lower_s = map toLower s` | `std::string s = "HELLO";`<br/>`std::transform(s.begin(), s.end(), s.begin(), ::tolower);` | `string s = "HELLO";`<br/>`string lower_s = s.ToLower();` | `s="HELLO"`<br/>`lower_s="${s,,}"` | `$s = "HELLO"`<br/>`$lower_s = $s.ToLower()` |
| 文字列 | 文字列の検索 | `text = "Hello, World!"`<br/>`index = text.find("World")` | `const text = "Hello, World!";`<br/>`const index = text.indexOf("World");` | `let text = "Hello, World!";`<br/>`let index = text.find("World");` | `text = "Hello, World!"`<br/>`index = Data.List.findIndex "World" text` | `std::string text = "Hello, World!";`<br/>`size_t index = text.find("World");` | `string text = "Hello, World!";`<br/>`int index = text.IndexOf("World");` | `text="Hello, World!"`<br/>`index=$(echo "$text" \| grep -b -o "World" \| cut -d: -f1)` | `$text = "Hello, World!"`<br/>`$index = $text.IndexOf("World")` |
| 文字列 | 文字列の逆順 | `text = "Hello, World!"`<br/>`reversed_text = text[::-1]` | `const text = "Hello, World!";`<br/>`const reversed_text = text.split("").reverse().join("");` | `let text = "Hello, World!";`<br/>`let reversed_text = text.chars().rev().collect::<String>();` | `text = "Hello, World!"`<br/>`reversed_text = reverse text` | `std::string text = "Hello, World!";`<br/>`std::reverse(text.begin(), text.end());` | `string text = "Hello, World!";`<br/>`char[] charArray = text.ToCharArray();`<br/>`Array.Reverse(charArray);`<br/>`string reversed_text = new string(charArray);` | `text="Hello, World!"`<br/>`reversed_text=$(echo "$text" \| rev)` | `$text = "Hello, World!"`<br/>`$reversed_text = -join ($text[-1..-($text.Length)])` |
| 文字列 | 文字列の繰り返し | `text = "abc" `<br/> `repeated_text = text * 3 ` | `const text = "abc"; `<br/> `const repeated_text = text.repeat(3); ` | `let text = "abc"; `<br/> `let repeated_text = text.repeat(3); ` | `text = "abc" `<br/> `repeated_text = concat $ replicate 3 text ` | `std::string text = "abc"; `<br/> `std::string repeated_text(text, 3); ` | `string text = "abc"; `<br/> `string repeated_text = new StringBuilder().Insert(0, text, 3).ToString(); ` | `text="abc" `<br/> `repeated_text=$(printf "%.0s$text" {1..3}) ` | `$text = "abc" `<br/> `$repeated_text = $text * 3 ` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 文字列 | 文字列の一部取得 | `text = "abcde" `<br/> `substring = text[1:4] ` | `const text = "abcde"; `<br/> `const substring = text.slice(1, 4); ` | `let text = "abcde"; `<br/> `let substring = &text[1..4]; ` | `text = "abcde" `<br/> `substring = take 3 $ drop 1 text ` | `std::string text = "abcde"; `<br/> `std::string substring = text.substr(1, 3); ` | `string text = "abcde"; `<br/> `string substring = text.Substring(1, 3); ` | `text="abcde" `<br/> `substring=${text:1:3} ` | `$text = "abcde" `<br/> `$substring = $text.Substring(1, 3) ` |
| 文字列 | 文字列の一部置換 | `text = "hello world" `<br/> `replaced_text = text.replace("world", "python") ` | `const text = "hello world"; `<br/> `const replaced_text = text.replace("world", "python"); ` | `let text = String::from("hello world"); `<br/> `let replaced_text = text.replace("world", "python"); ` | `text = "hello world" `<br/> `replaced_text = replace "world" "python" text ` | `std::string text = "hello world"; `<br/> `std::string replaced_text = text; `<br/> `size_t pos = replaced_text.find("world"); `<br/> `if (pos != std::string::npos) { replaced_text.replace(pos, 5, "python"); } ` | `string text = "hello world"; `<br/> `string replaced_text = text.Replace("world", "python"); ` | `text="hello world" `<br/> `replaced_text="${text/world/python}" ` | `$text = "hello world" `<br/> `$replaced_text = $text.Replace("world", "python") ` |
| 辞書 | 生成 | `d = {'a': 1, 'b': 2, 'c': 3}` | `let d = {'a': 1, 'b': 2, 'c': 3};` | `let d = [("a", 1), ("b", 2), ("c", 3)].iter().cloned().collect();` | `d = [("a", 1), ("b", 2), ("c", 3)]` | `std::map<std::string, int> d = {{"a", 1}, {"b", 2}, {"c", 3}};` | `Dictionary<string, int> d = new Dictionary<string, int> { { "a", 1 }, { "b", 2 }, { "c", 3 } };` | `declare -A d=( ["a"]=1 ["b"]=2 ["c"]=3 )` | `$d = @{ "a" = 1; "b" = 2; "c" = 3 }` |
| 辞書 | 要素の取得 | `value = d['a']` | `let value = d['a'];` | `let value = d.get("a").unwrap();` | `value = lookup "a" d` | `int value = d["a"];` | `int value = d["a"];` | `value="${d["a"]}"` | `$value = $d["a"]` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 辞書 | 要素の追加 | `d['d'] = 4` | `d['d'] = 4;` | `d.insert("d", 4);` | `d = insert "d" 4 d` | `d.insert(std::pair<std::string, int>("d", 4));` | `d.Add("d", 4);` | `d+=( ["d"]=4 )` | `$d.Add("d", 4)` |
| 辞書 | 要素の削除 | `del d['a']` | `delete d['a'];` | `d.remove("a");` | `d = delete "a" d` | `d.erase("a");` | `d.Remove("a");` | `unset d["a"]` | `$d.Remove("a")` |
| エラー処理 | try-except | `try:`<br/>　　`...`<br/>`except:`<br/>　　`...` | `try {`<br/>　　`...`<br/>`} catch (error) {`<br/>　　`...`<br/>`}` | `match func() {`<br/>　　`Ok() => {...},`<br/>　　`Err() => {...},`<br/>`}` | `case func of`<br/>　　`Left e -> ...`<br/>　　`Right r -> ...` | `try {`<br/>　　`...`<br/>`} catch (...) {`<br/>　　`...`<br/>`}` | `try {`<br/>　　`...`<br/>`} catch (Exception) {`<br/>　　`...`<br/>`}` | `if command; then`<br/>　　`...`<br/>`else`<br/>　　`...`<br/>`fi` | `try {`<br/>　　`...`<br/>`} catch {`<br/>　　`...`<br/>`}` |
| 数学 | 乱数生成 | `import random`<br/>`random.randint(1, 10)` | `Math.floor(Math.random() * 10) + 1;` | `use rand::Rng;`<br/>`rand::thread_rng().gen_range(1..=10)` | `import System.Random`<br/>`randomR (1, 10)` | `#include <random>`<br/>`std::uniform_int_distribution<>(1, 10)(std::default_random_engine())` | `Random rnd = new Random();`<br/>`rnd.Next(1, 11);` | `$((RANDOM % 10) + 1)` | `Get-Random -Minimum 1 -Maximum 11` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 日付・時刻 | 現在時刻取得 | `import datetime`<br/>`datetime.datetime.now()` | `new Date();` | `use chrono::Local;`<br/>`Local::now()` | `import Data.Time.Clock`<br/>`getCurrentTime` | `#include <ctime>`<br/>`std::time(0)` | `DateTime.Now;` | `date` | `Get-Date` |
| 日付・時刻 | 時間差計算 | `from datetime import datetime, timedelta`<br/>`delta = timedelta(days=1)`<br/>`new_date = datetime.now() + delta` | `const date = new Date();`<br/>`const newDate = new Date(date.getTime() + 86400000);` | `use chrono::{Duration, Utc};`<br/>`let new_date = Utc::now() + Duration::days(1);` | `import Data.Time.Clock`<br/>`new_date = addUTCTime (60 * 60 * 24) getCurrentTime` | `std::chrono::system_clock::time_point now = std::chrono::system_clock::now();`<br/>`auto new_date = now + std::chrono::hours(24);` | `DateTime now = DateTime.Now;`<br/>`DateTime new_date = now.AddHours(24);` | `new_date=$(date -d "+1 day" +"%Y-%m-%d")` | `$now = Get-Date`<br/>`$new_date = $now.AddDays(1)` |
| クラス | クラス定義 | `class Dog:`<br/>`def bark(self):`<br/>　　`print("Woof!")` | `class Dog {`<br/>　　`bark() {`<br/>　　`console.log("Woof!");`<br/>　　`}`<br/>`}` | `struct Dog;`<br/>`impl Dog {`<br/>　　`fn bark(&self) {`<br/>　　`println!("Woof!");`<br/>　　`}`<br/>`}` | `data Dog = Dog`<br/>`bark :: Dog -> String`<br/>`bark _ = "Woof!"` | `class Dog {`<br/>`public:`<br/>　　`void bark() {`<br/>　　`std::cout << "Woof!" << std::endl;`<br/>　　`}`<br/>`};` | `public class Dog`<br/>`{`<br/>　　`public void Bark()`<br/>　　`{`<br/>　　`Console.WriteLine("Woof!");`<br/>　　`}`<br/>`}` | `# クラスのような構造はシェルスクリプトにはないため、スキップします。` | `class Dog {`<br/>　　`[void] Bark() {`<br/>　　`Write-Host "Woof!"`<br/>　　`}`<br/>`}` |
| クラス | クラスのインスタンス化 | `my_dog = Dog()`<br/>`my_dog.bark()` | `let myDog = new Dog();`<br/>`myDog.bark();`<br/>`}` | `let my_dog = Dog;`<br/>`my_dog.bark();`<br/>`}` | `let myDog = Dog`<br/>`putStrLn $ bark myDog` | `Dog myDog;`<br/>`myDog.bark();`<br/>`}` | `Dog myDog = new Dog();`<br/>`myDog.Bark();`<br/>`}` | `# クラスのような構造はシェルスクリプトにはないため、スキップします。` | `$myDog = [Dog]::new();`<br/>`$myDog.Bark();`<br/>`}` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| モジュール | インポート | `import math` | `import * as math from 'math';` | `use std::math;` | `import Math` | `#include <cmath>` | `using System.Math;` | `source math.sh` | `Import-Module Math` |
| モジュール | 関数呼び出し | `result = math.sqrt(4)` | `const result = math.sqrt(4);` | `let result = f64::sqrt(4.0);` | `result = sqrt 4` | `double result = std::sqrt(4);` | `double result = Math.Sqrt(4);` | `result=$(sqrt 4)` | `$result = [Math]::Sqrt(4)` |
| 辞書 | キーのリスト取得 | `d = {'a': 1, 'b': 2}`<br/>`keys = list(d.keys())` | `let d = {'a': 1, 'b': 2};`<br/>`let keys = Object.keys(d);` | `let d = vec![("a", 1), ("b", 2)];`<br/>`let keys = d.iter().map(\|(k, \_)\| k).collect::<Vec<&str>>();` | `import Data.Map`<br/>`let d = fromList [("a", 1), ("b", 2)]`<br/>`let keys = keys d` | `std::map<std::string, int> d = {{"a", 1}, {"b", 2}};`<br/>`std::vectorstd::string keys;`<br/>`for (const auto& kvp : d) { keys.push_back(kvp.first); }` | `var d = new Dictionary<string, int> { { "a", 1 }, { "b", 2 } };`<br/>`List<string> keys = d.Keys.ToList();` | `declare -A d=( ["a"]=1 ["b"]=2 )`<br/>`keys=("${!d[@]}")` | `$d = @{"a"=1;"b"=2}`<br/>`$keys = $d.Keys` |
| 辞書 | 値のリスト取得 | `d = {'a': 1, 'b': 2}`<br/>`values = list(d.values())` | `let d = {'a': 1, 'b': 2};`<br/>`let values = Object.values(d);` | `let d = vec![("a", 1), ("b", 2)];`<br/>`let values = d.iter().map(\|(\_, v)\| v).collect::<Vec<&i32>>();` | `import Data.Map`<br/>`let d = fromList [("a", 1), ("b", 2)]`<br/>`let values = elems d` | `std::map<std::string, int> d = {{"a", 1}, {"b", 2}};`<br/>`std::vector<int> values;`<br/>`for (const auto& kvp : d) { values.push_back(kvp.second); }` | `var d = new Dictionary<string, int> { { "a", 1 }, { "b", 2 } };`<br/>`List<int> values = d.Values.ToList();` | `declare -A d=( ["a"]=1 ["b"]=2 )`<br/>`values=("${d[@]}")` | `$d = @{"a"=1;"b"=2}`<br/>`$values = $d.Values` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 関数 | クロージャ | `def outer(x):`<br/>　　`def inner(y):`<br/>　　`return x + y`<br/>　　`return inner`<br/>`f = outer(10)`<br/>`result = f(5)` | `function outer(x) {`<br/>　　`return function inner(y) {`<br/>　　`return x + y;`<br/>　　`};`<br/>`}`<br/>`let f = outer(10);`<br/>`let result = f(5);` | `fn outer(x: i32) -> impl Fn(i32) -> i32 {`<br/>　　`move \|y\| x + y`<br/>`}`<br/>`let f = outer(10);`<br/>`let result = f(5);` | `outer :: Int -> Int -> Int`<br/>`outer x = \y -> x + y`<br/>`f = outer 10`<br/>`result = f 5` | `auto outer(int x) {`<br/>　　`return [x](int y) { return x + y; };`<br/>`}`<br/>`auto f = outer(10);`<br/>`int result = f(5);` | `Func<int, int> Outer(int x) {`<br/>　　`return y => x + y;`<br/>`}`<br/>`var f = Outer(10);`<br/>`int result = f(5);` | `outer() { x=$1; inner() { y=$1; echo $((x+y)); }; return 0; }`<br/>`f=$(outer 10)`<br/>`result=$(f 5)` | `function Outer($x) {`<br/>　　`return { param($y) $x + $y };`<br/>`}`<br/>`$f = Outer 10`<br/>`$result = $f.Invoke(5)` |
| 関数 | 関数の戻り値 | `def add(x, y):`<br/>　　`return x + y`<br/>`result = add(1, 2)` | `function add(x, y) {`<br/>　　`return x + y;`<br/>`}`<br/>`let result = add(1, 2);` | `fn add(x: i32, y: i32) -> i32 {`<br/>　　`x + y`<br/>`}`<br/>`let result = add(1, 2);` | `add :: Int -> Int -> Int`<br/>`add x y = x + y`<br/>`result = add 1 2` | `int add(int x, int y) {`<br/>　　`return x + y;`<br/>`}`<br/>`int result = add(1, 2);` | `int Add(int x, int y) {`<br/>　　`return x + y;`<br/>`}`<br/>`int result = Add(1, 2);` | `add() { return $(($1 + $2)); }`<br/>`result=$(add 1 2)` | `function Add($x, $y) {`<br/>　　`return $x + $y;`<br/>`}`<br/>`$result = Add 1 2` |
| 数学 | 平方根の取得 | `import math`<br/>`sqrt_val = math.sqrt(25)` | `const sqrt_val = Math.sqrt(25);` | `use std::f64;`<br/>`let sqrt_val = f64::sqrt(25.0);` | `sqrt_val = sqrt 25` | `double sqrt_val = std::sqrt(25);` | `double sqrt_val = Math.Sqrt(25);` | `sqrt_val=$(echo "scale=0;sqrt(25)" \| bc)` | `$sqrt_val = [Math]::Sqrt(25)` |
| 数学 | 絶対値の取得 | `abs_val = abs(-10)` | `const abs_val = Math.abs(-10);` | `let abs_val = i32::abs(-10);` | `abs_val = abs (-10)` | `int abs_val = std::abs(-10);` | `int abs_val = Math.Abs(-10);` | `abs_val=$(echo "scale=0;(-10)" \| bc)` | `$abs_val = [Math]::Abs(-10)` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 数学 | 三角関数の取得 | `import math`<br/>`sin_val = math.sin(math.radians(30))` | `const sin_val = Math.sin(Math.PI / 6);` | `use std::f64;`<br/>`let sin_val = f64::sin(f64::consts::PI / 6.0);` | `sin_val = sin(pi / 6)` | `double sin_val = std::sin(M_PI / 6);` | `double sin_val = Math.Sin(Math.PI / 6);` | `sin_val=$(echo "scale=2;sin(30 * 3.14159/180)" \| bc -l)` | `$sin_val = [Math]::Sin([Math]::PI / 6)` |
| 集合 | 集合の生成 | `my_set = {1, 2, 3}` | `const mySet = new Set([1, 2, 3]);` | `use std::collections::HashSet;`<br/>`let my_set: HashSet<i32> = [1, 2, 3].iter().cloned().collect();` | `mySet = Data.Set.fromList [1, 2, 3]` | `std::set<int> my_set = {1, 2, 3};` | `HashSet<int> mySet = new HashSet<int>(){1, 2, 3};` | `my_set=$(echo "1 2 3" \| tr ' ' '\n' \| sort -u)` | `$mySet = [1, 2, 3] -as [System.Collections.Generic.HashSet[int]]` |
| 集合 | 要素の追加 | `my_set.add(4)` | `mySet.add(4);` | `my_set.insert(4);` | `mySet = Data.Set.insert 4 mySet` | `my_set.insert(4);` | `mySet.Add(4);` | `my_set=$(echo "$my_set"; echo "4") \| sort -u` | `$mySet.Add(4)` |
| 集合 | 要素の削除 | `my_set.remove(3)` | `mySet.delete(3);` | `my_set.remove(&3);` | `mySet = Data.Set.delete 3 mySet` | `my_set.erase(3);` | `mySet.Remove(3);` | `my_set=$(echo "$my_set" \| grep -v '^3$')` | `$mySet.Remove(3)` |

| 大分類 | 小分類 | python | JavaScript | Rust | Haskell | C++ | C# | bash | PowerShell |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------- |
| 集合 | 長さ取得 | `len(my_set)` | `mySet.size;` | `my_set.len();` | `Data.Set.size mySet` | `my_set.size();` | `mySet.Count;` | `my_set_count=$(echo "$my_set" \| wc -l)` | `$mySet.Count` |
| 集合 | 集合の交差 | `set1 = {1, 2, 3}`<br/>`set2 = {2, 3, 4}`<br/>`intersection = set1.intersection(set2)` | `const set1 = new Set([1, 2, 3]);`<br/>`const set2 = new Set([2, 3, 4]);`<br/>`const intersection = new Set([...set1].filter(x => set2.has(x)));` | `use std::collections::HashSet;`<br/>`let set1: HashSet<> = [1, 2, 3].iter().cloned().collect();`<br/>`let set2: HashSet<> = [2, 3, 4].iter().cloned().collect();`<br/>`let intersection: HashSet<> = set1.intersection(&set2).cloned().collect();` | `import qualified Data.Set as Set`<br/>`set1 = Set.fromList [1, 2, 3]`<br/>`set2 = Set.fromList [2, 3, 4]`<br/>`intersection = Set.intersection set1 set2` | `std::set<int> set1{1, 2, 3};`<br/>`std::set<int> set2{2, 3, 4};`<br/>`std::set<int> intersection;`<br/>`std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin()));` | `HashSet<int> set1 = new HashSet<int> {1, 2, 3};`<br/>`HashSet<int> set2 = new HashSet<int> {2, 3, 4};`<br/>`set1.IntersectWith(set2);` | `set1=(1 2 3)`<br/>`set2=(2 3 4)`<br/>`intersection=($(comm -12 <(echo "${set1[@]}" \| tr ' ' '\n' \| sort) <(echo "${set2[@]}" \| tr ' ' '\n' \| sort)))` | `$set1 = @('1','2','3')`<br/>`$set2 = @('2','3','4')`<br/>`$intersection = $set1 \| ? { $set2 -contains $ }` |
| 集合 | 集合の和集合 | `set1 = {1, 2, 3}`<br/>`set2 = {3, 4, 5}`<br/>`union_set = set1.union(set2)` | `const set1 = new Set([1, 2, 3]);`<br/>`const set2 = new Set([3, 4, 5]);`<br/>`const union_set = new Set([...set1, ...set2]);` | `use std::collections::HashSet;`<br/>`let set1: HashSet<> = [1, 2, 3].iter().cloned().collect();`<br/>`let set2: HashSet<> = [3, 4, 5].iter().cloned().collect();`<br/>`let union_set: HashSet<_> = set1.union(&set2).cloned().collect();` | `import Data.Set`<br/>`let set1 = fromList [1, 2, 3]`<br/>`let set2 = fromList [3, 4, 5]`<br/>`let union_set = set1 union set2` | `std::unordered_set<int> set1 = {1, 2, 3};`<br/>`std::unordered_set<int> set2 = {3, 4, 5};`<br/>`std::unordered_set<int> union_set;`<br/>`std::set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(union_set, union_set.begin()));` | `HashSet<int> set1 = new HashSet<int> {1, 2, 3};`<br/>`HashSet<int> set2 = new HashSet<int> {3, 4, 5};`<br/>`set1.UnionWith(set2);` | `set1=(1 2 3)`<br/>`set2=(3 4 5)`<br/>`union_set=($(echo "${set1[@]}" "${set2[@]}" \| tr ' ' '\n' \| sort -u \| tr '\n' ' '))` | `$set1 = @(1, 2, 3)`<br/>`$set2 = @(3, 4, 5)`<br/>`$union_set = $set1 + $set2 \| Sort-Object -Unique` |
| 集合 | 集合の差集合 | `set1 = {1, 2, 3}`<br/>`set2 = {2, 3, 4}`<br/>`difference = set1.difference(set2)` | `const set1 = new Set([1, 2, 3]);`<br/>`const set2 = new Set([2, 3, 4]);`<br/>`const difference = new Set([...set1].filter(x => !set2.has(x)));` | `use std::collections::HashSet;`<br/>`let set1: HashSet<i32> = [1, 2, 3].iter().cloned().collect();`<br/>`let set2: HashSet<i32> = [2, 3, 4].iter().cloned().collect();`<br/>`let difference: HashSet<i32> = set1.difference(&set2).cloned().collect();` | `import Data.Set as Set`<br/>`set1 = Set.fromList [1, 2, 3]`<br/>`set2 = Set.fromList [2, 3, 4]`<br/>`difference = Set.difference set1 set2` | `std::set<int> set1{1, 2, 3};`<br/>`std::set<int> set2{2, 3, 4};`<br/>`std::set<int> difference;`<br/>`std::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(difference, difference.begin()));` | `HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };`<br/>`HashSet<int> set2 = new HashSet<int> { 2, 3, 4 };`<br/>`HashSet<int> difference = new HashSet<int>(set1);`<br/>`difference.ExceptWith(set2);` | `set1="1 2 3"`<br/>`set2="2 3 4"`<br/>`difference=$(comm -23 <(echo "$set1" \| tr ' ' '\n' \| sort) <(echo "$set2" \| tr ' ' '\n' \| sort) \| tr '\n' ' ')` | `$set1 = @(1, 2, 3)`<br/>`$set2 = @(2, 3, 4)`<br/>`$difference = $set1 \| Where-Object { -not ($set2 -contains $_) }` |
| 集合 | 集合の部分集合判定 | `A = {1, 2, 3} `<br/> `B = {1, 2} `<br/> `is_subset = B.issubset(A) ` | `const A = new Set([1, 2, 3]); `<br/> `const B = new Set([1, 2]); `<br/> `const is_subset = [...B].every(x => A.has(x)); ` | `use std::collections::HashSet; `<br/> `let A: HashSet<i32> = [1, 2, 3].iter().cloned().collect(); `<br/> `let B: HashSet<i32> = [1, 2].iter().cloned().collect(); `<br/> `let is_subset = B.is_subset(&A); ` | `import Data.Set (isSubsetOf, fromList) `<br/> `let A = fromList [1, 2, 3] `<br/> `let B = fromList [1, 2] `<br/> `let is_subset = B isSubsetOf A ` | `std::set<int> A{1, 2, 3}; `<br/> `std::set<int> B{1, 2}; `<br/> `bool is_subset = std::includes(A.begin(), A.end(), B.begin(), B.end()); ` | `HashSet<int> A = new HashSet<int>(){1, 2, 3}; `<br/> `HashSet<int> B = new HashSet<int>(){1, 2}; `<br/> `bool is_subset = B.IsSubsetOf(A); ` | `A="1 2 3" `<br/> `B="1 2" `<br/> `is_subset=true `<br/> `for e in $B; do if ! [[ $A =~ $e ]]; then is_subset=false; break; fi; done ` | `$A = @{1, 2, 3} `<br/> `$B = @{1, 2} `<br/> `$is_subset = $B.IsSubsetOf($A) ` |