Skip to content

Commit

Permalink
Add index.html from ChatGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Jun 6, 2024
1 parent 359e491 commit cb2c5c0
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Optimal Commitment Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input, button {
margin: 5px 0;
}
label {
display: block;
margin-top: 10px;
}
.result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Optimal Commitment Calculator</h1>
<form id="calculator-form">
<label for="usage">Historical Usage (comma separated):</label>
<input type="text" id="usage" required>

<label for="discountedRate">Discounted Rate (£):</label>
<input type="number" id="discountedRate" step="0.01" required>

<label for="fullPrice">Full Price (£):</label>
<input type="number" id="fullPrice" step="0.01" required>

<button type="button" onclick="calculateOptimalCommitment()">Calculate</button>
</form>

<div class="result" id="result"></div>

<script>
function calculateOptimalCommitment() {
// Get the inputs
const usageData = document.getElementById('usage').value.split(',').map(Number);
const discountedRate = parseFloat(document.getElementById('discountedRate').value);
const fullPrice = parseFloat(document.getElementById('fullPrice').value);

const minCommitment = Math.min(...usageData);
const maxCommitment = Math.max(...usageData);
const step = 10; // Adjust step size as needed

let optimalCommitment = minCommitment;
let minTotalCost = Infinity;

// Iterate through possible commitment levels
for (let commitment = minCommitment; commitment <= maxCommitment; commitment += step) {
let totalCost = 0;

for (let usage of usageData) {
if (usage <= commitment) {
totalCost += commitment * discountedRate;
} else {
totalCost += commitment * discountedRate + (usage - commitment) * fullPrice;
}
}

if (totalCost < minTotalCost) {
minTotalCost = totalCost;
optimalCommitment = commitment;
}
}

// Display the result
document.getElementById('result').innerText =
`Optimal Commitment Level: £${optimalCommitment.toFixed(2)}\nMinimum Total Cost: £${minTotalCost.toFixed(2)}`;
}
</script>
</body>
</html>


0 comments on commit cb2c5c0

Please sign in to comment.