文字入れ替え組み合わせ計算
計算結果: 0
以下は、ユーザーの要望を実現するためのサンプルプログラムです。
```html
<!DOCTYPE html>
<html>
<head>
<title>文字入れ替え組み合わせ計算</title>
<style>
#result {
width: 80%;
margin: 20px auto;
border: 1px solid black;
padding: 10px;
text-align: center;
}
#graph {
width: 80%;
margin: 20px auto;
height: 200px;
border: 1px solid black;
}
.bar {
background-color: blue;
height: 100%;
transition: height 0.5s;
}
</style>
</head>
<body>
<h1>文字入れ替え組み合わせ計算</h1>
<div>
<label for="text">入力文字列:</label>
<input type="text" id="text" placeholder="文字列を入力してください">
<button onclick="calculate()">計算</button>
</div>
<div id="result">
計算結果: <span id="count">0</span>
</div>
<div id="graph">
<div class="bar" style="height: 0%;"></div>
</div>
<script>
function calculate() {
var inputText = document.getElementById("text").value;
// 重複を省いた文字の数を取得
var uniqueCharCount = new Set(inputText).size;
// 各文字数の組み合わせを計算し、結果を表示
var totalCount = 1;
var resultDiv = document.getElementById("result");
var countSpan = document.getElementById("count");
countSpan.textContent = totalCount.toLocaleString();
resultDiv.style.display = "block";
// グラフのアニメーション表示
var graphDiv = document.getElementById("graph");
var barDiv = document.querySelector(".bar");
barDiv.style.height = "0%";
for (var i = 1; i <= uniqueCharCount; i++) {
totalCount *= i;
countSpan.textContent = totalCount.toLocaleString();
// グラフのアニメーション設定
var percentage = (totalCount / factorial(uniqueCharCount)) * 100;
barDiv.style.height = percentage + "%";
}
}
// 階乗を計算するヘルパー関数
function factorial(n) {
if (n === 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
// ジョークの表示
console.log("Why did the programmer go broke?");
console.log("Because he lost his domain in a bet!");
</script>
</body>
</html>
```
これは、テキストボックスに入力された文字列の中での文字の組み合わせを計算し、結果を表示するためのHTMLファイルです。文字列の長さが増えるごとに組み合わせの数を計算し、グラフで可視化しています。
また、ジョークの一つとして「なぜプログラマーはお金持ちになれないのか?」という問いと、答えの「賭けでドメインを失ったからです!」をコンソールに表示しています。
注意点として、セキュリティ上のリスクを減らすために、evalを使うことや他のサイトに遷移させることは避けています。また、不正なリダイレクトもありません。