Upload 2025 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Procfile +1 -0
- README.md +10 -6
- app.py +693 -0
- code_counter.txt +1 -0
- evaluation/.DS_Store +0 -0
- evaluation/.ipynb_checkpoints/Untitled-checkpoint.ipynb +6 -0
- evaluation/eval_interfaces/.DS_Store +0 -0
- evaluation/eval_interfaces/coding_eval_interface.html +336 -0
- evaluation/eval_interfaces/graph_eval_interface.html +333 -0
- evaluation/eval_interfaces/instructions.html +147 -0
- evaluation/eval_interfaces/interactive_coding_explanations/.DS_Store +0 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_1.html +533 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_10.html +507 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_11.html +541 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_12.html +542 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_13.html +515 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_14.html +548 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_15.html +515 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_16.html +551 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_17.html +508 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_18.html +500 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_19.html +498 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_2.html +501 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_20.html +512 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_21.html +527 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_22.html +517 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_23.html +522 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_24.html +515 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_25.html +513 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_26.html +539 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_27.html +482 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_28.html +489 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_29.html +492 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_3.html +506 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_30.html +554 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_31.html +516 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_32.html +500 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_33.html +515 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_34.html +560 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_35.html +519 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_36.html +533 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_37.html +503 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_38.html +516 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_39.html +513 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_4.html +507 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_40.html +504 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_41.html +497 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_42.html +511 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_43.html +536 -0
- evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_44.html +502 -0
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: python app.py
|
README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title: Interactive
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Interactive Llm Xai
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.22.0
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: interactive-llm-xai
|
| 12 |
---
|
| 13 |
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
Evaluation back-end for the “interactive-graph” interface on Hugging Face Spaces
|
| 5 |
+
───────────────────────────────────────────────────────────────────────────────
|
| 6 |
+
* Serves all evaluation UIs (`/eval_interfaces/<option>`).
|
| 7 |
+
* Transparently patches every explanation HTML so you never touch the originals:
|
| 8 |
+
▸ layout / badge / telemetry tweaks (unchanged)
|
| 9 |
+
▸ **NEW** helper that counts steps and answers the parent’s
|
| 10 |
+
`xai-get-step-count`, so the prompt shows “1 – N”.
|
| 11 |
+
* **DEBUG MODE** (toggle with `ICOT_DEBUG=1`) prints:
|
| 12 |
+
▸ every file request + whether it was patched
|
| 13 |
+
▸ console-side step counts inside each iframe.
|
| 14 |
+
* Persists results to CSV / JSON and can push them to
|
| 15 |
+
`LLM-XAI/interactive-COT-data` if `ICOT_TOKEN` is set.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import os, csv, json, uuid, logging
|
| 19 |
+
from datetime import datetime
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
from flask import (
|
| 22 |
+
Flask, abort, Response, send_file, request,
|
| 23 |
+
url_for, render_template_string, jsonify
|
| 24 |
+
)
|
| 25 |
+
from huggingface_hub import HfApi, login
|
| 26 |
+
import re # ← add near other imports
|
| 27 |
+
from datasets import load_dataset
|
| 28 |
+
import random
|
| 29 |
+
|
| 30 |
+
# ────────────────────────── SET THE COUNTERS ──────────────────────
|
| 31 |
+
MAX_USERS = 50
|
| 32 |
+
COT_COUNTER_FILE = "regular_cot_counter.txt"
|
| 33 |
+
GRAPH_COUNTER_FILE = "graph_counter.txt"
|
| 34 |
+
CODE_COUNTER_FILE = "code_counter.txt"
|
| 35 |
+
NATURAL_LANG_COUNTER_FILE = "natural_lang_counter.txt"
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
SELECTED_CARD = "graph"
|
| 39 |
+
|
| 40 |
+
def get_submit_counter(file_path:str) -> int:
|
| 41 |
+
with open(file_path, 'r') as f:
|
| 42 |
+
try:
|
| 43 |
+
val = int(f.read().strip())
|
| 44 |
+
except ValueError:
|
| 45 |
+
val = 0
|
| 46 |
+
return val
|
| 47 |
+
|
| 48 |
+
def increment_submit_counter(file_path:str) -> int:
|
| 49 |
+
with open(file_path, 'r+') as f:
|
| 50 |
+
current = get_submit_counter(file_path)
|
| 51 |
+
new_value = (current+1) % (MAX_USERS+1)
|
| 52 |
+
if new_value == 0:
|
| 53 |
+
new_value = 1
|
| 54 |
+
f.seek(0)
|
| 55 |
+
f.write(str(new_value))
|
| 56 |
+
f.truncate()
|
| 57 |
+
return new_value
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def increment_submit_counter_absolute(file_path:str) -> int:
|
| 61 |
+
with open(file_path, 'r+') as f:
|
| 62 |
+
current = get_submit_counter(file_path)
|
| 63 |
+
new_value = current+1
|
| 64 |
+
f.seek(0)
|
| 65 |
+
f.write(str(new_value))
|
| 66 |
+
f.truncate()
|
| 67 |
+
return new_value
|
| 68 |
+
|
| 69 |
+
def get_the_min_interface() -> str:
|
| 70 |
+
# format_dict = {"interactive_coding_explanations": "code", "interactive_graph_explanations": "graph", "interactive_nat_lang_explanations": "inl","traditional_cot_explanations": "cot"}
|
| 71 |
+
# ds = load_dataset("Miles1999/interactive-COT-data")
|
| 72 |
+
# train_df = ds["train"].to_pandas()
|
| 73 |
+
# train_df['interface_type'] = train_df['samples'].apply(get_interface_format)
|
| 74 |
+
# counts = train_df['interface_type'].value_counts()
|
| 75 |
+
# log.info(counts)
|
| 76 |
+
# min_count = counts.min()
|
| 77 |
+
# # Find all formats that have this minimum count
|
| 78 |
+
# min_formats = counts[counts == min_count].index.tolist()
|
| 79 |
+
# log.info("min formats:")
|
| 80 |
+
# log.info(min_formats)
|
| 81 |
+
# # Pick one randomly if more than one
|
| 82 |
+
# chosen_format = random.choice(min_formats)
|
| 83 |
+
# log.info("chosen format:")
|
| 84 |
+
# log.info(chosen_format)
|
| 85 |
+
# return format_dict[chosen_format]
|
| 86 |
+
format_lst= ["code", "graph", "inl","cot"]
|
| 87 |
+
chosen_format = random.choice(format_lst)
|
| 88 |
+
return chosen_format
|
| 89 |
+
|
| 90 |
+
# this function extract the interface format from the sample path
|
| 91 |
+
def get_interface_format(sample_list):
|
| 92 |
+
file_path = sample_list[0].get("file", "")
|
| 93 |
+
parts = file_path.split("eval_interfaces/")
|
| 94 |
+
if len(parts) > 1:
|
| 95 |
+
return parts[1].split("/")[0] # the folder after eval_interfaces/
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
# ────────────────────────── GLOBAL DEBUG FLAG ──────────────────────
|
| 99 |
+
DEBUG_MODE = os.getenv("ICOT_DEBUG", "0") != "0"
|
| 100 |
+
|
| 101 |
+
logging.basicConfig(
|
| 102 |
+
level=logging.DEBUG if DEBUG_MODE else logging.INFO,
|
| 103 |
+
format="%(asctime)s | %(levelname)-8s | %(message)s"
|
| 104 |
+
)
|
| 105 |
+
log = logging.getLogger(__name__)
|
| 106 |
+
log.info("Debug mode: %s", DEBUG_MODE)
|
| 107 |
+
|
| 108 |
+
# ───────────────────────────── CONFIG ──────────────────────────────
|
| 109 |
+
HF_TOKEN = os.getenv("ICOT_TOKEN") # set in Space → Settings → Secrets
|
| 110 |
+
if HF_TOKEN:
|
| 111 |
+
login(token=HF_TOKEN)
|
| 112 |
+
else:
|
| 113 |
+
log.warning("ICOT_TOKEN not set – results will stay local")
|
| 114 |
+
|
| 115 |
+
HF_REPO = "Miles1999/interactive-COT-data"
|
| 116 |
+
HF_FOLDER = "session_logs"
|
| 117 |
+
|
| 118 |
+
CODEBASE_DIR = "."
|
| 119 |
+
EVAL_PAGES = {
|
| 120 |
+
"cot" : "evaluation/eval_interfaces/reg_cot_eval_interface.html",
|
| 121 |
+
"interactive_nl" : "evaluation/eval_interfaces/nl_eval_interface.html",
|
| 122 |
+
"interactive_code" : "evaluation/eval_interfaces/coding_eval_interface.html",
|
| 123 |
+
"interactive_graph": "evaluation/eval_interfaces/graph_eval_interface.html",
|
| 124 |
+
}
|
| 125 |
+
ALLOWED_ROOTS = ["html_explanations", "evaluation"]
|
| 126 |
+
|
| 127 |
+
CSV_FILENAME = "evaluation_stats.csv"
|
| 128 |
+
CSV_PATH = Path(CSV_FILENAME).resolve()
|
| 129 |
+
CSV_HEADER = [
|
| 130 |
+
"timestamp","session_id","user_name",
|
| 131 |
+
"overallAccuracy(%)","correctItemAccuracy(%)","incorrectItemAccuracy(%)",
|
| 132 |
+
"avgTimeCorrect","avgTimeIncorrect",
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
SESSION_DIR = Path("/tmp/sessions")
|
| 136 |
+
SESSION_DIR.mkdir(parents=True, exist_ok=True)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
# ───────────────────────────── HELPERS ─────────────────────────────
|
| 141 |
+
def gen_session_id() -> str:
|
| 142 |
+
return str(uuid.uuid4())
|
| 143 |
+
|
| 144 |
+
def save_session_local(sid: str, data: dict) -> Path:
|
| 145 |
+
path = SESSION_DIR / f"{sid}.json"
|
| 146 |
+
path.write_text(json.dumps(data, indent=2))
|
| 147 |
+
log.info("Stored session JSON → %s", path)
|
| 148 |
+
return path
|
| 149 |
+
|
| 150 |
+
def push_to_hf(local_path: Path, sid: str):
|
| 151 |
+
try:
|
| 152 |
+
HfApi().upload_file(
|
| 153 |
+
path_or_fileobj=str(local_path),
|
| 154 |
+
path_in_repo=f"{HF_FOLDER}/{local_path.name}",
|
| 155 |
+
repo_id=HF_REPO,
|
| 156 |
+
repo_type="dataset",
|
| 157 |
+
)
|
| 158 |
+
local_path.unlink()
|
| 159 |
+
log.info("Uploaded session %s to HF & removed local copy", sid)
|
| 160 |
+
except Exception as e:
|
| 161 |
+
log.warning("HF upload failed for %s : %s", sid, e)
|
| 162 |
+
|
| 163 |
+
# ────────────────────────── HTML PATCHING ──────────────────────────
|
| 164 |
+
INJECT_STYLE = """
|
| 165 |
+
<style>
|
| 166 |
+
/* layout tweak: 40 / 60 split */
|
| 167 |
+
.left-panel { width:40%!important }
|
| 168 |
+
.right-panel{ width:60%!important }
|
| 169 |
+
|
| 170 |
+
/* hide “Variables” pane */
|
| 171 |
+
.variables-container{display:none!important}
|
| 172 |
+
.explanation-container{flex:1!important;height:auto!important}
|
| 173 |
+
/* numbered badge next to each step */
|
| 174 |
+
.step{display:none;align-items:center;gap:12px}
|
| 175 |
+
.step.shown{display:flex}
|
| 176 |
+
.step-content,.step>*:first-child{flex:1}
|
| 177 |
+
.badge{
|
| 178 |
+
flex-shrink:0;color:#adadad;font-size:1.7rem;
|
| 179 |
+
font-weight:700;padding:4px 14px;border-radius:16px;pointer-events:none;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/* ── eliminate blank space in Problem Statement ──────────────────── */
|
| 183 |
+
.problem-statement{
|
| 184 |
+
/* let the section size itself */
|
| 185 |
+
height:auto!important; /* overrides 50 % */
|
| 186 |
+
flex:0 0 auto!important; /* occupy only the space it needs */
|
| 187 |
+
padding:20px!important; /* keep your original insets */
|
| 188 |
+
overflow-y:visible!important; /* scroll not usually needed here */
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.problem-understanding{
|
| 192 |
+
/* fill everything that’s left */
|
| 193 |
+
flex:1 1 auto!important; /* grow/shrink with column */
|
| 194 |
+
height:auto!important; /* overrides 50 % */
|
| 195 |
+
overflow-y:auto!important; /* still scroll if content is long */
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/* tidy up internal spacing */
|
| 199 |
+
.problem-statement p{
|
| 200 |
+
margin:0!important;
|
| 201 |
+
line-height:1.4!important;
|
| 202 |
+
}
|
| 203 |
+
.section-title{
|
| 204 |
+
margin-bottom:8px!important;
|
| 205 |
+
padding-bottom:3px!important;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/* ── eliminate per‑line margins in the Summary panel ─────────────── */
|
| 209 |
+
.problem-understanding .variable-item,
|
| 210 |
+
.problem-understanding p,
|
| 211 |
+
.problem-understanding li {
|
| 212 |
+
margin: 0 !important; /* no extra vertical gap */
|
| 213 |
+
padding: 0 !important; /* align text to the left edge */
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/* ── make every control button solid black ── */
|
| 217 |
+
.btn,
|
| 218 |
+
.btn-play-pause,
|
| 219 |
+
.btn-stop,
|
| 220 |
+
.btn-prev,
|
| 221 |
+
.btn-next,
|
| 222 |
+
.btn-correct,
|
| 223 |
+
.btn-wrong{
|
| 224 |
+
background: #000 !important; /* black fill */
|
| 225 |
+
color: #fff !important; /* white text so it stays readable */
|
| 226 |
+
border: none !important; /* ensure no colored borders peek through */
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
.btn:hover { /* keep hover subtle */
|
| 230 |
+
opacity: 0.9 !important;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/* if you dim disabled buttons, keep them grey */
|
| 234 |
+
.btn.disabled {
|
| 235 |
+
background: #6c6c6c !important;
|
| 236 |
+
color: #fff !important;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/* Natural‑language & graph explanations (.step.active) */
|
| 240 |
+
.step.active { /* remove yellow fill */
|
| 241 |
+
background: transparent !important;
|
| 242 |
+
border: 2px solid #ffd700 !important; /* gold border */
|
| 243 |
+
padding-left: 10px !important; /* keep text indented */
|
| 244 |
+
}
|
| 245 |
+
.code-line.current {
|
| 246 |
+
background: transparent !important;
|
| 247 |
+
border: 2px solid #ffd700 !important;
|
| 248 |
+
padding-left: 8px !important;
|
| 249 |
+
}
|
| 250 |
+
.step.active::before { display: none !important; } /* hide blinking dot */
|
| 251 |
+
|
| 252 |
+
/* disable clicking */
|
| 253 |
+
.step{
|
| 254 |
+
pointer-events:none !important; /* clicks, hovers, etc. are ignored */
|
| 255 |
+
cursor: default !important; /* arrow cursor instead of pointer */
|
| 256 |
+
}
|
| 257 |
+
/* Do not bold the formula*/
|
| 258 |
+
.formula {
|
| 259 |
+
font-weight: normal;
|
| 260 |
+
margin: 5px 0;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
</style>
|
| 265 |
+
"""
|
| 266 |
+
|
| 267 |
+
# ── Original helper (rename heading, add badges, telemetry) ──────────
|
| 268 |
+
INJECT_SCRIPT_BASE = """
|
| 269 |
+
<script>
|
| 270 |
+
|
| 271 |
+
document.addEventListener('DOMContentLoaded', ()=>{
|
| 272 |
+
|
| 273 |
+
/* 1. optional: hide the download button in outer pages */
|
| 274 |
+
const dl = document.getElementById('download-btn');
|
| 275 |
+
if (dl) dl.remove(); // safe even if not present
|
| 276 |
+
|
| 277 |
+
/* 2. rename headings */
|
| 278 |
+
const h = document.querySelector('.problem-understanding .section-title');
|
| 279 |
+
if (h) h.textContent = 'Summary';
|
| 280 |
+
const q = document.querySelector('.problem-statement .section-title');
|
| 281 |
+
if (q) q.textContent = 'Question';
|
| 282 |
+
|
| 283 |
+
/* 3. “Goal” wording */
|
| 284 |
+
// Case 1: <div class="what-to-find"><h4>...</h4>
|
| 285 |
+
const goalH4 = document.querySelector('.what-to-find h4');
|
| 286 |
+
if (goalH4) {
|
| 287 |
+
goalH4.textContent = 'Goal:';
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// Case 2: standalone <h3>What we need to find
|
| 291 |
+
const goalH3 = document.querySelector('.problem-understanding h3');
|
| 292 |
+
if (goalH3 && /what we need to find/i.test(goalH3.textContent)) {
|
| 293 |
+
goalH3.textContent = 'Goal:';
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/* 5. remove the formula if there is one */
|
| 297 |
+
const stepContents = document.querySelectorAll('.step-content');
|
| 298 |
+
stepContents.forEach(step => {
|
| 299 |
+
let currentNode = step.firstChild;
|
| 300 |
+
const formulaDiv = step.querySelector('.formula');
|
| 301 |
+
while (currentNode && currentNode !== formulaDiv) {
|
| 302 |
+
if (/[+\-*/=]/.test(currentNode.textContent)){
|
| 303 |
+
if(formulaDiv){
|
| 304 |
+
let next = formulaDiv.nextSibling;
|
| 305 |
+
while (next) {
|
| 306 |
+
const toRemove = next;
|
| 307 |
+
next = next.nextSibling;
|
| 308 |
+
step.removeChild(toRemove);
|
| 309 |
+
formulaDiv.textContent = "";
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
break;
|
| 313 |
+
}
|
| 314 |
+
currentNode = currentNode.nextSibling;
|
| 315 |
+
}
|
| 316 |
+
});
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
/* 4. decorate & reveal steps */
|
| 320 |
+
const steps = [...document.querySelectorAll('.step')];
|
| 321 |
+
steps.forEach((s, i) => {
|
| 322 |
+
const wrap = document.createElement('div');
|
| 323 |
+
wrap.className = 'step-content';
|
| 324 |
+
while (s.firstChild) wrap.appendChild(s.firstChild);
|
| 325 |
+
s.appendChild(wrap);
|
| 326 |
+
|
| 327 |
+
// Add badge for all steps except the last one
|
| 328 |
+
if (i < steps.length - 1) {
|
| 329 |
+
const badge = document.createElement('span');
|
| 330 |
+
badge.className = 'badge';
|
| 331 |
+
badge.textContent = '' + (i + 1);
|
| 332 |
+
s.appendChild(badge);
|
| 333 |
+
}
|
| 334 |
+
});
|
| 335 |
+
if (steps.length) {
|
| 336 |
+
steps[0].classList.add('active', 'shown');
|
| 337 |
+
window.currentStepIndex = 0;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
/* cumulative reveal on highlight change */
|
| 343 |
+
const sync = ()=>{
|
| 344 |
+
const idx=steps.findIndex(el=>el.classList.contains('active'));
|
| 345 |
+
steps.forEach((el,i)=>el.classList.toggle('shown',i<=idx));
|
| 346 |
+
};
|
| 347 |
+
sync();
|
| 348 |
+
const obs=new MutationObserver(sync);
|
| 349 |
+
steps.forEach(el=>obs.observe(el,{attributes:true,attributeFilter:['class']}));
|
| 350 |
+
|
| 351 |
+
/* click telemetry */
|
| 352 |
+
const post = key => window.parent?.postMessage({type:'xai-click',key},'*');
|
| 353 |
+
const map = {playPauseBtn:'play',stopBtn:'stop',nextBtn:'next',prevBtn:'prev'};
|
| 354 |
+
Object.entries(map).forEach(([id,key])=>{
|
| 355 |
+
const btn=document.getElementById(id);
|
| 356 |
+
if (btn) btn.addEventListener('click',()=>post(key),{capture:true});
|
| 357 |
+
});
|
| 358 |
+
/* Number only executable lines (i.e. lines *without* the .comment span). */
|
| 359 |
+
(function renumberCodeLines(){
|
| 360 |
+
const codeLines = document.querySelectorAll('.code-line');
|
| 361 |
+
let n = 0;
|
| 362 |
+
codeLines.forEach(cl=>{
|
| 363 |
+
const numSpan = cl.querySelector('.line-number');
|
| 364 |
+
if(!numSpan) return; // safety check
|
| 365 |
+
if(cl.querySelector('.comment')){ // comment line
|
| 366 |
+
numSpan.textContent = ''; // blank → hides via :empty
|
| 367 |
+
}else{ // real code
|
| 368 |
+
numSpan.textContent = ++n;
|
| 369 |
+
}
|
| 370 |
+
});
|
| 371 |
+
})();
|
| 372 |
+
|
| 373 |
+
});
|
| 374 |
+
|
| 375 |
+
</script>
|
| 376 |
+
"""
|
| 377 |
+
|
| 378 |
+
# ── NEW helper: answers “How many steps?” for the outer UI ───────────
|
| 379 |
+
INJECT_STEPCOUNT = """
|
| 380 |
+
<script>
|
| 381 |
+
/* Counts steps and answers parent page’s xai-get-step-count query */
|
| 382 |
+
(function(){
|
| 383 |
+
function countSteps(){
|
| 384 |
+
/* Case 1: explicit JSON */
|
| 385 |
+
if(typeof problemData==='object'){
|
| 386 |
+
if(problemData.totalSteps) return problemData.totalSteps;
|
| 387 |
+
if(Array.isArray(problemData.steps))return problemData.steps.length;
|
| 388 |
+
}
|
| 389 |
+
/* Case 2: count DOM markers */
|
| 390 |
+
const sel=['.step-item','.step','.badge','[data-step]'];
|
| 391 |
+
for(const s of sel){
|
| 392 |
+
const n=document.querySelectorAll(s).length;
|
| 393 |
+
if(n) return n;
|
| 394 |
+
}
|
| 395 |
+
return 1;
|
| 396 |
+
}
|
| 397 |
+
function send(){
|
| 398 |
+
const n = countSteps();
|
| 399 |
+
/* >>> DEBUG <<< */
|
| 400 |
+
console.debug('[step-count]', n, window.location.pathname);
|
| 401 |
+
window.parent?.postMessage({type:'xai-step-count', count:n}, '*');
|
| 402 |
+
}
|
| 403 |
+
/* answer on request */
|
| 404 |
+
window.addEventListener('message',ev=>{
|
| 405 |
+
if(ev?.data?.type==='xai-get-step-count') send();
|
| 406 |
+
});
|
| 407 |
+
/* …and volunteer once */
|
| 408 |
+
if(document.readyState==='loading'){
|
| 409 |
+
document.addEventListener('DOMContentLoaded',send);
|
| 410 |
+
}else{send();}
|
| 411 |
+
})();
|
| 412 |
+
</script>
|
| 413 |
+
"""
|
| 414 |
+
|
| 415 |
+
# ── NEW helper: adds “Step N” badges to .step-item, but skips “Final Answer” (For Graph Iterface)──
|
| 416 |
+
INJECT_SCRIPT_GRAPH_BADGE = """
|
| 417 |
+
<script>
|
| 418 |
+
document.addEventListener('DOMContentLoaded',()=>{
|
| 419 |
+
const frame = document.getElementById('step-iframe');
|
| 420 |
+
if(!frame) return; /* not a graph explanation */
|
| 421 |
+
/* inline style keeps badge self-contained */
|
| 422 |
+
const styleBadge = [
|
| 423 |
+
'flex-shrink:0',
|
| 424 |
+
'color:#adadad',
|
| 425 |
+
'font-size:1.7rem',
|
| 426 |
+
'font-weight:700',
|
| 427 |
+
'padding:2px 10px',
|
| 428 |
+
'border-radius:14px',
|
| 429 |
+
'pointer-events:none'
|
| 430 |
+
].join(';');
|
| 431 |
+
function decorate(){
|
| 432 |
+
try{
|
| 433 |
+
const doc = frame.contentDocument;
|
| 434 |
+
if(!doc) return;
|
| 435 |
+
let num = 0; /* running step counter */
|
| 436 |
+
[...doc.querySelectorAll('.step-item')].forEach(el=>{
|
| 437 |
+
if(el.querySelector('.badge')) return; /* already done */
|
| 438 |
+
const step_id = el.id
|
| 439 |
+
/* title text (trim & lowercase) */
|
| 440 |
+
const title = (el.textContent || '').trim().toLowerCase();
|
| 441 |
+
if(title.startsWith('final answer')) return; /* skip badge */
|
| 442 |
+
/* flex container so title & badge share a line */
|
| 443 |
+
el.style.display = 'flex';
|
| 444 |
+
el.style.alignItems = 'center';
|
| 445 |
+
el.style.gap = '12px';
|
| 446 |
+
if(el.firstElementChild) el.firstElementChild.style.flex = '1';
|
| 447 |
+
const b = doc.createElement('span');
|
| 448 |
+
b.className = 'badge';
|
| 449 |
+
b.style.cssText = styleBadge;
|
| 450 |
+
b.textContent = '' + step_id; /* number only real steps */
|
| 451 |
+
el.appendChild(b);
|
| 452 |
+
});
|
| 453 |
+
}catch(e){}
|
| 454 |
+
}
|
| 455 |
+
decorate(); /* decorate current content */
|
| 456 |
+
frame.addEventListener('load', decorate); /* …and on every reload */
|
| 457 |
+
});
|
| 458 |
+
</script>
|
| 459 |
+
"""
|
| 460 |
+
|
| 461 |
+
DISABLE_SCROLL_SCRIPT = """
|
| 462 |
+
<script>
|
| 463 |
+
document.addEventListener('DOMContentLoaded', ()=>{
|
| 464 |
+
// Override scrollIntoView for all steps
|
| 465 |
+
const steps = document.querySelectorAll('.step');
|
| 466 |
+
steps.forEach(s => {
|
| 467 |
+
s.scrollIntoView = function(){};
|
| 468 |
+
});
|
| 469 |
+
});
|
| 470 |
+
</script>
|
| 471 |
+
"""
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def preprocess_html(path: str) -> str:
|
| 479 |
+
"""Return patched HTML as string, injecting style + scripts."""
|
| 480 |
+
html = Path(path).read_text(encoding="utf-8")
|
| 481 |
+
|
| 482 |
+
# ── NEW: make problemData globally visible for graph pages ──
|
| 483 |
+
html = re.sub(r'\bconst\s+problemData\b', 'window.problemData', html)
|
| 484 |
+
|
| 485 |
+
# inj = INJECT_STYLE + INJECT_SCRIPT_BASE + INJECT_STEPCOUNT + DISABLE_SCROLL_SCRIPT + INJECT_SCRIPT_GRAPH_BADGE
|
| 486 |
+
inj = (
|
| 487 |
+
INJECT_STYLE +
|
| 488 |
+
INJECT_STEPCOUNT+
|
| 489 |
+
INJECT_SCRIPT_BASE+
|
| 490 |
+
DISABLE_SCROLL_SCRIPT
|
| 491 |
+
)
|
| 492 |
+
|
| 493 |
+
res = html.replace("</head>", inj + "</head>", 1) if "</head>" in html else inj + html
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
if DEBUG_MODE:
|
| 497 |
+
log.debug("Injected helpers into %s (%d → %d bytes)", path, len(html), len(res))
|
| 498 |
+
return res
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def needs_transform(path: str) -> bool:
|
| 502 |
+
p = path.replace("\\", "/").lower()
|
| 503 |
+
return (
|
| 504 |
+
p.endswith(".html") and
|
| 505 |
+
(
|
| 506 |
+
"/interactive_nat_lang_explanations/" in p or
|
| 507 |
+
"/interactive_graph_explanations/" in p or
|
| 508 |
+
"/interactive_coding_explanations/" in p
|
| 509 |
+
)
|
| 510 |
+
)
|
| 511 |
+
|
| 512 |
+
# ───────────────────────────── FLASK APP ───────────────────────────
|
| 513 |
+
app = Flask(__name__)
|
| 514 |
+
|
| 515 |
+
# ───────────────────────────── ROUTES ──────────────────────────────
|
| 516 |
+
# Landing page with four evaluation modes
|
| 517 |
+
SELECT_TEMPLATE = """
|
| 518 |
+
<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'>
|
| 519 |
+
<title>Select Evaluation Mode</title>
|
| 520 |
+
<link href='https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap' rel='stylesheet'>
|
| 521 |
+
<style>
|
| 522 |
+
*,*:before,*:after{box-sizing:border-box}
|
| 523 |
+
body{margin:0;min-height:100vh;display:flex;flex-direction:column;justify-content:center;align-items:center;
|
| 524 |
+
font-family:'Inter',sans-serif;background:#f1f5f9}
|
| 525 |
+
h1{color:#111827;font-size:2.4rem;font-weight:700;margin-bottom:2rem;text-align:center}
|
| 526 |
+
.grid{width:90%;max-width:680px;display:grid;gap:28px;grid-template-columns:repeat(auto-fit,minmax(240px,1fr))}
|
| 527 |
+
.card{height:150px;padding:10px;border-radius:16px;color:#fff;font-weight:600;font-size:1.4rem;
|
| 528 |
+
display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;
|
| 529 |
+
text-decoration:none;transition:.25s;box-shadow:0 6px 18px rgba(0,0,0,.08)}
|
| 530 |
+
.card:hover{transform:translateY(-6px);box-shadow:0 10px 24px rgba(0,0,0,.12)}
|
| 531 |
+
.cot{background:#ef4444}.inl{background:#f97316}.code{background:#10b981}.graph{background:#3b82f6}
|
| 532 |
+
</style></head><body>
|
| 533 |
+
<h1>Choose an Evaluation Interface</h1>
|
| 534 |
+
<div class='grid'>
|
| 535 |
+
<a class='card cot' href='/eval_interfaces/cot'>Chain of Thought</a>
|
| 536 |
+
<a class='card inl' href='/eval_interfaces/interactive_nl'>Interactive Natural Language</a>
|
| 537 |
+
<a class='card code' href='/eval_interfaces/interactive_code'>Interactive Code</a>
|
| 538 |
+
<a class='card graph' href='/eval_interfaces/interactive_graph'>Interactive Graph</a>
|
| 539 |
+
</div>
|
| 540 |
+
</body></html>
|
| 541 |
+
"""
|
| 542 |
+
|
| 543 |
+
@app.route("/")
|
| 544 |
+
def landing():
|
| 545 |
+
log.info("landing page update")
|
| 546 |
+
SELECTED_CARD = get_the_min_interface()
|
| 547 |
+
return render_template_string(SELECT_TEMPLATE, selected_card = SELECTED_CARD)
|
| 548 |
+
|
| 549 |
+
# frontend (outer) pages
|
| 550 |
+
@app.route("/eval_interfaces/<option>")
|
| 551 |
+
def load_outer(option):
|
| 552 |
+
global SELECTED_CARD
|
| 553 |
+
rel = EVAL_PAGES.get(option)
|
| 554 |
+
if not rel:
|
| 555 |
+
abort(404)
|
| 556 |
+
#added below
|
| 557 |
+
full_path = Path(CODEBASE_DIR) / rel
|
| 558 |
+
html = full_path.read_text(encoding="utf-8")
|
| 559 |
+
|
| 560 |
+
#Inject the counter value
|
| 561 |
+
if option == "cot":
|
| 562 |
+
counter = increment_submit_counter(COT_COUNTER_FILE)
|
| 563 |
+
log.info("cot counter value %d", counter)
|
| 564 |
+
injected = f"<script>const USER_COUNTER = {counter};</script>\n"
|
| 565 |
+
html = html.replace("</head>", injected + "</head>")
|
| 566 |
+
elif option == "interactive_graph":
|
| 567 |
+
counter = increment_submit_counter(GRAPH_COUNTER_FILE)
|
| 568 |
+
log.info("graph counter value %d", counter)
|
| 569 |
+
injected = f"<script>const USER_COUNTER = {counter};</script>\n"
|
| 570 |
+
html = html.replace("</head>", injected + "</head>")
|
| 571 |
+
elif option == "interactive_code":
|
| 572 |
+
counter = increment_submit_counter(CODE_COUNTER_FILE)
|
| 573 |
+
log.info("code counter value %d", counter)
|
| 574 |
+
injected = f"<script>const USER_COUNTER = {counter};</script>\n"
|
| 575 |
+
html = html.replace("</head>", injected + "</head>")
|
| 576 |
+
elif option == "interactive_nl":
|
| 577 |
+
counter = increment_submit_counter(NATURAL_LANG_COUNTER_FILE)
|
| 578 |
+
log.info("natural language counter value %d", counter)
|
| 579 |
+
injected = f"<script>const USER_COUNTER = {counter};</script>\n"
|
| 580 |
+
html = html.replace("</head>", injected + "</head>")
|
| 581 |
+
|
| 582 |
+
return render_template_string(html)
|
| 583 |
+
# return send_file(Path(CODEBASE_DIR) / rel)
|
| 584 |
+
|
| 585 |
+
# Explanation HTML (inner iframes)
|
| 586 |
+
@app.route("/interactive-llm-xai/<path:sub>")
|
| 587 |
+
@app.route("/eval_interfaces/interactive-llm-xai/<path:sub>")
|
| 588 |
+
def serve_explanation(sub):
|
| 589 |
+
full = Path(sub).resolve()
|
| 590 |
+
needs = needs_transform(str(full))
|
| 591 |
+
log.info("serve_explanation | %s | needs_transform=%s", full, needs)
|
| 592 |
+
|
| 593 |
+
if not full.exists():
|
| 594 |
+
abort(404)
|
| 595 |
+
if full.is_dir():
|
| 596 |
+
return browse(sub)
|
| 597 |
+
if needs:
|
| 598 |
+
return Response(preprocess_html(str(full)), mimetype="text/html")
|
| 599 |
+
return send_file(full)
|
| 600 |
+
|
| 601 |
+
# Very lightweight directory browser (handy for debugging)
|
| 602 |
+
BROWSER_TEMPLATE = """
|
| 603 |
+
<!DOCTYPE html><html><head><meta charset='utf-8'><title>Browse</title>
|
| 604 |
+
<style>
|
| 605 |
+
html,body{font-family:Arial;margin:20px;height: 100vh !important;}
|
| 606 |
+
ul{list-style:none;padding:0} li{margin:4px 0}
|
| 607 |
+
a{text-decoration:none;color:#2563eb} a:hover{text-decoration:underline}
|
| 608 |
+
.content{margin-top:15px;border:1px solid #e5e7eb;padding:10px;border-radius:8px;background:#f9fafb}
|
| 609 |
+
</style></head><body>
|
| 610 |
+
{% if parent_link %}<p><a href='{{ parent_link }}'>[Parent]</a></p>{% endif %}
|
| 611 |
+
{% if directories %}<h2>Folders</h2><ul>{% for d in directories %}
|
| 612 |
+
<li><a href='{{ url_for('browse', req_path=d.link) }}'>{{ d.name }}</a></li>{% endfor %}</ul>{% endif %}
|
| 613 |
+
{% if files %}<h2>HTML Files</h2><ul>{% for f in files %}
|
| 614 |
+
<li><a href='{{ url_for('browse', req_path=f.link) }}'>{{ f.name }}</a></li>{% endfor %}</ul>{% endif %}
|
| 615 |
+
{% if html_content %}<div class='content'>{{ html_content|safe }}</div>{% endif %}
|
| 616 |
+
</body></html>
|
| 617 |
+
"""
|
| 618 |
+
|
| 619 |
+
@app.route("/browse/", defaults={"req_path": ""})
|
| 620 |
+
@app.route("/browse/<path:req_path>")
|
| 621 |
+
def browse(req_path):
|
| 622 |
+
if req_path and req_path.split(os.sep)[0] not in ALLOWED_ROOTS:
|
| 623 |
+
abort(404)
|
| 624 |
+
full = Path(req_path).resolve()
|
| 625 |
+
if not full.exists():
|
| 626 |
+
abort(404)
|
| 627 |
+
|
| 628 |
+
if full.is_dir():
|
| 629 |
+
dirs, files = [], []
|
| 630 |
+
for e in sorted(full.iterdir()):
|
| 631 |
+
if e.name.startswith("."): # skip hidden
|
| 632 |
+
continue
|
| 633 |
+
rel = str(e.relative_to(Path(".")))
|
| 634 |
+
if e.is_dir():
|
| 635 |
+
dirs.append({"name": e.name, "link": rel})
|
| 636 |
+
elif e.suffix.lower() == ".html":
|
| 637 |
+
files.append({"name": e.name, "link": rel})
|
| 638 |
+
parent = url_for("landing") if not req_path else url_for("browse", req_path=str(full.parent))
|
| 639 |
+
return render_template_string(BROWSER_TEMPLATE,
|
| 640 |
+
parent_link=parent,
|
| 641 |
+
directories=dirs, files=files,
|
| 642 |
+
html_content=None)
|
| 643 |
+
|
| 644 |
+
# serve file content (HTML or plain text)
|
| 645 |
+
if full.suffix.lower() == ".html":
|
| 646 |
+
return send_file(full)
|
| 647 |
+
parent = url_for("browse", req_path=str(full.parent.relative_to(Path("."))))
|
| 648 |
+
txt = full.read_text(encoding="utf-8", errors="replace")
|
| 649 |
+
return render_template_string(BROWSER_TEMPLATE,
|
| 650 |
+
parent_link=parent,
|
| 651 |
+
html_content=f"<pre>{txt}</pre>")
|
| 652 |
+
|
| 653 |
+
# ──���───────────────────── RESULT ENDPOINTS ─────────────────────────
|
| 654 |
+
@app.route("/save-stats", methods=["POST"])
|
| 655 |
+
def save_stats():
|
| 656 |
+
# global SELECTED_CARD
|
| 657 |
+
data = request.get_json(force=True, silent=True) or {}
|
| 658 |
+
sid = data.get("sessionId") or gen_session_id()
|
| 659 |
+
stats = {k: data.get(k) for k in (
|
| 660 |
+
"overallAccuracy","correctItemAccuracy","incorrectItemAccuracy",
|
| 661 |
+
"avgTimeCorrect","avgTimeIncorrect","samples","subjective_feedback")}
|
| 662 |
+
stats["timestamp"] = datetime.utcnow().isoformat()
|
| 663 |
+
stats["session_id"]= sid
|
| 664 |
+
stats["user_name"] = data.get("userName","anonymous")
|
| 665 |
+
|
| 666 |
+
# quick CSV summary (one line)
|
| 667 |
+
row = [
|
| 668 |
+
stats["timestamp"], sid, stats["user_name"],
|
| 669 |
+
data.get("overallAccuracy"), data.get("correctItemAccuracy"),
|
| 670 |
+
data.get("incorrectItemAccuracy"), data.get("avgTimeCorrect"),
|
| 671 |
+
data.get("avgTimeIncorrect"),
|
| 672 |
+
]
|
| 673 |
+
need_header = not CSV_PATH.exists()
|
| 674 |
+
with CSV_PATH.open("a", newline="") as f:
|
| 675 |
+
w = csv.writer(f)
|
| 676 |
+
if need_header:
|
| 677 |
+
w.writerow(CSV_HEADER)
|
| 678 |
+
w.writerow(row)
|
| 679 |
+
|
| 680 |
+
# full JSON per session
|
| 681 |
+
path = save_session_local(sid, stats)
|
| 682 |
+
if HF_TOKEN:
|
| 683 |
+
push_to_hf(path, sid)
|
| 684 |
+
log.info("new result pushed to database")
|
| 685 |
+
SELECTED_CARD = get_the_min_interface()
|
| 686 |
+
log.info("current selected card")
|
| 687 |
+
log.info(SELECTED_CARD)
|
| 688 |
+
return jsonify({"status":"ok"})
|
| 689 |
+
|
| 690 |
+
# ─────────────────────────────── MAIN ──────────────────────────────
|
| 691 |
+
if __name__ == "__main__":
|
| 692 |
+
# For local debugging; HF Spaces will launch via gunicorn/uvicorn
|
| 693 |
+
app.run(host="0.0.0.0", port=int(os.getenv("PORT", 7860)), debug=False)
|
code_counter.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0
|
evaluation/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
evaluation/.ipynb_checkpoints/Untitled-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [],
|
| 3 |
+
"metadata": {},
|
| 4 |
+
"nbformat": 4,
|
| 5 |
+
"nbformat_minor": 5
|
| 6 |
+
}
|
evaluation/eval_interfaces/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
evaluation/eval_interfaces/coding_eval_interface.html
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8"/>
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
| 6 |
+
<title>Explanation Evaluation</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap" rel="stylesheet">
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
/* ──────────── layout & theme ──────────── */
|
| 11 |
+
html, body{ margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
background: #fff; /* Make background white */
|
| 14 |
+
height: 100vh;
|
| 15 |
+
overflow: hidden;
|
| 16 |
+
}
|
| 17 |
+
.container{
|
| 18 |
+
height: 100vh; /* Full viewport height */
|
| 19 |
+
background: #fff; /* Container background white */
|
| 20 |
+
padding: 1rem; /* Keep internal padding */
|
| 21 |
+
box-sizing: border-box;
|
| 22 |
+
width: 100%; /* compensate width after scaling */
|
| 23 |
+
margin: 0; /* Remove margin */
|
| 24 |
+
border-radius: 0; /* Remove rounded corners */
|
| 25 |
+
box-shadow: none; /* Remove shadow */
|
| 26 |
+
display: flex;
|
| 27 |
+
flex-direction: column;}
|
| 28 |
+
header{text-align:center;border-bottom:1px solid #dee2e6}
|
| 29 |
+
header h2{margin:0;font-size:1.5rem;color:#343a40; margin-bottom:1rem}
|
| 30 |
+
/* progress bar */
|
| 31 |
+
#progress-container{margin:.5rem 0;text-align:center;margin-top:5rem}
|
| 32 |
+
progress{width:100%;height:20px;border-radius:10px;appearance:none}
|
| 33 |
+
progress::-webkit-progress-bar{background:#f1f1f1}
|
| 34 |
+
progress::-webkit-progress-value{background:#28a745;border-radius:10px}
|
| 35 |
+
#progress-text{margin-top:.5rem;font-size:1.1rem;color:#495057}
|
| 36 |
+
/* explanation frame */
|
| 37 |
+
|
| 38 |
+
/* explanation frame */
|
| 39 |
+
.explain-row{
|
| 40 |
+
display:flex;
|
| 41 |
+
gap:16px; /* space between iframe and button column */
|
| 42 |
+
align-items:flex-start;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
iframe{
|
| 46 |
+
width: 85%;
|
| 47 |
+
height: 89vh; /* Take most of the height */
|
| 48 |
+
border: 2px solid #ced4da;
|
| 49 |
+
border-radius: 4px;
|
| 50 |
+
background: #fff;
|
| 51 |
+
transform: scale(1, 1);
|
| 52 |
+
transform-origin:top right;
|
| 53 |
+
}
|
| 54 |
+
/* controls */
|
| 55 |
+
.controls{
|
| 56 |
+
flex:1 1 0;
|
| 57 |
+
display:flex;
|
| 58 |
+
flex-direction:column;
|
| 59 |
+
align-items:center;
|
| 60 |
+
text-align:center;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.controls p{font-size:1.2rem;margin: 0.5rem 2rem 0.5rem 0;color:#343a40}
|
| 64 |
+
button{padding:.8rem 1.5rem;margin:.5rem;font-size:1rem;border:none;border-radius:4px;
|
| 65 |
+
cursor:pointer;transition:opacity .3s;background:#6c757d;color:#fff}
|
| 66 |
+
button:hover{opacity:.9}
|
| 67 |
+
/* follow-up (wrong-step) */
|
| 68 |
+
#wrong-box{display:none;margin:1rem auto;text-align:center;flex-direction:column;align-items:center}
|
| 69 |
+
#wrong-step{width:90px;padding:.45rem;text-align:center;font-size:1rem;margin-top:.4rem}
|
| 70 |
+
#confirm-wrong{margin-top:.8rem}
|
| 71 |
+
/* footer buttons */
|
| 72 |
+
#download-btn{display:block;margin:1rem auto;visibility:hidden}
|
| 73 |
+
#download-btn{background:#007bff;display:none}
|
| 74 |
+
#restart-btn{display:block;margin:1rem auto} /* optional offline CSV */
|
| 75 |
+
#restart-btn{background:#dc3545;display:none}
|
| 76 |
+
/* results + feedback */
|
| 77 |
+
#accuracy{margin-top:2rem;padding:1rem;border:1px solid #ced4da;border-radius:4px;
|
| 78 |
+
background:#f8f9fa;color:#495057;font-size:1.1rem;line-height:1.6;text-align:center}
|
| 79 |
+
#accuracy h2{margin:0 0 1rem}
|
| 80 |
+
</style>
|
| 81 |
+
</head>
|
| 82 |
+
<body>
|
| 83 |
+
<div class="container">
|
| 84 |
+
<header><h2>Interactive Code Explanation Experiment</h2></header>
|
| 85 |
+
|
| 86 |
+
<!-- <div id="progress-container">
|
| 87 |
+
<progress id="progress-bar" value="0" max="10"></progress>
|
| 88 |
+
<p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
|
| 89 |
+
</div> -->
|
| 90 |
+
|
| 91 |
+
<div class="explain-row">
|
| 92 |
+
<iframe id="explanation-frame" src=""></iframe>
|
| 93 |
+
|
| 94 |
+
<!-- MAIN CONTROLS (now vertical on the right) -->
|
| 95 |
+
<div class="controls" style="display:none">
|
| 96 |
+
<p id= "instruction"> you <strong>MUST</strong> do the experiment in full screen mode by clicking the button below 👇 </p>
|
| 97 |
+
<button id="full_screen" >Enter Full Screen</button>
|
| 98 |
+
<p>Is the final answer correct or incorrect?</p>
|
| 99 |
+
<button id="btn-correct">Correct</button>
|
| 100 |
+
<button id="btn-wrong" >Incorrect</button>
|
| 101 |
+
<!-- ══════ FOLLOW-UP WHEN INCORRECT ══════ -->
|
| 102 |
+
<div id="wrong-box">
|
| 103 |
+
<span>You think the final answer is incorrect! In which step do you think the model was wrong? Step (1 – <span id="max-step">1</span>)</span>
|
| 104 |
+
<input id="wrong-step" type="number" min="1" step="1">
|
| 105 |
+
<button id="confirm-wrong">Confirm</button>
|
| 106 |
+
</div>
|
| 107 |
+
<div id="progress-container">
|
| 108 |
+
<progress id="progress-bar" value="0" max="10"></progress>
|
| 109 |
+
<p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<button id="download-btn">Download Results</button>
|
| 115 |
+
<button id="restart-btn">Submit</button>
|
| 116 |
+
|
| 117 |
+
<div id="accuracy"></div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
<!-- ──────────── SCRIPT ──────────── -->
|
| 122 |
+
<script>
|
| 123 |
+
|
| 124 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 125 |
+
const btn = document.getElementById('full_screen');
|
| 126 |
+
const span = document.getElementById('instruction');
|
| 127 |
+
|
| 128 |
+
function isFullscreen() {
|
| 129 |
+
return document.fullscreenElement ||
|
| 130 |
+
document.webkitFullscreenElement ||
|
| 131 |
+
document.mozFullScreenElement ||
|
| 132 |
+
document.msFullscreenElement;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
//Show button only if NOT in fullscreen at start
|
| 136 |
+
if (!isFullscreen()) {
|
| 137 |
+
btn.style.visibility = 'visible';
|
| 138 |
+
span.style.visibility = "visible";
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
btn.addEventListener('click', () => {
|
| 144 |
+
if (!isFullscreen()) {
|
| 145 |
+
document.documentElement.requestFullscreen?.() ||
|
| 146 |
+
document.documentElement.webkitRequestFullscreen?.() ||
|
| 147 |
+
document.documentElement.mozRequestFullScreen?.() ||
|
| 148 |
+
document.documentElement.msRequestFullscreen?.();
|
| 149 |
+
}
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
function toggleButton() {
|
| 153 |
+
if (isFullscreen()) {
|
| 154 |
+
btn.style.visibility = 'hidden'; // Hide in fullscreen
|
| 155 |
+
span.style.visibility = "hidden";
|
| 156 |
+
} else {
|
| 157 |
+
btn.style.visibility = 'visible'; // Show when not fullscreen
|
| 158 |
+
span.style.visibility = "visible";
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
document.addEventListener('fullscreenchange', toggleButton);
|
| 162 |
+
document.addEventListener('webkitfullscreenchange', toggleButton);
|
| 163 |
+
document.addEventListener('mozfullscreenchange', toggleButton);
|
| 164 |
+
document.addEventListener('MSFullscreenChange', toggleButton);
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
/* utilities */
|
| 168 |
+
const shuffle=a=>{for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;}
|
| 169 |
+
const nowISO=()=>new Date().toISOString();
|
| 170 |
+
/* session vars */
|
| 171 |
+
let userName="anonymous"; function setUserName(n){userName=n;}
|
| 172 |
+
const sessionId=crypto.randomUUID();
|
| 173 |
+
const base ="interactive-llm-xai/evaluation/eval_interfaces/interactive_coding_explanations/";
|
| 174 |
+
const files = [
|
| 175 |
+
// 1 “right” explanation
|
| 176 |
+
`${base}interactive_code_right_NA_41.html`,
|
| 177 |
+
`${base}interactive_code_right_CA_${USER_COUNTER}.html`,
|
| 178 |
+
`${base}interactive_code_wrong_CO_${USER_COUNTER}.html`,
|
| 179 |
+
`${base}interactive_code_wrong_CS_${USER_COUNTER}.html`,
|
| 180 |
+
`${base}interactive_code_wrong_CV_${USER_COUNTER}.html`,
|
| 181 |
+
`${base}interactive_code_wrong_FC_${USER_COUNTER}.html`,
|
| 182 |
+
`${base}interactive_code_wrong_HA_${USER_COUNTER}.html`,
|
| 183 |
+
`${base}interactive_code_wrong_MS_${USER_COUNTER}.html`,
|
| 184 |
+
`${base}interactive_code_wrong_OP_31.html`,
|
| 185 |
+
`${base}interactive_code_wrong_UC_${USER_COUNTER}.html`
|
| 186 |
+
];
|
| 187 |
+
const total=files.length;
|
| 188 |
+
/* state */
|
| 189 |
+
let idx=0,startTime="",firstClick="";
|
| 190 |
+
let clickCounts={play:0,stop:0,next:0,prev:0};
|
| 191 |
+
const samples=[];
|
| 192 |
+
let currentMaxStep=1;
|
| 193 |
+
/* DOM */
|
| 194 |
+
const frame=document.getElementById('explanation-frame');
|
| 195 |
+
const controls=document.querySelector('.controls');
|
| 196 |
+
const downloadBtn=document.getElementById('download-btn');
|
| 197 |
+
const restartBtn=document.getElementById('restart-btn');
|
| 198 |
+
const wrongBox=document.getElementById('wrong-box');
|
| 199 |
+
const wrongInput=document.getElementById('wrong-step');
|
| 200 |
+
const maxStepSpan=document.getElementById('max-step');
|
| 201 |
+
const accDiv=document.getElementById('accuracy');
|
| 202 |
+
/* progress */
|
| 203 |
+
function updateProgress(){
|
| 204 |
+
document.getElementById('progress-bar').value=idx;
|
| 205 |
+
document.getElementById('progress-text').textContent=
|
| 206 |
+
idx<total?`Question ${idx+1} of ${total} (Remaining: ${total-idx})`
|
| 207 |
+
:'All questions reviewed.';
|
| 208 |
+
}
|
| 209 |
+
/* telemetry from explanation page */
|
| 210 |
+
window.addEventListener('message',ev=>{
|
| 211 |
+
if(!ev.data||ev.data.type!=='xai-click')return;
|
| 212 |
+
clickCounts[ev.data.key]=(clickCounts[ev.data.key]||0)+1;
|
| 213 |
+
if(!firstClick)firstClick=nowISO();
|
| 214 |
+
});
|
| 215 |
+
/* navigation */
|
| 216 |
+
function loadNext(){
|
| 217 |
+
if(idx>=total){renderResults();return;}
|
| 218 |
+
updateProgress();
|
| 219 |
+
frame.src=files[idx];
|
| 220 |
+
controls.style.display='block';downloadBtn.style.display='block';
|
| 221 |
+
wrongBox.style.display='none';wrongInput.value='';
|
| 222 |
+
startTime=Date.now();firstClick=null;clickCounts={play:0,stop:0,next:0,prev:0};
|
| 223 |
+
}
|
| 224 |
+
frame.addEventListener('load',()=>{
|
| 225 |
+
const hide=frame.src.includes('instructions.html');
|
| 226 |
+
controls.style.display=hide?'none':'block';
|
| 227 |
+
downloadBtn.style.display=hide?'none':'black';
|
| 228 |
+
restartBtn.style.display='none';
|
| 229 |
+
if(!hide){
|
| 230 |
+
currentMaxStep=10;
|
| 231 |
+
wrongInput.min=1;wrongInput.max=currentMaxStep;maxStepSpan.textContent=currentMaxStep;
|
| 232 |
+
}
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
/* answer flow */
|
| 237 |
+
document.getElementById('btn-correct').onclick=()=>saveAnswer('correct',0);
|
| 238 |
+
document.getElementById('btn-wrong').onclick=()=>{
|
| 239 |
+
wrongBox.style.display='flex';wrongInput.value='';wrongInput.focus();
|
| 240 |
+
};
|
| 241 |
+
document.getElementById('confirm-wrong').onclick=()=>{
|
| 242 |
+
const n=parseInt(wrongInput.value,10);
|
| 243 |
+
if(Number.isNaN(n)||n<1||n>currentMaxStep){
|
| 244 |
+
alert(`Enter a valid step number (1 – ${currentMaxStep})`);wrongInput.focus();return;
|
| 245 |
+
}
|
| 246 |
+
saveAnswer('incorrect',n);wrongBox.style.display='none';
|
| 247 |
+
};
|
| 248 |
+
function saveAnswer(ans,userInputWrongStep){
|
| 249 |
+
const elapsed=(Date.now()-startTime)/1000;
|
| 250 |
+
const ActualWrongStep = parseInt(frame.contentDocument.querySelector('.wrong-step')?.textContent.trim() ?? '', 10);
|
| 251 |
+
samples.push({
|
| 252 |
+
file:files[idx],
|
| 253 |
+
id:files[idx].match(/([^/_]+_[^/_]+_\d+)\.html$/)[1],
|
| 254 |
+
label:files[idx].includes('right')?'correct':'wrong',
|
| 255 |
+
humanAnswer:ans,
|
| 256 |
+
actualWrongstep: ActualWrongStep,
|
| 257 |
+
userInputWrongStep,
|
| 258 |
+
elapsedSeconds:+elapsed.toFixed(3),
|
| 259 |
+
clickCounts,
|
| 260 |
+
// firstActionAt:firstClick,
|
| 261 |
+
// answeredAt:nowISO()
|
| 262 |
+
});
|
| 263 |
+
idx++;loadNext();
|
| 264 |
+
}
|
| 265 |
+
/* results + feedback */
|
| 266 |
+
function renderResults(){
|
| 267 |
+
/* metrics */
|
| 268 |
+
const correctItems=samples.filter(s=>s.label==='correct');
|
| 269 |
+
const incorrectItems=samples.filter(s=>s.label==='wrong');
|
| 270 |
+
const correctHits=samples.filter(s=>s.label==='correct'&&s.humanAnswer==='correct').length;
|
| 271 |
+
const incorrectHits=samples.filter(s=>s.label==='wrong'&&s.humanAnswer==='incorrect').length;
|
| 272 |
+
const overallCorrect=correctHits+incorrectHits;
|
| 273 |
+
const overallAcc=((overallCorrect/total)*100).toFixed(2);
|
| 274 |
+
const correctAcc =correctItems.length?((correctHits /correctItems.length )*100).toFixed(2):'0.00';
|
| 275 |
+
const incorrectAcc=incorrectItems.length?((incorrectHits/incorrectItems.length)*100).toFixed(2):'0.00';
|
| 276 |
+
const avgTC=(correctItems .reduce((a,s)=>a+s.elapsedSeconds,0)/(correctItems.length ||1)).toFixed(2);
|
| 277 |
+
const avgTI=(incorrectItems.reduce((a,s)=>a+s.elapsedSeconds,0)/(incorrectItems.length||1)).toFixed(2);
|
| 278 |
+
/* hide UI parts */
|
| 279 |
+
controls.style.display='none';downloadBtn.style.display='none';
|
| 280 |
+
document.getElementById('progress-container').style.display='none';
|
| 281 |
+
frame.style.display='none';
|
| 282 |
+
/* results + feedback UI */
|
| 283 |
+
accDiv.innerHTML=`
|
| 284 |
+
<h2>Results</h2>
|
| 285 |
+
<p><strong>Overall Accuracy:</strong> ${overallCorrect}/${total} (${overallAcc}%)</p>
|
| 286 |
+
<p><strong>Correct-Item Accuracy:</strong> ${correctAcc}%</p>
|
| 287 |
+
<p><strong>Incorrect-Item Accuracy:</strong> ${incorrectAcc}%</p>
|
| 288 |
+
<p><strong>Avg Time (Correct):</strong> ${avgTC} s</p>
|
| 289 |
+
<p><strong>Avg Time (Incorrect):</strong> ${avgTI} s</p>
|
| 290 |
+
<textarea id="feedback-box" placeholder="Any comments or suggestions?"></textarea>
|
| 291 |
+
`;
|
| 292 |
+
restartBtn.style.display='block';
|
| 293 |
+
/* send + restart */
|
| 294 |
+
restartBtn.onclick=()=>{
|
| 295 |
+
const subjective_feedback=document.getElementById('feedback-box').value.trim();
|
| 296 |
+
fetch('/save-stats', {
|
| 297 |
+
method: 'POST',
|
| 298 |
+
headers: {'Content-Type': 'application/json'},
|
| 299 |
+
body: JSON.stringify({
|
| 300 |
+
sessionId,
|
| 301 |
+
userName,
|
| 302 |
+
overallAccuracy: +overallAcc,
|
| 303 |
+
correctItemAccuracy: correctAcc,
|
| 304 |
+
incorrectItemAccuracy: incorrectAcc,
|
| 305 |
+
avgTimeCorrect: avgTC,
|
| 306 |
+
avgTimeIncorrect: avgTI,
|
| 307 |
+
samples,
|
| 308 |
+
subjective_feedback
|
| 309 |
+
})
|
| 310 |
+
}).then(response => {
|
| 311 |
+
if (response.ok) {
|
| 312 |
+
window.location.href = 'interactive-llm-xai/evaluation/eval_interfaces/thank_you_icoding.html';
|
| 313 |
+
} else {
|
| 314 |
+
alert('Failed to save stats. Please try again.');
|
| 315 |
+
}
|
| 316 |
+
});
|
| 317 |
+
};
|
| 318 |
+
}
|
| 319 |
+
/* offline CSV (optional) */
|
| 320 |
+
downloadBtn.onclick=()=>{
|
| 321 |
+
const hdr=['file','label','humanAnswer','wrongStep','time','play','stop','next','prev'];
|
| 322 |
+
const rows=[hdr,...samples.map(s=>[
|
| 323 |
+
s.file,s.label,s.humanAnswer,s.wrongStep??'',s.elapsedSeconds,
|
| 324 |
+
s.clickCounts.play,s.clickCounts.stop,s.clickCounts.next,s.clickCounts.prev
|
| 325 |
+
])];
|
| 326 |
+
const csv=new Blob([rows.map(r=>r.join(',')).join('\n')],{type:'text/csv'});
|
| 327 |
+
const url=URL.createObjectURL(csv);
|
| 328 |
+
const a=document.createElement('a');a.href=url;a.download='results.csv';a.click();
|
| 329 |
+
URL.revokeObjectURL(url);
|
| 330 |
+
};
|
| 331 |
+
/* kick-off */
|
| 332 |
+
updateProgress();
|
| 333 |
+
frame.src="interactive-llm-xai/evaluation/eval_interfaces/instructions.html";
|
| 334 |
+
</script>
|
| 335 |
+
</body>
|
| 336 |
+
</html>
|
evaluation/eval_interfaces/graph_eval_interface.html
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8"/>
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
| 6 |
+
<title>Explanation Evaluation</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap" rel="stylesheet">
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
/* ──────────── layout & theme ──────────── */
|
| 11 |
+
html, body{ margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
background: #fff; /* Make background white */
|
| 14 |
+
height: 100vh;
|
| 15 |
+
overflow: hidden;
|
| 16 |
+
}
|
| 17 |
+
.container{
|
| 18 |
+
height: 100vh; /* Full viewport height */
|
| 19 |
+
background: #fff; /* Container background white */
|
| 20 |
+
padding: 1rem; /* Keep internal padding */
|
| 21 |
+
box-sizing: border-box;
|
| 22 |
+
width: 100%; /* compensate width after scaling */
|
| 23 |
+
margin: 0; /* Remove margin */
|
| 24 |
+
border-radius: 0; /* Remove rounded corners */
|
| 25 |
+
box-shadow: none; /* Remove shadow */
|
| 26 |
+
display: flex;
|
| 27 |
+
flex-direction: column;}
|
| 28 |
+
header{text-align:center;border-bottom:1px solid #dee2e6}
|
| 29 |
+
header h2{margin:0;font-size:1.5rem;color:#343a40; margin-bottom:1rem}
|
| 30 |
+
/* progress bar */
|
| 31 |
+
#progress-container{margin:.5rem 0;text-align:center;margin-top:5rem}
|
| 32 |
+
progress{width:100%;height:20px;border-radius:10px;appearance:none}
|
| 33 |
+
progress::-webkit-progress-bar{background:#f1f1f1}
|
| 34 |
+
progress::-webkit-progress-value{background:#28a745;border-radius:10px}
|
| 35 |
+
#progress-text{margin-top:.5rem;font-size:1.1rem;color:#495057}
|
| 36 |
+
/* explanation frame */
|
| 37 |
+
|
| 38 |
+
/* explanation frame */
|
| 39 |
+
.explain-row{
|
| 40 |
+
display:flex;
|
| 41 |
+
gap:16px; /* space between iframe and button column */
|
| 42 |
+
align-items:flex-start;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
iframe{
|
| 46 |
+
width: 85%;
|
| 47 |
+
height: 89vh; /* Take most of the height */
|
| 48 |
+
border: 2px solid #ced4da;
|
| 49 |
+
border-radius: 4px;
|
| 50 |
+
background: #fff;
|
| 51 |
+
transform: scale(1, 1);
|
| 52 |
+
transform-origin:top right;
|
| 53 |
+
}
|
| 54 |
+
/* controls */
|
| 55 |
+
.controls{
|
| 56 |
+
flex:1 1 0;
|
| 57 |
+
display:flex;
|
| 58 |
+
flex-direction:column;
|
| 59 |
+
align-items:center;
|
| 60 |
+
text-align:center;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.controls p{font-size:1.2rem;margin: 0.5rem 2rem 0.5rem 0;color:#343a40}
|
| 64 |
+
button{padding:.8rem 1.5rem;margin:.5rem;font-size:1rem;border:none;border-radius:4px;
|
| 65 |
+
cursor:pointer;transition:opacity .3s;background:#6c757d;color:#fff}
|
| 66 |
+
button:hover{opacity:.9}
|
| 67 |
+
/* follow-up (wrong-step) */
|
| 68 |
+
#wrong-box{display:none;margin:1rem auto;text-align:center;flex-direction:column;align-items:center}
|
| 69 |
+
#wrong-step{width:90px;padding:.45rem;text-align:center;font-size:1rem;margin-top:.4rem}
|
| 70 |
+
#confirm-wrong{margin-top:.8rem}
|
| 71 |
+
/* footer buttons */
|
| 72 |
+
#download-btn{display:block;margin:1rem auto;visibility:hidden}
|
| 73 |
+
#download-btn{background:#007bff;display:none}
|
| 74 |
+
#restart-btn{display:block;margin:1rem auto} /* optional offline CSV */
|
| 75 |
+
#restart-btn{background:#dc3545;display:none}
|
| 76 |
+
/* results + feedback */
|
| 77 |
+
#accuracy{margin-top:2rem;padding:1rem;border:1px solid #ced4da;border-radius:4px;
|
| 78 |
+
background:#f8f9fa;color:#495057;font-size:1.1rem;line-height:1.6;text-align:center}
|
| 79 |
+
#accuracy h2{margin:0 0 1rem}
|
| 80 |
+
</style>
|
| 81 |
+
</head>
|
| 82 |
+
<body>
|
| 83 |
+
<div class="container">
|
| 84 |
+
<header><h2>Interactive Graph Explanation Experiment</h2></header>
|
| 85 |
+
|
| 86 |
+
<!-- <div id="progress-container">
|
| 87 |
+
<progress id="progress-bar" value="0" max="10"></progress>
|
| 88 |
+
<p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
|
| 89 |
+
</div> -->
|
| 90 |
+
|
| 91 |
+
<div class="explain-row">
|
| 92 |
+
<iframe id="explanation-frame" src=""></iframe>
|
| 93 |
+
|
| 94 |
+
<!-- MAIN CONTROLS (now vertical on the right) -->
|
| 95 |
+
<div class="controls" style="display:none">
|
| 96 |
+
<p id= "instruction"> you <strong>MUST</strong> do the experiment in full screen mode by clicking the button below 👇 </p>
|
| 97 |
+
<button id="full_screen" >Enter Full Screen</button>
|
| 98 |
+
<p>Is the final answer correct or incorrect?</p>
|
| 99 |
+
<button id="btn-correct">Correct</button>
|
| 100 |
+
<button id="btn-wrong">Incorrect</button>
|
| 101 |
+
<!-- ══════ FOLLOW-UP WHEN INCORRECT ══════ -->
|
| 102 |
+
<div id="wrong-box">
|
| 103 |
+
<span>You think the final answer is incorrect! In which step do you think the model was wrong? Step (1 – <span id="max-step">1</span>)</span>
|
| 104 |
+
<input id="wrong-step" type="number" min="1" step="1">
|
| 105 |
+
<button id="confirm-wrong">Confirm</button>
|
| 106 |
+
</div>
|
| 107 |
+
<div id="progress-container">
|
| 108 |
+
<progress id="progress-bar" value="0" max="10"></progress>
|
| 109 |
+
<p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<button id="download-btn">Download Results</button>
|
| 115 |
+
<button id="restart-btn">Submit</button>
|
| 116 |
+
|
| 117 |
+
<div id="accuracy"></div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
<!-- ──────────── SCRIPT ──────────── -->
|
| 122 |
+
<script>
|
| 123 |
+
|
| 124 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 125 |
+
const btn = document.getElementById('full_screen');
|
| 126 |
+
const span = document.getElementById('instruction');
|
| 127 |
+
function isFullscreen() {
|
| 128 |
+
return document.fullscreenElement ||
|
| 129 |
+
document.webkitFullscreenElement ||
|
| 130 |
+
document.mozFullScreenElement ||
|
| 131 |
+
document.msFullscreenElement;
|
| 132 |
+
}
|
| 133 |
+
// Show button only if NOT in fullscreen at start
|
| 134 |
+
if (!isFullscreen()) {
|
| 135 |
+
btn.style.visibility = 'visible';
|
| 136 |
+
span.style.visibility = "visible";
|
| 137 |
+
}
|
| 138 |
+
btn.addEventListener('click', () => {
|
| 139 |
+
if (!isFullscreen()) {
|
| 140 |
+
document.documentElement.requestFullscreen?.() ||
|
| 141 |
+
document.documentElement.webkitRequestFullscreen?.() ||
|
| 142 |
+
document.documentElement.mozRequestFullScreen?.() ||
|
| 143 |
+
document.documentElement.msRequestFullscreen?.();
|
| 144 |
+
}
|
| 145 |
+
});
|
| 146 |
+
function toggleButton() {
|
| 147 |
+
if (isFullscreen()) {
|
| 148 |
+
btn.style.visibility = 'hidden'; // Hide in fullscreen
|
| 149 |
+
span.style.visibility = "hidden";
|
| 150 |
+
} else {
|
| 151 |
+
btn.style.visibility = 'visible'; // Show when not fullscreen
|
| 152 |
+
span.style.visibility = "visible";
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
document.addEventListener('fullscreenchange', toggleButton);
|
| 156 |
+
document.addEventListener('webkitfullscreenchange', toggleButton);
|
| 157 |
+
document.addEventListener('mozfullscreenchange', toggleButton);
|
| 158 |
+
document.addEventListener('MSFullscreenChange', toggleButton);
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
/* utilities */
|
| 162 |
+
const shuffle=a=>{for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;}
|
| 163 |
+
const nowISO=()=>new Date().toISOString();
|
| 164 |
+
/* session vars */
|
| 165 |
+
let userName="anonymous"; function setUserName(n){userName=n;}
|
| 166 |
+
const sessionId=crypto.randomUUID();
|
| 167 |
+
const base =
|
| 168 |
+
"interactive-llm-xai/evaluation/eval_interfaces/interactive_graph_explanations/";
|
| 169 |
+
const files = [
|
| 170 |
+
// 1 “right” explanation
|
| 171 |
+
// 1 “right” explanation
|
| 172 |
+
`${base}interactive_graph_right_NA_41.html`,
|
| 173 |
+
`${base}interactive_graph_wrong_CA_13.html`,
|
| 174 |
+
`${base}interactive_graph_wrong_CO_6.html`,
|
| 175 |
+
`${base}interactive_graph_wrong_CS_33.html`,
|
| 176 |
+
`${base}interactive_graph_wrong_CV_24.html`,
|
| 177 |
+
`${base}interactive_graph_wrong_FC_19.html`,
|
| 178 |
+
`${base}interactive_graph_wrong_HA_19.html`,
|
| 179 |
+
`${base}interactive_graph_wrong_MS_25.html`,
|
| 180 |
+
`${base}interactive_graph_wrong_OP_31.html`,
|
| 181 |
+
`${base}interactive_graph_wrong_UC_39.html`
|
| 182 |
+
];
|
| 183 |
+
|
| 184 |
+
const total=files.length;
|
| 185 |
+
/* state */
|
| 186 |
+
let idx=0,startTime="",firstClick="";
|
| 187 |
+
let clickCounts={play:0,stop:0,next:0,prev:0};
|
| 188 |
+
const samples=[];
|
| 189 |
+
let currentMaxStep=1;
|
| 190 |
+
/* DOM */
|
| 191 |
+
const frame=document.getElementById('explanation-frame');
|
| 192 |
+
const controls=document.querySelector('.controls');
|
| 193 |
+
const downloadBtn=document.getElementById('download-btn');
|
| 194 |
+
const restartBtn=document.getElementById('restart-btn');
|
| 195 |
+
const wrongBox=document.getElementById('wrong-box');
|
| 196 |
+
const wrongInput=document.getElementById('wrong-step');
|
| 197 |
+
const maxStepSpan=document.getElementById('max-step');
|
| 198 |
+
const accDiv=document.getElementById('accuracy');
|
| 199 |
+
/* progress */
|
| 200 |
+
function updateProgress(){
|
| 201 |
+
document.getElementById('progress-bar').value=idx;
|
| 202 |
+
document.getElementById('progress-text').textContent=
|
| 203 |
+
idx<total?`Question ${idx+1} of ${total} (Remaining: ${total-idx})`
|
| 204 |
+
:'All questions reviewed.';
|
| 205 |
+
}
|
| 206 |
+
/* telemetry from explanation page */
|
| 207 |
+
window.addEventListener('message',ev=>{
|
| 208 |
+
if(!ev.data||ev.data.type!=='xai-click')return;
|
| 209 |
+
clickCounts[ev.data.key]=(clickCounts[ev.data.key]||0)+1;
|
| 210 |
+
if(!firstClick)firstClick=nowISO();
|
| 211 |
+
});
|
| 212 |
+
/* navigation */
|
| 213 |
+
function loadNext(){
|
| 214 |
+
if(idx>=total){renderResults();return;}
|
| 215 |
+
updateProgress();
|
| 216 |
+
frame.src=files[idx];
|
| 217 |
+
controls.style.display='block';downloadBtn.style.display='block';
|
| 218 |
+
wrongBox.style.display='none';wrongInput.value='';
|
| 219 |
+
startTime=Date.now();firstClick=null;clickCounts={play:0,stop:0,next:0,prev:0};
|
| 220 |
+
}
|
| 221 |
+
frame.addEventListener('load',()=>{
|
| 222 |
+
const hide=frame.src.includes('instructions.html');
|
| 223 |
+
controls.style.display=hide?'none':'block';
|
| 224 |
+
downloadBtn.style.display=hide?'none':'black';
|
| 225 |
+
restartBtn.style.display='none';
|
| 226 |
+
if(!hide){
|
| 227 |
+
currentMaxStep=10;
|
| 228 |
+
wrongInput.min=1;wrongInput.max=currentMaxStep;maxStepSpan.textContent=currentMaxStep;
|
| 229 |
+
}
|
| 230 |
+
});
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
/* answer flow */
|
| 234 |
+
document.getElementById('btn-correct').onclick=()=>saveAnswer('correct',0);
|
| 235 |
+
document.getElementById('btn-wrong').onclick=()=>{
|
| 236 |
+
wrongBox.style.display='flex';wrongInput.value='';wrongInput.focus();
|
| 237 |
+
};
|
| 238 |
+
document.getElementById('confirm-wrong').onclick=()=>{
|
| 239 |
+
const n=parseInt(wrongInput.value,10);
|
| 240 |
+
if(Number.isNaN(n)||n<1||n>currentMaxStep){
|
| 241 |
+
alert(`Enter a valid step number (1 – ${currentMaxStep})`);wrongInput.focus();return;
|
| 242 |
+
}
|
| 243 |
+
saveAnswer('incorrect',n);wrongBox.style.display='none';
|
| 244 |
+
};
|
| 245 |
+
function saveAnswer(ans,userInputWrongStep){
|
| 246 |
+
const elapsed=(Date.now()-startTime)/1000;
|
| 247 |
+
const ActualWrongStep = parseInt(frame.contentDocument.querySelector('.wrong-step')?.textContent.trim() ?? '', 10);
|
| 248 |
+
samples.push({
|
| 249 |
+
file:files[idx],
|
| 250 |
+
id:files[idx].match(/([^/_]+_[^/_]+_\d+)\.html$/)[1],
|
| 251 |
+
label:files[idx].includes('right')?'correct':'wrong',
|
| 252 |
+
humanAnswer:ans,
|
| 253 |
+
actualWrongstep: ActualWrongStep,
|
| 254 |
+
userInputWrongStep,
|
| 255 |
+
elapsedSeconds:+elapsed.toFixed(3),
|
| 256 |
+
clickCounts,
|
| 257 |
+
// firstActionAt:firstClick,
|
| 258 |
+
// answeredAt:nowISO()
|
| 259 |
+
});
|
| 260 |
+
idx++;loadNext();
|
| 261 |
+
}
|
| 262 |
+
/* results + feedback */
|
| 263 |
+
function renderResults(){
|
| 264 |
+
/* metrics */
|
| 265 |
+
const correctItems=samples.filter(s=>s.label==='correct');
|
| 266 |
+
const incorrectItems=samples.filter(s=>s.label==='wrong');
|
| 267 |
+
const correctHits=samples.filter(s=>s.label==='correct'&&s.humanAnswer==='correct').length;
|
| 268 |
+
const incorrectHits=samples.filter(s=>s.label==='wrong'&&s.humanAnswer==='incorrect').length;
|
| 269 |
+
const overallCorrect=correctHits+incorrectHits;
|
| 270 |
+
const overallAcc=((overallCorrect/total)*100).toFixed(2);
|
| 271 |
+
const correctAcc =correctItems.length?((correctHits /correctItems.length )*100).toFixed(2):'0.00';
|
| 272 |
+
const incorrectAcc=incorrectItems.length?((incorrectHits/incorrectItems.length)*100).toFixed(2):'0.00';
|
| 273 |
+
const avgTC=(correctItems .reduce((a,s)=>a+s.elapsedSeconds,0)/(correctItems.length ||1)).toFixed(2);
|
| 274 |
+
const avgTI=(incorrectItems.reduce((a,s)=>a+s.elapsedSeconds,0)/(incorrectItems.length||1)).toFixed(2);
|
| 275 |
+
/* hide UI parts */
|
| 276 |
+
controls.style.display='none';downloadBtn.style.display='none';
|
| 277 |
+
document.getElementById('progress-container').style.display='none';
|
| 278 |
+
frame.style.display='none';
|
| 279 |
+
/* results + feedback UI */
|
| 280 |
+
accDiv.innerHTML=`
|
| 281 |
+
<h2>Results</h2>
|
| 282 |
+
<p><strong>Overall Accuracy:</strong> ${overallCorrect}/${total} (${overallAcc}%)</p>
|
| 283 |
+
<p><strong>Correct-Item Accuracy:</strong> ${correctAcc}%</p>
|
| 284 |
+
<p><strong>Incorrect-Item Accuracy:</strong> ${incorrectAcc}%</p>
|
| 285 |
+
<p><strong>Avg Time (Correct):</strong> ${avgTC} s</p>
|
| 286 |
+
<p><strong>Avg Time (Incorrect):</strong> ${avgTI} s</p>
|
| 287 |
+
<textarea id="feedback-box" placeholder="Any comments or suggestions?"></textarea>
|
| 288 |
+
`;
|
| 289 |
+
restartBtn.style.display='block';
|
| 290 |
+
/* send + restart */
|
| 291 |
+
restartBtn.onclick=()=>{
|
| 292 |
+
const subjective_feedback=document.getElementById('feedback-box').value.trim();
|
| 293 |
+
fetch('/save-stats', {
|
| 294 |
+
method: 'POST',
|
| 295 |
+
headers: {'Content-Type': 'application/json'},
|
| 296 |
+
body: JSON.stringify({
|
| 297 |
+
sessionId,
|
| 298 |
+
userName,
|
| 299 |
+
overallAccuracy: +overallAcc,
|
| 300 |
+
correctItemAccuracy: correctAcc,
|
| 301 |
+
incorrectItemAccuracy: incorrectAcc,
|
| 302 |
+
avgTimeCorrect: avgTC,
|
| 303 |
+
avgTimeIncorrect: avgTI,
|
| 304 |
+
samples,
|
| 305 |
+
subjective_feedback
|
| 306 |
+
})
|
| 307 |
+
}).then(response => {
|
| 308 |
+
if (response.ok) {
|
| 309 |
+
window.location.href = 'interactive-llm-xai/evaluation/eval_interfaces/thank_you_igraph.html';
|
| 310 |
+
} else {
|
| 311 |
+
alert('Failed to save stats. Please try again.');
|
| 312 |
+
}
|
| 313 |
+
});
|
| 314 |
+
};
|
| 315 |
+
}
|
| 316 |
+
/* offline CSV (optional) */
|
| 317 |
+
downloadBtn.onclick=()=>{
|
| 318 |
+
const hdr=['file','label','humanAnswer','wrongStep','time','play','stop','next','prev'];
|
| 319 |
+
const rows=[hdr,...samples.map(s=>[
|
| 320 |
+
s.file,s.label,s.humanAnswer,s.wrongStep??'',s.elapsedSeconds,
|
| 321 |
+
s.clickCounts.play,s.clickCounts.stop,s.clickCounts.next,s.clickCounts.prev
|
| 322 |
+
])];
|
| 323 |
+
const csv=new Blob([rows.map(r=>r.join(',')).join('\n')],{type:'text/csv'});
|
| 324 |
+
const url=URL.createObjectURL(csv);
|
| 325 |
+
const a=document.createElement('a');a.href=url;a.download='results.csv';a.click();
|
| 326 |
+
URL.revokeObjectURL(url);
|
| 327 |
+
};
|
| 328 |
+
/* kick-off */
|
| 329 |
+
updateProgress();
|
| 330 |
+
frame.src="interactive-llm-xai/evaluation/eval_interfaces/instructions.html";
|
| 331 |
+
</script>
|
| 332 |
+
</body>
|
| 333 |
+
</html>
|
evaluation/eval_interfaces/instructions.html
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Experiment Instructions</title>
|
| 6 |
+
<style>
|
| 7 |
+
/* ─────────── base ─────────── */
|
| 8 |
+
*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}
|
| 9 |
+
:root{
|
| 10 |
+
--gap:1.25rem;
|
| 11 |
+
--card-border:#0d6efd;
|
| 12 |
+
--card-bg:#ffffff;
|
| 13 |
+
}
|
| 14 |
+
html,body{height:80%}
|
| 15 |
+
body{
|
| 16 |
+
font-family:Arial,Helvetica,sans-serif;
|
| 17 |
+
line-height:1.55;
|
| 18 |
+
height:800px;
|
| 19 |
+
background:#f8f9fa;
|
| 20 |
+
color:#212529;
|
| 21 |
+
display:flex;
|
| 22 |
+
flex-direction:column;
|
| 23 |
+
align-items:center; /* center on huge screens */
|
| 24 |
+
padding:var(--gap);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/* ─────────── header ─────────── */
|
| 28 |
+
h2{
|
| 29 |
+
color:#343a40;
|
| 30 |
+
margin-bottom:var(--gap);
|
| 31 |
+
font-size:1.6rem;
|
| 32 |
+
font-weight:700;
|
| 33 |
+
text-align:center;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* ─────────── card stack ─────────── */
|
| 37 |
+
.stack{
|
| 38 |
+
flex:1;
|
| 39 |
+
width:100%;
|
| 40 |
+
max-width:820px; /* keeps long lines readable */
|
| 41 |
+
display:flex;
|
| 42 |
+
flex-direction:column;
|
| 43 |
+
gap:var(--gap);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.card{
|
| 47 |
+
background:var(--card-bg);
|
| 48 |
+
border-left:5px solid var(--card-border);
|
| 49 |
+
padding:1rem 1.25rem;
|
| 50 |
+
border-radius:6px;
|
| 51 |
+
box-shadow:0 1px 4px rgba(0,0,0,.06);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.card h3{
|
| 55 |
+
color:#343a40;
|
| 56 |
+
font-size:1.1rem;
|
| 57 |
+
margin-bottom:.5rem;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.card ul{padding-left:1.2rem}
|
| 61 |
+
.card p,
|
| 62 |
+
.card li{margin-bottom:.55rem}
|
| 63 |
+
|
| 64 |
+
/* ─────────── start button ─────────── */
|
| 65 |
+
.start{
|
| 66 |
+
align-self:center;
|
| 67 |
+
margin-top:var(--gap);
|
| 68 |
+
padding:.75rem 1.6rem;
|
| 69 |
+
font-size:1rem;
|
| 70 |
+
background:#0d6efd;
|
| 71 |
+
color:#fff;
|
| 72 |
+
border:none;
|
| 73 |
+
border-radius:4px;
|
| 74 |
+
cursor:pointer;
|
| 75 |
+
transition:opacity .25s;
|
| 76 |
+
}
|
| 77 |
+
.start:hover{opacity:.9}
|
| 78 |
+
|
| 79 |
+
/* ─────────── small screens ─────────── */
|
| 80 |
+
@media(max-width:480px){
|
| 81 |
+
body{padding:.9rem}
|
| 82 |
+
.card{padding:.9rem 1rem}
|
| 83 |
+
}
|
| 84 |
+
</style>
|
| 85 |
+
</head>
|
| 86 |
+
<body>
|
| 87 |
+
|
| 88 |
+
<h2>🧠 Experiment Instructions</h2>
|
| 89 |
+
|
| 90 |
+
<!-- instruction blocks -->
|
| 91 |
+
<div class="stack">
|
| 92 |
+
<div class="card">
|
| 93 |
+
<h3>🧭 Interface Overview</h3>
|
| 94 |
+
<p>You will review <strong>10 math problems</strong> and decide whether each final numerical answer is <em>correct</em> or <em>incorrect</em>.</p>
|
| 95 |
+
<ul>
|
| 96 |
+
<li><strong>Left panel</strong> — problem statement & facts</li>
|
| 97 |
+
<li><strong>Right panel</strong> — step-by-step explanation</li>
|
| 98 |
+
</ul>
|
| 99 |
+
</div>
|
| 100 |
+
|
| 101 |
+
<div class="card">
|
| 102 |
+
<h3>🕹️ Controls</h3>
|
| 103 |
+
<ul>
|
| 104 |
+
<li><strong>▶ / ❚❚</strong> — auto-play / pause</li>
|
| 105 |
+
<li><strong>⤴ / ⤵</strong> — previous / next step manually</li>
|
| 106 |
+
</ul>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<div class="card">
|
| 110 |
+
<h3>🎨 Highlights</h3>
|
| 111 |
+
<p>Variables are colour-coded and their values update live as each step runs.</p>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div class="card">
|
| 115 |
+
<h3>❌Potential Errors</h3>
|
| 116 |
+
<p>Some explanations may contain errors. If you notice any, please indicate the step where you believe the first error occurs..</p>
|
| 117 |
+
<p>The error type includes:</p>
|
| 118 |
+
<ul>
|
| 119 |
+
<li><strong>Calculation Error (CA)</strong>: Error appears during the calculation process.</li>
|
| 120 |
+
<li><strong>Counting Error (CO)</strong>: Error occurs during the counting process.</li>
|
| 121 |
+
<li><strong>Context Value Error (CV)</strong>: Error arises when attributes of named entities do not align with the information provided.</li>
|
| 122 |
+
<li><strong>Hallucination (HA)</strong>: Error involves adding fictitious unrelated statements contradictory to the question.</li>
|
| 123 |
+
<li><strong>Unit Conversion Error (UC)</strong>: Error occurs during unit conversion process.</li>
|
| 124 |
+
<li><strong>Operator Error (OP)</strong>: Error involves a single operator being erroneously applied within the expression.</li>
|
| 125 |
+
<li><strong>Formula Confusion Error (FC)</strong>: Error appears when applying formula in inappropriate scenario.</li>
|
| 126 |
+
<li><strong>Missing Step (MS)</strong>: Error entails an incomplete generation of reasoning process, lacking a necessary step.</li>
|
| 127 |
+
<li><strong>Contradictory Step (CS)</strong>: Error manifests inconsistency between preceding and subsequent reasoning steps.</li>
|
| 128 |
+
</ul>
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
<!-- start button -->
|
| 135 |
+
<button class="start" id="startBtn">Next</button>
|
| 136 |
+
|
| 137 |
+
<script>
|
| 138 |
+
document.getElementById('startBtn').addEventListener('click', ()=>{
|
| 139 |
+
if(window.parent && typeof window.parent.setUserName==='function'){
|
| 140 |
+
window.location.href = 'warning.html';
|
| 141 |
+
}else{
|
| 142 |
+
alert('Parent interface not ready. Please reload.');
|
| 143 |
+
}
|
| 144 |
+
});
|
| 145 |
+
</script>
|
| 146 |
+
</body>
|
| 147 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/.DS_Store
ADDED
|
Binary file (10.2 kB). View file
|
|
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_1.html
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 196 |
+
.var6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
<span id="fact1" class="fact1-color">Jackson's mom promises $5 per hour spent on chores.</span>
|
| 232 |
+
<span id="fact2" class="fact2-color">Jackson spends 2 hours vacuuming, and decides to do this twice.</span>
|
| 233 |
+
<span id="fact3" class="fact3-color">He also spends 0.5 hours washing dishes.</span>
|
| 234 |
+
<span id="fact4" class="fact4-color">He spends three times as long cleaning the bathroom as washing dishes.</span>
|
| 235 |
+
</p>
|
| 236 |
+
</div>
|
| 237 |
+
<div class="problem-understanding">
|
| 238 |
+
<div class="section-title">Problem Summary</div>
|
| 239 |
+
<ul>
|
| 240 |
+
<li><span class="fact1-color">Rate per hour: $5</span></li>
|
| 241 |
+
<li><span class="fact2-color">Hours vacuuming (each time): 2</span></li>
|
| 242 |
+
<li><span class="fact2-color">Number of times vacuuming: 2</span></li>
|
| 243 |
+
<li><span class="fact3-color">Hours washing dishes: 0.5</span></li>
|
| 244 |
+
<li><span class="fact4-color">Bathroom cleaning multiplier: 3</span></li>
|
| 245 |
+
</ul>
|
| 246 |
+
<div class="what-to-find">
|
| 247 |
+
<h4>What we need to find:</h4>
|
| 248 |
+
<p>We need to calculate the total amount of money Jackson earned from all chores.</p>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="right-panel">
|
| 253 |
+
<div class="debugger-controls">
|
| 254 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 255 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 256 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 257 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="python-solution">
|
| 260 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 261 |
+
<div class="python-code" id="python-code">
|
| 262 |
+
<div class="code-line" data-step="1">
|
| 263 |
+
<span class="line-number">1</span>
|
| 264 |
+
<span class="comment"># Calculate total hours spent vacuuming</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="1">
|
| 267 |
+
<span class="line-number">2</span>
|
| 268 |
+
<span><span class="var1-color">hours_vacuuming</span> = <span class="fact2-color">2</span> * <span class="fact2-color">2</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="2">
|
| 271 |
+
<span class="line-number">3</span>
|
| 272 |
+
<span class="comment"># Calculate money earned from vacuuming</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="2">
|
| 275 |
+
<span class="line-number">4</span>
|
| 276 |
+
<span><span class="var2-color">vacuuming_money</span> = <span class="var1-color">hours_vacuuming</span> * <span class="fact1-color">5</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="3">
|
| 279 |
+
<span class="line-number">5</span>
|
| 280 |
+
<span class="comment"># Calculate money earned from washing dishes</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="3">
|
| 283 |
+
<span class="line-number">6</span>
|
| 284 |
+
<span><span class="var3-color">dishes_money</span> = <span class="fact3-color">0.5</span> * <span class="fact1-color">5</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="4">
|
| 287 |
+
<span class="line-number">7</span>
|
| 288 |
+
<span class="comment"># Calculate time spent cleaning the bathroom</span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="4">
|
| 291 |
+
<span class="line-number">8</span>
|
| 292 |
+
<span><span class="var4-color">bathroom_time</span> = <span class="fact3-color">0.5</span> * <span class="fact4-color">3</span></span>
|
| 293 |
+
</div>
|
| 294 |
+
<div class="code-line" data-step="5">
|
| 295 |
+
<span class="line-number">9</span>
|
| 296 |
+
<span class="comment"># Calculate money earned from cleaning the bathroom</span>
|
| 297 |
+
</div>
|
| 298 |
+
<div class="code-line" data-step="5">
|
| 299 |
+
<span class="line-number">10</span>
|
| 300 |
+
<span><span class="var5-color">bathroom_money</span> = <span class="var4-color">bathroom_time</span> * <span class="fact1-color">5</span></span>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="code-line" data-step="6">
|
| 303 |
+
<span class="line-number">11</span>
|
| 304 |
+
<span class="comment"># Calculate total money earned from all chores</span>
|
| 305 |
+
</div>
|
| 306 |
+
<div class="code-line" data-step="6">
|
| 307 |
+
<span class="line-number">12</span>
|
| 308 |
+
<span><span class="var6-color">total_money</span> = <span class="var2-color">vacuuming_money</span> + <span class="var3-color">dishes_money</span> + <span class="var5-color">bathroom_money</span></span>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
<div class="variables-display" id="variables-display">
|
| 313 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 314 |
+
<div id="variables-list">
|
| 315 |
+
<div class="variable-item">
|
| 316 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 317 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 318 |
+
</div>
|
| 319 |
+
</div>
|
| 320 |
+
</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
|
| 324 |
+
<script>
|
| 325 |
+
class PythonDebugger {
|
| 326 |
+
constructor() {
|
| 327 |
+
this.currentStep = -1;
|
| 328 |
+
this.isPlaying = false;
|
| 329 |
+
this.playInterval = null;
|
| 330 |
+
this.totalSteps = 6;
|
| 331 |
+
this.variables = {};
|
| 332 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 333 |
+
|
| 334 |
+
this.initializeElements();
|
| 335 |
+
this.bindEvents();
|
| 336 |
+
this.updateUI();
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
initializeElements() {
|
| 340 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 341 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 342 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 343 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 344 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 345 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
bindEvents() {
|
| 349 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 350 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 351 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 352 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
togglePlay() {
|
| 356 |
+
if (this.isPlaying) {
|
| 357 |
+
this.pause();
|
| 358 |
+
} else {
|
| 359 |
+
this.play();
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
play() {
|
| 364 |
+
this.isPlaying = true;
|
| 365 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 366 |
+
|
| 367 |
+
if (this.currentStep >= this.totalSteps) {
|
| 368 |
+
this.currentStep = -1;
|
| 369 |
+
this.variables = {};
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
this.playInterval = setInterval(() => {
|
| 373 |
+
if (this.currentStep < this.totalSteps) {
|
| 374 |
+
this.nextStep();
|
| 375 |
+
} else {
|
| 376 |
+
this.pause();
|
| 377 |
+
}
|
| 378 |
+
}, 1500);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
pause() {
|
| 382 |
+
this.isPlaying = false;
|
| 383 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 384 |
+
if (this.playInterval) {
|
| 385 |
+
clearInterval(this.playInterval);
|
| 386 |
+
this.playInterval = null;
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
stop() {
|
| 391 |
+
this.pause();
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
nextStep() {
|
| 398 |
+
if (this.currentStep < this.totalSteps) {
|
| 399 |
+
this.currentStep++;
|
| 400 |
+
this.executeStep(this.currentStep);
|
| 401 |
+
this.updateUI();
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
previousStep() {
|
| 406 |
+
if (this.currentStep > 0) {
|
| 407 |
+
this.currentStep--;
|
| 408 |
+
this.recalculateVariables();
|
| 409 |
+
this.updateUI();
|
| 410 |
+
} else if (this.currentStep === 0) {
|
| 411 |
+
this.currentStep = -1;
|
| 412 |
+
this.variables = {};
|
| 413 |
+
this.updateUI();
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
executeStep(step) {
|
| 418 |
+
switch(step) {
|
| 419 |
+
case 1:
|
| 420 |
+
this.variables.hours_vacuuming = 2 * 2;
|
| 421 |
+
break;
|
| 422 |
+
case 2:
|
| 423 |
+
this.variables.vacuuming_money = this.variables.hours_vacuuming * 5;
|
| 424 |
+
break;
|
| 425 |
+
case 3:
|
| 426 |
+
this.variables.dishes_money = 0.5 * 5;
|
| 427 |
+
break;
|
| 428 |
+
case 4:
|
| 429 |
+
// This is the wrong step
|
| 430 |
+
this.variables.bathroom_time = 0.5 * 3;
|
| 431 |
+
break;
|
| 432 |
+
case 5:
|
| 433 |
+
this.variables.bathroom_money = this.variables.bathroom_time * 5;
|
| 434 |
+
break;
|
| 435 |
+
case 6:
|
| 436 |
+
this.variables.total_money = this.variables.vacuuming_money + this.variables.dishes_money + this.variables.bathroom_money;
|
| 437 |
+
break;
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
recalculateVariables() {
|
| 442 |
+
const oldVariables = {...this.variables};
|
| 443 |
+
this.variables = {};
|
| 444 |
+
for (let i = 1; i <= this.currentStep; i++) {
|
| 445 |
+
this.executeStep(i);
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
updateUI() {
|
| 450 |
+
// Update code highlighting
|
| 451 |
+
this.codeLines.forEach(line => {
|
| 452 |
+
line.classList.remove('current');
|
| 453 |
+
});
|
| 454 |
+
|
| 455 |
+
if (this.currentStep >= 0) {
|
| 456 |
+
const currentLines = document.querySelectorAll(`.code-line[data-step="${this.currentStep}"]`);
|
| 457 |
+
currentLines.forEach(line => {
|
| 458 |
+
line.classList.add('current');
|
| 459 |
+
});
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
// Update button states
|
| 463 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 464 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep === this.totalSteps);
|
| 465 |
+
|
| 466 |
+
// Update variables display
|
| 467 |
+
this.updateVariablesDisplay();
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
updateVariablesDisplay() {
|
| 471 |
+
if (Object.keys(this.variables).length === 0) {
|
| 472 |
+
this.variablesDisplay.innerHTML = `
|
| 473 |
+
<div class="variable-item">
|
| 474 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 475 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 476 |
+
</div>
|
| 477 |
+
`;
|
| 478 |
+
return;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
let html = '';
|
| 482 |
+
const variableOrder = ['hours_vacuuming', 'vacuuming_money', 'dishes_money', 'bathroom_time', 'bathroom_money', 'total_money'];
|
| 483 |
+
|
| 484 |
+
variableOrder.forEach(varName => {
|
| 485 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 486 |
+
const value = this.variables[varName];
|
| 487 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 488 |
+
const displayValue = varName.includes('money') ? `$${value}` : value;
|
| 489 |
+
|
| 490 |
+
let itemClass = "variable-item " + colorClass;
|
| 491 |
+
if (this.currentStep === this.wrongStep && varName === 'bathroom_time') {
|
| 492 |
+
itemClass += " error-highlight";
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 496 |
+
if(varName === lastVarName){
|
| 497 |
+
varName = varName + " (Final Answer)";
|
| 498 |
+
html += `<div class="variable-item ${colorClass}">
|
| 499 |
+
<span class="variable-name">${varName}</span>
|
| 500 |
+
<span class="variable-value">${value}</span>
|
| 501 |
+
</div>`;
|
| 502 |
+
} else {
|
| 503 |
+
html += `<div class="variable-item ${colorClass}">
|
| 504 |
+
<span class="variable-name">${varName}</span>
|
| 505 |
+
<span class="variable-value">${value}</span>
|
| 506 |
+
</div>`;
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
});
|
| 510 |
+
|
| 511 |
+
this.variablesDisplay.innerHTML = html;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
getVariableColorClass(varName) {
|
| 515 |
+
const colorMap = {
|
| 516 |
+
'hours_vacuuming': 'var1-color',
|
| 517 |
+
'vacuuming_money': 'var2-color',
|
| 518 |
+
'dishes_money': 'var3-color',
|
| 519 |
+
'bathroom_time': 'var4-color',
|
| 520 |
+
'bathroom_money': 'var5-color',
|
| 521 |
+
'total_money': 'var6-color'
|
| 522 |
+
};
|
| 523 |
+
return colorMap[varName] || '';
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// Initialize the debugger when the page loads
|
| 528 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 529 |
+
new PythonDebugger();
|
| 530 |
+
});
|
| 531 |
+
</script>
|
| 532 |
+
</body>
|
| 533 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_10.html
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 196 |
+
|
| 197 |
+
ul {
|
| 198 |
+
padding-left: 20px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
li {
|
| 202 |
+
margin-bottom: 12px;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.what-to-find {
|
| 206 |
+
margin-top: 20px;
|
| 207 |
+
padding: 15px;
|
| 208 |
+
background-color: #e8f4fd;
|
| 209 |
+
border-radius: 6px;
|
| 210 |
+
border-left: 4px solid #3498db;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.what-to-find h4 {
|
| 214 |
+
color: #2c3e50;
|
| 215 |
+
margin-bottom: 8px;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.wrong-step {
|
| 219 |
+
display: none;
|
| 220 |
+
}
|
| 221 |
+
</style>
|
| 222 |
+
</head>
|
| 223 |
+
<body>
|
| 224 |
+
<div class="wrong-step">0</div>
|
| 225 |
+
<div class="container">
|
| 226 |
+
<div class="left-panel">
|
| 227 |
+
<div class="problem-statement">
|
| 228 |
+
<div class="section-title">Problem Statement</div>
|
| 229 |
+
<p>
|
| 230 |
+
<span id="fact1" class="fact1-color">Two stores sell the same model of smartphone, but they offer it at different prices and with different discounts. Store A lists the smartphone at a full price of $125</span> and <span id="fact2" class="fact2-color">offers an additional discount of 8%</span>. <span id="fact3" class="fact3-color">Store B lists the same smartphone for $130</span> and <span id="fact4" class="fact4-color">offers an additional discount of 10%</span>. After both stores' discounts are applied, how much cheaper is store A's smartphone than store B's smartphone?
|
| 231 |
+
</p>
|
| 232 |
+
</div>
|
| 233 |
+
<div class="problem-understanding">
|
| 234 |
+
<div class="section-title">Problem Summary</div>
|
| 235 |
+
<ul>
|
| 236 |
+
<li><span class="fact1-color">Store A full price: $125</span></li>
|
| 237 |
+
<li><span class="fact2-color">Store A discount: 8%</span></li>
|
| 238 |
+
<li><span class="fact3-color">Store B full price: $130</span></li>
|
| 239 |
+
<li><span class="fact4-color">Store B discount: 10%</span></li>
|
| 240 |
+
</ul>
|
| 241 |
+
<div class="what-to-find">
|
| 242 |
+
<h4>What we need to find:</h4>
|
| 243 |
+
<p>Calculate how much cheaper Store A's smartphone is than Store B's smartphone after discounts are applied.</p>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="right-panel">
|
| 248 |
+
<div class="debugger-controls">
|
| 249 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 250 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 251 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 252 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="python-solution">
|
| 255 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 256 |
+
<div class="python-code" id="python-code">
|
| 257 |
+
<div class="code-line" data-step="0">
|
| 258 |
+
<span class="line-number">1</span>
|
| 259 |
+
<span class="comment"># Calculate the discount amount for Store A</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="1">
|
| 262 |
+
<span class="line-number">2</span>
|
| 263 |
+
<span><span class="var1-color">store_A_discount</span> = <span class="fact1-color">125</span> * <span class="fact2-color">8</span> / 100</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="2">
|
| 266 |
+
<span class="line-number">3</span>
|
| 267 |
+
<span class="comment"># Calculate the final price at Store A</span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="3">
|
| 270 |
+
<span class="line-number">4</span>
|
| 271 |
+
<span><span class="var2-color">store_A_price</span> = <span class="fact1-color">125</span> - <span class="var1-color">store_A_discount</span></span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="4">
|
| 274 |
+
<span class="line-number">5</span>
|
| 275 |
+
<span class="comment"># Calculate the discount amount for Store B</span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="5">
|
| 278 |
+
<span class="line-number">6</span>
|
| 279 |
+
<span><span class="var3-color">store_B_discount</span> = <span class="fact3-color">130</span> * <span class="fact4-color">10</span> / 100</span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="6">
|
| 282 |
+
<span class="line-number">7</span>
|
| 283 |
+
<span class="comment"># Calculate the final price at Store B</span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="7">
|
| 286 |
+
<span class="line-number">8</span>
|
| 287 |
+
<span><span class="var4-color">store_B_price</span> = <span class="fact3-color">130</span> - <span class="var3-color">store_B_discount</span></span>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="code-line" data-step="8">
|
| 290 |
+
<span class="line-number">9</span>
|
| 291 |
+
<span class="comment"># Calculate the price difference between Store A and Store B</span>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="code-line" data-step="9">
|
| 294 |
+
<span class="line-number">10</span>
|
| 295 |
+
<span><span class="var5-color">price_difference</span> = <span class="var4-color">store_B_price</span> - <span class="var2-color">store_A_price</span></span>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="variables-display" id="variables-display">
|
| 300 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 301 |
+
<div id="variables-list">
|
| 302 |
+
<div class="variable-item">
|
| 303 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 304 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
|
| 311 |
+
<script>
|
| 312 |
+
class PythonDebugger {
|
| 313 |
+
constructor() {
|
| 314 |
+
this.currentStep = -1;
|
| 315 |
+
this.isPlaying = false;
|
| 316 |
+
this.playInterval = null;
|
| 317 |
+
this.totalSteps = 9;
|
| 318 |
+
this.variables = {};
|
| 319 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 320 |
+
|
| 321 |
+
this.initializeElements();
|
| 322 |
+
this.bindEvents();
|
| 323 |
+
this.updateUI();
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
initializeElements() {
|
| 327 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 328 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 329 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 330 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 331 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 332 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
bindEvents() {
|
| 336 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 337 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 338 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 339 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
togglePlay() {
|
| 343 |
+
if (this.isPlaying) {
|
| 344 |
+
this.pause();
|
| 345 |
+
} else {
|
| 346 |
+
this.play();
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
play() {
|
| 351 |
+
this.isPlaying = true;
|
| 352 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 353 |
+
|
| 354 |
+
if (this.currentStep >= this.totalSteps) {
|
| 355 |
+
this.currentStep = -1;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
this.playInterval = setInterval(() => {
|
| 359 |
+
if (this.currentStep < this.totalSteps) {
|
| 360 |
+
this.nextStep();
|
| 361 |
+
} else {
|
| 362 |
+
this.pause();
|
| 363 |
+
}
|
| 364 |
+
}, 1500);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
pause() {
|
| 368 |
+
this.isPlaying = false;
|
| 369 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 370 |
+
if (this.playInterval) {
|
| 371 |
+
clearInterval(this.playInterval);
|
| 372 |
+
this.playInterval = null;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
stop() {
|
| 377 |
+
this.pause();
|
| 378 |
+
this.currentStep = -1;
|
| 379 |
+
this.variables = {};
|
| 380 |
+
this.updateUI();
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
nextStep() {
|
| 384 |
+
if (this.currentStep < this.totalSteps) {
|
| 385 |
+
this.currentStep++;
|
| 386 |
+
this.executeStep(this.currentStep);
|
| 387 |
+
this.updateUI();
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
previousStep() {
|
| 392 |
+
if (this.currentStep > 0) {
|
| 393 |
+
this.currentStep--;
|
| 394 |
+
this.recalculateVariables();
|
| 395 |
+
this.updateUI();
|
| 396 |
+
} else if (this.currentStep === 0) {
|
| 397 |
+
this.currentStep = -1;
|
| 398 |
+
this.variables = {};
|
| 399 |
+
this.updateUI();
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
executeStep(step) {
|
| 404 |
+
switch(step) {
|
| 405 |
+
case 1:
|
| 406 |
+
this.variables.store_A_discount = 125 * 8 / 100;
|
| 407 |
+
break;
|
| 408 |
+
case 3:
|
| 409 |
+
this.variables.store_A_price = 125 - this.variables.store_A_discount;
|
| 410 |
+
break;
|
| 411 |
+
case 5:
|
| 412 |
+
this.variables.store_B_discount = 130 * 10 / 100;
|
| 413 |
+
break;
|
| 414 |
+
case 7:
|
| 415 |
+
// This is the wrong step (step 4 in the unformatted info)
|
| 416 |
+
if (step === this.wrongStep) {
|
| 417 |
+
this.variables.store_B_price = 130 - this.variables.store_B_discount;
|
| 418 |
+
} else {
|
| 419 |
+
this.variables.store_B_price = 130 - this.variables.store_B_discount;
|
| 420 |
+
}
|
| 421 |
+
break;
|
| 422 |
+
case 9:
|
| 423 |
+
this.variables.price_difference = this.variables.store_B_price - this.variables.store_A_price;
|
| 424 |
+
break;
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
recalculateVariables() {
|
| 429 |
+
this.variables = {};
|
| 430 |
+
for (let i = 1; i <= this.currentStep; i += 2) {
|
| 431 |
+
this.executeStep(i);
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
updateUI() {
|
| 436 |
+
// Update code highlighting
|
| 437 |
+
this.codeLines.forEach((line, index) => {
|
| 438 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 439 |
+
});
|
| 440 |
+
|
| 441 |
+
// Update button states
|
| 442 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 443 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep === this.totalSteps);
|
| 444 |
+
|
| 445 |
+
// Update variables display
|
| 446 |
+
this.updateVariablesDisplay();
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
updateVariablesDisplay() {
|
| 450 |
+
if (Object.keys(this.variables).length === 0) {
|
| 451 |
+
this.variablesDisplay.innerHTML = `
|
| 452 |
+
<div class="variable-item">
|
| 453 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 454 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 455 |
+
</div>
|
| 456 |
+
`;
|
| 457 |
+
return;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
let html = '';
|
| 461 |
+
const variableOrder = ['store_A_discount', 'store_A_price', 'store_B_discount', 'store_B_price', 'price_difference'];
|
| 462 |
+
|
| 463 |
+
variableOrder.forEach(varName => {
|
| 464 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 465 |
+
const value = this.variables[varName];
|
| 466 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 467 |
+
const formattedValue = varName.includes('price') || varName.includes('discount') ?
|
| 468 |
+
`$${value.toFixed(2)}` : value.toFixed(2);
|
| 469 |
+
|
| 470 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 471 |
+
if(varName === lastVarName){
|
| 472 |
+
varName = varName + " (Final Answer)";
|
| 473 |
+
html += `<div class="variable-item ${colorClass}">
|
| 474 |
+
<span class="variable-name">${varName}</span>
|
| 475 |
+
<span class="variable-value">${value}</span>
|
| 476 |
+
</div>`;
|
| 477 |
+
} else {
|
| 478 |
+
html += `<div class="variable-item ${colorClass}">
|
| 479 |
+
<span class="variable-name">${varName}</span>
|
| 480 |
+
<span class="variable-value">${value}</span>
|
| 481 |
+
</div>`;
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
});
|
| 485 |
+
|
| 486 |
+
this.variablesDisplay.innerHTML = html;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
getVariableColorClass(varName) {
|
| 490 |
+
const colorMap = {
|
| 491 |
+
'store_A_discount': 'var1-color',
|
| 492 |
+
'store_A_price': 'var2-color',
|
| 493 |
+
'store_B_discount': 'var3-color',
|
| 494 |
+
'store_B_price': 'var4-color',
|
| 495 |
+
'price_difference': 'var5-color'
|
| 496 |
+
};
|
| 497 |
+
return colorMap[varName] || '';
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
// Initialize the debugger when the page loads
|
| 502 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 503 |
+
new PythonDebugger();
|
| 504 |
+
});
|
| 505 |
+
</script>
|
| 506 |
+
</body>
|
| 507 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_11.html
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 193 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 194 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 196 |
+
.var5-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
A school is buying virus protection software to cover <span id="fact1" class="fact1-color">50 devices</span>. One software package costs <span id="fact2" class="fact2-color">$40</span> and covers up to <span id="fact3" class="fact3-color">5 devices</span>. The other software package costs <span id="fact4" class="fact4-color">$60</span> and covers up to <span id="fact5" class="fact5-color">10 devices</span>. How much money, in dollars, can the school save by buying the $60 software package instead of the $40 software package?
|
| 232 |
+
</p>
|
| 233 |
+
</div>
|
| 234 |
+
<div class="problem-understanding">
|
| 235 |
+
<div class="section-title">Problem Summary</div>
|
| 236 |
+
<ul>
|
| 237 |
+
<li><span class="fact1-color">Total devices: 50</span></li>
|
| 238 |
+
<li><span class="fact2-color">Cost of first package: $40</span></li>
|
| 239 |
+
<li><span class="fact3-color">Devices covered by first package: 5</span></li>
|
| 240 |
+
<li><span class="fact4-color">Cost of second package: $60</span></li>
|
| 241 |
+
<li><span class="fact5-color">Devices covered by second package: 10</span></li>
|
| 242 |
+
</ul>
|
| 243 |
+
<div class="what-to-find">
|
| 244 |
+
<h4>What we need to find:</h4>
|
| 245 |
+
<p>How much money, in dollars, can the school save by buying the $60 software package instead of the $40 software package.</p>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
</div>
|
| 249 |
+
<div class="right-panel">
|
| 250 |
+
<div class="debugger-controls">
|
| 251 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 252 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 253 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 254 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="python-solution">
|
| 257 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 258 |
+
<div class="python-code" id="python-code">
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">1</span>
|
| 261 |
+
<span class="comment"># Calculate how many sets of 5 devices are in the school</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">2</span>
|
| 265 |
+
<span><span class="var1-color">sets_of_5_devices</span> = <span class="fact1-color">50</span> / <span class="fact3-color">5</span></span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">3</span>
|
| 269 |
+
<span class="comment"># Calculate total cost for the $40 software package</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">4</span>
|
| 273 |
+
<span><span class="var2-color">cost_of_first_option</span> = <span class="fact2-color">40</span> * <span class="var1-color">sets_of_5_devices</span></span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">5</span>
|
| 277 |
+
<span class="comment"># Calculate how many sets of 10 devices are in the school</span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="6">
|
| 280 |
+
<span class="line-number">6</span>
|
| 281 |
+
<span><span class="var3-color">sets_of_10_devices</span> = <span class="fact1-color">50</span> / <span class="fact5-color">10</span></span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="7">
|
| 284 |
+
<span class="line-number">7</span>
|
| 285 |
+
<span class="comment"># Calculate total cost for the $60 software package</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="8">
|
| 288 |
+
<span class="line-number">8</span>
|
| 289 |
+
<span><span class="var4-color">cost_of_second_option</span> = <span class="fact4-color">60</span> * <span class="var3-color">sets_of_10_devices</span></span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="9">
|
| 292 |
+
<span class="line-number">9</span>
|
| 293 |
+
<span class="comment"># Calculate the savings</span>
|
| 294 |
+
</div>
|
| 295 |
+
<div class="code-line" data-step="10">
|
| 296 |
+
<span class="line-number">10</span>
|
| 297 |
+
<span><span class="var5-color">savings</span> = <span class="var2-color">cost_of_first_option</span> - <span class="var4-color">cost_of_second_option</span></span>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
<div class="variables-display" id="variables-display">
|
| 302 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 303 |
+
<div id="variables-list">
|
| 304 |
+
<div class="variable-item">
|
| 305 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 306 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
|
| 313 |
+
<script>
|
| 314 |
+
class PythonDebugger {
|
| 315 |
+
constructor() {
|
| 316 |
+
this.currentStep = -1;
|
| 317 |
+
this.isPlaying = false;
|
| 318 |
+
this.playInterval = null;
|
| 319 |
+
this.totalSteps = 10;
|
| 320 |
+
this.variables = {};
|
| 321 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 322 |
+
|
| 323 |
+
this.initializeElements();
|
| 324 |
+
this.bindEvents();
|
| 325 |
+
this.updateUI();
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
initializeElements() {
|
| 329 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 330 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 331 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 332 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 333 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 334 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
bindEvents() {
|
| 338 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 339 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 340 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 341 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
togglePlay() {
|
| 345 |
+
if (this.isPlaying) {
|
| 346 |
+
this.pause();
|
| 347 |
+
} else {
|
| 348 |
+
this.play();
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
play() {
|
| 353 |
+
this.isPlaying = true;
|
| 354 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 355 |
+
|
| 356 |
+
if (this.currentStep >= this.totalSteps) {
|
| 357 |
+
this.currentStep = -1;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
this.playInterval = setInterval(() => {
|
| 361 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 362 |
+
if (nextStep !== null) {
|
| 363 |
+
this.currentStep = nextStep;
|
| 364 |
+
this.executeStep(this.currentStep);
|
| 365 |
+
this.updateUI();
|
| 366 |
+
} else {
|
| 367 |
+
this.pause();
|
| 368 |
+
}
|
| 369 |
+
}, 1500);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
pause() {
|
| 373 |
+
this.isPlaying = false;
|
| 374 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 375 |
+
if (this.playInterval) {
|
| 376 |
+
clearInterval(this.playInterval);
|
| 377 |
+
this.playInterval = null;
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
stop() {
|
| 382 |
+
this.pause();
|
| 383 |
+
this.currentStep = -1;
|
| 384 |
+
this.variables = {};
|
| 385 |
+
this.updateUI();
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
nextStep() {
|
| 389 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 390 |
+
if (nextStep !== null) {
|
| 391 |
+
this.currentStep = nextStep;
|
| 392 |
+
this.executeStep(this.currentStep);
|
| 393 |
+
this.updateUI();
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
previousStep() {
|
| 398 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 399 |
+
if (prevStep !== null) {
|
| 400 |
+
this.currentStep = prevStep;
|
| 401 |
+
this.recalculateVariables();
|
| 402 |
+
this.updateUI();
|
| 403 |
+
} else if (this.currentStep !== -1) {
|
| 404 |
+
this.currentStep = -1;
|
| 405 |
+
this.variables = {};
|
| 406 |
+
this.updateUI();
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
executeStep(step) {
|
| 411 |
+
switch(step) {
|
| 412 |
+
case 2:
|
| 413 |
+
this.variables.sets_of_5_devices = 50 / 5;
|
| 414 |
+
break;
|
| 415 |
+
case 4:
|
| 416 |
+
this.variables.cost_of_first_option = 40 * this.variables.sets_of_5_devices;
|
| 417 |
+
break;
|
| 418 |
+
case 6:
|
| 419 |
+
this.variables.sets_of_10_devices = 50 / 10;
|
| 420 |
+
break;
|
| 421 |
+
case 8:
|
| 422 |
+
// This is the wrong step (step 4 in the unformatted information)
|
| 423 |
+
if (step === this.wrongStep * 2) {
|
| 424 |
+
// Intentionally introducing the error
|
| 425 |
+
this.variables.cost_of_second_option = 60 * 5;
|
| 426 |
+
} else {
|
| 427 |
+
this.variables.cost_of_second_option = 60 * this.variables.sets_of_10_devices;
|
| 428 |
+
}
|
| 429 |
+
break;
|
| 430 |
+
case 10:
|
| 431 |
+
this.variables.savings = this.variables.cost_of_first_option - this.variables.cost_of_second_option;
|
| 432 |
+
break;
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
getExecutableSteps() {
|
| 437 |
+
// Returns only the steps that execute actual code (not comments)
|
| 438 |
+
return [2, 4, 6, 8, 10];
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
getNextExecutableStep(currentStep) {
|
| 442 |
+
const executableSteps = this.getExecutableSteps();
|
| 443 |
+
if (currentStep === -1) return executableSteps[0];
|
| 444 |
+
|
| 445 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 446 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
getPreviousExecutableStep(currentStep) {
|
| 450 |
+
const executableSteps = this.getExecutableSteps();
|
| 451 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 452 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
recalculateVariables() {
|
| 456 |
+
this.variables = {};
|
| 457 |
+
const executableSteps = this.getExecutableSteps();
|
| 458 |
+
for (let step of executableSteps) {
|
| 459 |
+
if (step <= this.currentStep) {
|
| 460 |
+
this.executeStep(step);
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
updateUI() {
|
| 466 |
+
// Update code highlighting
|
| 467 |
+
this.codeLines.forEach(line => {
|
| 468 |
+
const step = parseInt(line.getAttribute('data-step'));
|
| 469 |
+
line.classList.toggle('current', step === this.currentStep);
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
// Update button states
|
| 473 |
+
const executableSteps = this.getExecutableSteps();
|
| 474 |
+
const isFirstStep = this.currentStep === -1;
|
| 475 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 476 |
+
|
| 477 |
+
this.prevBtn.classList.toggle('disabled', isFirstStep);
|
| 478 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 479 |
+
|
| 480 |
+
// Update variables display
|
| 481 |
+
this.updateVariablesDisplay();
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
updateVariablesDisplay() {
|
| 485 |
+
if (Object.keys(this.variables).length === 0) {
|
| 486 |
+
this.variablesDisplay.innerHTML = `
|
| 487 |
+
<div class="variable-item">
|
| 488 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 489 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 490 |
+
</div>
|
| 491 |
+
`;
|
| 492 |
+
return;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
let html = '';
|
| 496 |
+
const variableOrder = ['sets_of_5_devices', 'cost_of_first_option', 'sets_of_10_devices', 'cost_of_second_option', 'savings'];
|
| 497 |
+
|
| 498 |
+
variableOrder.forEach(varName => {
|
| 499 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 500 |
+
const value = this.variables[varName];
|
| 501 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 502 |
+
const displayValue = varName.includes('cost') || varName === 'savings' ? `$${value}` : value;
|
| 503 |
+
|
| 504 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 505 |
+
if(varName === lastVarName){
|
| 506 |
+
varName = varName + " (Final Answer)";
|
| 507 |
+
html += `<div class="variable-item ${colorClass}">
|
| 508 |
+
<span class="variable-name">${varName}</span>
|
| 509 |
+
<span class="variable-value">${value}</span>
|
| 510 |
+
</div>`;
|
| 511 |
+
} else {
|
| 512 |
+
html += `<div class="variable-item ${colorClass}">
|
| 513 |
+
<span class="variable-name">${varName}</span>
|
| 514 |
+
<span class="variable-value">${value}</span>
|
| 515 |
+
</div>`;
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
});
|
| 519 |
+
|
| 520 |
+
this.variablesDisplay.innerHTML = html;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
getVariableColorClass(varName) {
|
| 524 |
+
const colorMap = {
|
| 525 |
+
'sets_of_5_devices': 'var1-color',
|
| 526 |
+
'cost_of_first_option': 'var2-color',
|
| 527 |
+
'sets_of_10_devices': 'var3-color',
|
| 528 |
+
'cost_of_second_option': 'var4-color',
|
| 529 |
+
'savings': 'var5-color'
|
| 530 |
+
};
|
| 531 |
+
return colorMap[varName] || '';
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// Initialize the debugger when the page loads
|
| 536 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 537 |
+
new PythonDebugger();
|
| 538 |
+
});
|
| 539 |
+
</script>
|
| 540 |
+
</body>
|
| 541 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_12.html
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 189 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 190 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 191 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 192 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 193 |
+
.var6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
Robin wants to buy jelly bracelets for her friends. She decides to buy one bracelet for each letter of the first name of her friends. Her friends are Jessica, Tori, Lily and Patrice. If each jelly bracelet costs <span id="fact1" class="fact1-color">$2</span>, what is the total she will spend in dollars?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Cost per jelly bracelet: $2</span></li>
|
| 235 |
+
</ul>
|
| 236 |
+
<div class="what-to-find">
|
| 237 |
+
<h4>What we need to find:</h4>
|
| 238 |
+
<p>The total amount Robin will spend on jelly bracelets for her friends.</p>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
<div class="right-panel">
|
| 243 |
+
<div class="debugger-controls">
|
| 244 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 245 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 246 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 247 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 248 |
+
</div>
|
| 249 |
+
<div class="python-solution">
|
| 250 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 251 |
+
<div class="python-code" id="python-code">
|
| 252 |
+
<div class="code-line" data-step="0">
|
| 253 |
+
<span class="line-number">1</span>
|
| 254 |
+
<span class="comment"># Count the number of letters in Jessica's name</span>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="code-line" data-step="1">
|
| 257 |
+
<span class="line-number">2</span>
|
| 258 |
+
<span><span class="var1-color">jessica_letters</span> = 7</span>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="code-line" data-step="2">
|
| 261 |
+
<span class="line-number">3</span>
|
| 262 |
+
<span class="comment"># Count the number of letters in Tori's name</span>
|
| 263 |
+
</div>
|
| 264 |
+
<div class="code-line" data-step="3">
|
| 265 |
+
<span class="line-number">4</span>
|
| 266 |
+
<span><span class="var2-color">tori_letters</span> = 4</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="code-line" data-step="4">
|
| 269 |
+
<span class="line-number">5</span>
|
| 270 |
+
<span class="comment"># Count the number of letters in Lily's name</span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="5">
|
| 273 |
+
<span class="line-number">6</span>
|
| 274 |
+
<span><span class="var3-color">lily_letters</span> = 4</span>
|
| 275 |
+
</div>
|
| 276 |
+
<div class="code-line" data-step="6">
|
| 277 |
+
<span class="line-number">7</span>
|
| 278 |
+
<span class="comment"># Count the number of letters in Patrice's name</span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="code-line" data-step="7">
|
| 281 |
+
<span class="line-number">8</span>
|
| 282 |
+
<span><span class="var4-color">patrice_letters</span> = 7</span>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="code-line" data-step="8">
|
| 285 |
+
<span class="line-number">9</span>
|
| 286 |
+
<span class="comment"># Calculate the total number of bracelets needed</span>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="code-line" data-step="9">
|
| 289 |
+
<span class="line-number">10</span>
|
| 290 |
+
<span><span class="var5-color">total_bracelets</span> = <span class="var1-color">jessica_letters</span> + <span class="var2-color">tori_letters</span> + <span class="var3-color">lily_letters</span> + <span class="var4-color">patrice_letters</span></span>
|
| 291 |
+
</div>
|
| 292 |
+
<div class="code-line" data-step="10">
|
| 293 |
+
<span class="line-number">11</span>
|
| 294 |
+
<span class="comment"># Calculate the total cost</span>
|
| 295 |
+
</div>
|
| 296 |
+
<div class="code-line" data-step="11">
|
| 297 |
+
<span class="line-number">12</span>
|
| 298 |
+
<span><span class="var6-color">total_cost</span> = <span class="var5-color">total_bracelets</span> * <span class="fact1-color">2</span></span>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="variables-display" id="variables-display">
|
| 303 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 304 |
+
<div id="variables-list">
|
| 305 |
+
<div class="variable-item">
|
| 306 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 307 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
|
| 314 |
+
<script>
|
| 315 |
+
class PythonDebugger {
|
| 316 |
+
constructor() {
|
| 317 |
+
this.currentStep = -1;
|
| 318 |
+
this.isPlaying = false;
|
| 319 |
+
this.playInterval = null;
|
| 320 |
+
this.totalSteps = 11;
|
| 321 |
+
this.variables = {};
|
| 322 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 323 |
+
|
| 324 |
+
this.initializeElements();
|
| 325 |
+
this.bindEvents();
|
| 326 |
+
this.updateUI();
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
initializeElements() {
|
| 330 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 331 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 332 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 333 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 334 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 335 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
bindEvents() {
|
| 339 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 340 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 341 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 342 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
togglePlay() {
|
| 346 |
+
if (this.isPlaying) {
|
| 347 |
+
this.pause();
|
| 348 |
+
} else {
|
| 349 |
+
this.play();
|
| 350 |
+
}
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
play() {
|
| 354 |
+
this.isPlaying = true;
|
| 355 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 356 |
+
|
| 357 |
+
if (this.currentStep >= this.totalSteps) {
|
| 358 |
+
this.currentStep = -1;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
this.playInterval = setInterval(() => {
|
| 362 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 363 |
+
if (nextStep !== null) {
|
| 364 |
+
this.currentStep = nextStep;
|
| 365 |
+
this.executeStep(this.currentStep);
|
| 366 |
+
this.updateUI();
|
| 367 |
+
} else {
|
| 368 |
+
this.pause();
|
| 369 |
+
}
|
| 370 |
+
}, 1500);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
pause() {
|
| 374 |
+
this.isPlaying = false;
|
| 375 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 376 |
+
if (this.playInterval) {
|
| 377 |
+
clearInterval(this.playInterval);
|
| 378 |
+
this.playInterval = null;
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
stop() {
|
| 383 |
+
this.pause();
|
| 384 |
+
this.currentStep = -1;
|
| 385 |
+
this.variables = {};
|
| 386 |
+
this.updateUI();
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
nextStep() {
|
| 390 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 391 |
+
if (nextStep !== null) {
|
| 392 |
+
this.currentStep = nextStep;
|
| 393 |
+
this.executeStep(this.currentStep);
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
previousStep() {
|
| 399 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 400 |
+
if (prevStep !== null) {
|
| 401 |
+
this.currentStep = prevStep;
|
| 402 |
+
this.recalculateVariables();
|
| 403 |
+
this.updateUI();
|
| 404 |
+
} else if (this.currentStep !== -1) {
|
| 405 |
+
this.currentStep = -1;
|
| 406 |
+
this.variables = {};
|
| 407 |
+
this.updateUI();
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
executeStep(step) {
|
| 412 |
+
switch(step) {
|
| 413 |
+
case 1:
|
| 414 |
+
this.variables.jessica_letters = 7;
|
| 415 |
+
break;
|
| 416 |
+
case 3:
|
| 417 |
+
this.variables.tori_letters = 4;
|
| 418 |
+
break;
|
| 419 |
+
case 5:
|
| 420 |
+
this.variables.lily_letters = 4;
|
| 421 |
+
break;
|
| 422 |
+
case 7:
|
| 423 |
+
this.variables.patrice_letters = 7;
|
| 424 |
+
break;
|
| 425 |
+
case 9:
|
| 426 |
+
this.variables.total_bracelets = this.variables.jessica_letters + this.variables.tori_letters + this.variables.lily_letters + this.variables.patrice_letters;
|
| 427 |
+
break;
|
| 428 |
+
case 11:
|
| 429 |
+
// Intentionally introducing the error from the wrongstep
|
| 430 |
+
if (step === this.wrongStep * 2 - 1) {
|
| 431 |
+
this.variables.total_cost = this.variables.total_bracelets * 2;
|
| 432 |
+
} else {
|
| 433 |
+
this.variables.total_cost = this.variables.total_bracelets * 2;
|
| 434 |
+
}
|
| 435 |
+
break;
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
getExecutableSteps() {
|
| 440 |
+
// Returns only the steps that execute actual code (not comments)
|
| 441 |
+
return [1, 3, 5, 7, 9, 11];
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
getNextExecutableStep(currentStep) {
|
| 445 |
+
const executableSteps = this.getExecutableSteps();
|
| 446 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 447 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
getPreviousExecutableStep(currentStep) {
|
| 451 |
+
const executableSteps = this.getExecutableSteps();
|
| 452 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 453 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
recalculateVariables() {
|
| 457 |
+
this.variables = {};
|
| 458 |
+
const executableSteps = this.getExecutableSteps();
|
| 459 |
+
for (let step of executableSteps) {
|
| 460 |
+
if (step <= this.currentStep) {
|
| 461 |
+
this.executeStep(step);
|
| 462 |
+
}
|
| 463 |
+
}
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
updateUI() {
|
| 467 |
+
// Update code highlighting
|
| 468 |
+
this.codeLines.forEach((line, index) => {
|
| 469 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
// Update button states
|
| 473 |
+
const executableSteps = this.getExecutableSteps();
|
| 474 |
+
const isFirstStep = this.currentStep === -1;
|
| 475 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 476 |
+
|
| 477 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 478 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 479 |
+
|
| 480 |
+
// Update variables display
|
| 481 |
+
this.updateVariablesDisplay();
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
updateVariablesDisplay() {
|
| 485 |
+
if (Object.keys(this.variables).length === 0) {
|
| 486 |
+
this.variablesDisplay.innerHTML = `
|
| 487 |
+
<div class="variable-item">
|
| 488 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 489 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 490 |
+
</div>
|
| 491 |
+
`;
|
| 492 |
+
return;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
let html = '';
|
| 496 |
+
const variableOrder = ['jessica_letters', 'tori_letters', 'lily_letters', 'patrice_letters', 'total_bracelets', 'total_cost'];
|
| 497 |
+
|
| 498 |
+
variableOrder.forEach(varName => {
|
| 499 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 500 |
+
const value = this.variables[varName];
|
| 501 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 502 |
+
const displayValue = varName === 'total_cost' ? `$${value}` : value;
|
| 503 |
+
|
| 504 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 505 |
+
if(varName === lastVarName){
|
| 506 |
+
varName = varName + " (Final Answer)";
|
| 507 |
+
html += `<div class="variable-item ${colorClass}">
|
| 508 |
+
<span class="variable-name">${varName}</span>
|
| 509 |
+
<span class="variable-value">${value}</span>
|
| 510 |
+
</div>`;
|
| 511 |
+
} else {
|
| 512 |
+
html += `<div class="variable-item ${colorClass}">
|
| 513 |
+
<span class="variable-name">${varName}</span>
|
| 514 |
+
<span class="variable-value">${value}</span>
|
| 515 |
+
</div>`;
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
});
|
| 519 |
+
|
| 520 |
+
this.variablesDisplay.innerHTML = html;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
getVariableColorClass(varName) {
|
| 524 |
+
const colorMap = {
|
| 525 |
+
'jessica_letters': 'var1-color',
|
| 526 |
+
'tori_letters': 'var2-color',
|
| 527 |
+
'lily_letters': 'var3-color',
|
| 528 |
+
'patrice_letters': 'var4-color',
|
| 529 |
+
'total_bracelets': 'var5-color',
|
| 530 |
+
'total_cost': 'var6-color'
|
| 531 |
+
};
|
| 532 |
+
return colorMap[varName] || '';
|
| 533 |
+
}
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
// Initialize the debugger when the page loads
|
| 537 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 538 |
+
new PythonDebugger();
|
| 539 |
+
});
|
| 540 |
+
</script>
|
| 541 |
+
</body>
|
| 542 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_13.html
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.wrong-step {
|
| 218 |
+
display: none;
|
| 219 |
+
}
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
<span id="fact1" class="fact1-color">Leo has to write a 400-word story for his literature class.</span> <span id="fact2" class="fact2-color">10 words fit on each line of his notebook</span> <span id="fact3" class="fact3-color">20 lines fit on each page.</span> <span id="fact4" class="fact4-color">Lucas has filled one and a half pages.</span> How many words does he have left to write?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Total words required: 400</span></li>
|
| 236 |
+
<li><span class="fact2-color">Words per line: 10</span></li>
|
| 237 |
+
<li><span class="fact3-color">Lines per page: 20</span></li>
|
| 238 |
+
<li><span class="fact4-color">Pages filled: 1.5</span></li>
|
| 239 |
+
</ul>
|
| 240 |
+
<div class="what-to-find">
|
| 241 |
+
<h4>What we need to find</h4>
|
| 242 |
+
<p>How many words Lucas has left to write.</p>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
<div class="right-panel">
|
| 247 |
+
<div class="debugger-controls">
|
| 248 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 249 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 250 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 251 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="python-solution">
|
| 254 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 255 |
+
<div class="python-code" id="python-code">
|
| 256 |
+
<div class="code-line" data-step="0">
|
| 257 |
+
<span class="line-number">1</span>
|
| 258 |
+
<span class="comment"># Calculate how many lines are in half a page</span>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="code-line" data-step="1">
|
| 261 |
+
<span class="line-number">2</span>
|
| 262 |
+
<span><span class="var1-color">lines_in_half_page</span> = <span class="fact3-color">20</span> / 2</span>
|
| 263 |
+
</div>
|
| 264 |
+
<div class="code-line" data-step="2">
|
| 265 |
+
<span class="line-number">3</span>
|
| 266 |
+
<span class="comment"># Calculate total lines written</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="code-line" data-step="3">
|
| 269 |
+
<span class="line-number">4</span>
|
| 270 |
+
<span><span class="var2-color">total_lines_written</span> = <span class="fact3-color">20</span> + <span class="var1-color">lines_in_half_page</span></span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="4">
|
| 273 |
+
<span class="line-number">5</span>
|
| 274 |
+
<span class="comment"># Calculate words written so far</span>
|
| 275 |
+
</div>
|
| 276 |
+
<div class="code-line" data-step="5">
|
| 277 |
+
<span class="line-number">6</span>
|
| 278 |
+
<span><span class="var3-color">words_written</span> = <span class="var2-color">total_lines_written</span> * <span class="fact2-color">10</span></span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="code-line" data-step="6">
|
| 281 |
+
<span class="line-number">7</span>
|
| 282 |
+
<span class="comment"># Calculate words left to write</span>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="code-line" data-step="7">
|
| 285 |
+
<span class="line-number">8</span>
|
| 286 |
+
<span><span class="var4-color">words_left</span> = <span class="fact1-color">400</span> - <span class="var3-color">words_written</span></span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="variables-display" id="variables-display">
|
| 291 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 292 |
+
<div id="variables-list">
|
| 293 |
+
<div class="variable-item">
|
| 294 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 295 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
|
| 302 |
+
<script>
|
| 303 |
+
class PythonDebugger {
|
| 304 |
+
constructor() {
|
| 305 |
+
this.currentStep = -1;
|
| 306 |
+
this.isPlaying = false;
|
| 307 |
+
this.playInterval = null;
|
| 308 |
+
this.totalSteps = 7;
|
| 309 |
+
this.variables = {};
|
| 310 |
+
|
| 311 |
+
this.initializeElements();
|
| 312 |
+
this.bindEvents();
|
| 313 |
+
this.updateUI();
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
initializeElements() {
|
| 317 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 318 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 319 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 320 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 321 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 322 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
bindEvents() {
|
| 326 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 327 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 328 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 329 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
togglePlay() {
|
| 333 |
+
if (this.isPlaying) {
|
| 334 |
+
this.pause();
|
| 335 |
+
} else {
|
| 336 |
+
this.play();
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
play() {
|
| 341 |
+
this.isPlaying = true;
|
| 342 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 343 |
+
|
| 344 |
+
if (this.currentStep >= this.totalSteps) {
|
| 345 |
+
this.currentStep = -1;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
this.playInterval = setInterval(() => {
|
| 349 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 350 |
+
if (nextStep !== null) {
|
| 351 |
+
this.currentStep = nextStep;
|
| 352 |
+
this.executeStep(this.currentStep);
|
| 353 |
+
this.updateUI();
|
| 354 |
+
} else {
|
| 355 |
+
this.pause();
|
| 356 |
+
}
|
| 357 |
+
}, 1500);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
pause() {
|
| 361 |
+
this.isPlaying = false;
|
| 362 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 363 |
+
if (this.playInterval) {
|
| 364 |
+
clearInterval(this.playInterval);
|
| 365 |
+
this.playInterval = null;
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
stop() {
|
| 370 |
+
this.pause();
|
| 371 |
+
this.currentStep = -1;
|
| 372 |
+
this.variables = {};
|
| 373 |
+
this.updateUI();
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
nextStep() {
|
| 377 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 378 |
+
if (nextStep !== null) {
|
| 379 |
+
this.currentStep = nextStep;
|
| 380 |
+
this.executeStep(this.currentStep);
|
| 381 |
+
this.updateUI();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
previousStep() {
|
| 386 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 387 |
+
if (prevStep !== null) {
|
| 388 |
+
this.currentStep = prevStep;
|
| 389 |
+
this.recalculateVariables();
|
| 390 |
+
this.updateUI();
|
| 391 |
+
} else if (this.currentStep !== -1) {
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
executeStep(step) {
|
| 399 |
+
switch(step) {
|
| 400 |
+
case 1:
|
| 401 |
+
this.variables.lines_in_half_page = 20 / 2;
|
| 402 |
+
break;
|
| 403 |
+
case 3:
|
| 404 |
+
this.variables.total_lines_written = 20 + this.variables.lines_in_half_page;
|
| 405 |
+
break;
|
| 406 |
+
case 5:
|
| 407 |
+
this.variables.words_written = this.variables.total_lines_written * 10;
|
| 408 |
+
break;
|
| 409 |
+
case 7:
|
| 410 |
+
this.variables.words_left = 400 - this.variables.words_written;
|
| 411 |
+
break;
|
| 412 |
+
}
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
getExecutableSteps() {
|
| 416 |
+
// Returns only the steps that execute actual code (not comments)
|
| 417 |
+
return [1, 3, 5, 7];
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
getNextExecutableStep(currentStep) {
|
| 421 |
+
const executableSteps = this.getExecutableSteps();
|
| 422 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 423 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
getPreviousExecutableStep(currentStep) {
|
| 427 |
+
const executableSteps = this.getExecutableSteps();
|
| 428 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 429 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
recalculateVariables() {
|
| 433 |
+
this.variables = {};
|
| 434 |
+
const executableSteps = this.getExecutableSteps();
|
| 435 |
+
for (let step of executableSteps) {
|
| 436 |
+
if (step <= this.currentStep) {
|
| 437 |
+
this.executeStep(step);
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
updateUI() {
|
| 443 |
+
// Update code highlighting
|
| 444 |
+
this.codeLines.forEach((line, index) => {
|
| 445 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
// Update button states
|
| 449 |
+
const executableSteps = this.getExecutableSteps();
|
| 450 |
+
const isFirstStep = this.currentStep === -1;
|
| 451 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 452 |
+
|
| 453 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 454 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 455 |
+
|
| 456 |
+
// Update variables display
|
| 457 |
+
this.updateVariablesDisplay();
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
updateVariablesDisplay() {
|
| 461 |
+
if (Object.keys(this.variables).length === 0) {
|
| 462 |
+
this.variablesDisplay.innerHTML = `
|
| 463 |
+
<div class="variable-item">
|
| 464 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 465 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 466 |
+
</div>
|
| 467 |
+
`;
|
| 468 |
+
return;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
let html = '';
|
| 472 |
+
const variableOrder = ['lines_in_half_page', 'total_lines_written', 'words_written', 'words_left'];
|
| 473 |
+
|
| 474 |
+
variableOrder.forEach(varName => {
|
| 475 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 476 |
+
const value = this.variables[varName];
|
| 477 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 478 |
+
|
| 479 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 480 |
+
if(varName === lastVarName){
|
| 481 |
+
varName = varName + " (Final Answer)";
|
| 482 |
+
html += `<div class="variable-item ${colorClass}">
|
| 483 |
+
<span class="variable-name">${varName}</span>
|
| 484 |
+
<span class="variable-value">${value}</span>
|
| 485 |
+
</div>`;
|
| 486 |
+
} else {
|
| 487 |
+
html += `<div class="variable-item ${colorClass}">
|
| 488 |
+
<span class="variable-name">${varName}</span>
|
| 489 |
+
<span class="variable-value">${value}</span>
|
| 490 |
+
</div>`;
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
});
|
| 494 |
+
|
| 495 |
+
this.variablesDisplay.innerHTML = html;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
getVariableColorClass(varName) {
|
| 499 |
+
const colorMap = {
|
| 500 |
+
'lines_in_half_page': 'var1-color',
|
| 501 |
+
'total_lines_written': 'var2-color',
|
| 502 |
+
'words_written': 'var3-color',
|
| 503 |
+
'words_left': 'var4-color'
|
| 504 |
+
};
|
| 505 |
+
return colorMap[varName] || '';
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
// Initialize the debugger when the page loads
|
| 510 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 511 |
+
new PythonDebugger();
|
| 512 |
+
});
|
| 513 |
+
</script>
|
| 514 |
+
</body>
|
| 515 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_14.html
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 193 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 194 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 196 |
+
.var5-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
.wrong-step {
|
| 219 |
+
display: none;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
<span id="fact1" class="fact1-color">Valerie needs to put stamps on the envelopes she is about to mail.</span> She has thank you cards for each of her grandmother, uncle and aunt for the birthday presents they sent. <span id="fact2" class="fact2-color">She also has to pay the water bill and the electric bill separately.</span> <span id="fact3" class="fact3-color">She wants to send three more mail-in rebates than she does bills</span> and <span id="fact4" class="fact4-color">she has twice as many job applications as rebates to mail.</span> <span id="fact5" class="fact5-color">How many stamps does she need if everything needs 1 stamp except the electric bill, which needs 2?</span>
|
| 232 |
+
</p>
|
| 233 |
+
</div>
|
| 234 |
+
<div class="problem-understanding">
|
| 235 |
+
<div class="section-title">Problem Summary</div>
|
| 236 |
+
<ul>
|
| 237 |
+
<li><span class="fact1-color">Stamps needed per envelope: 1 (except electric bill)</span></li>
|
| 238 |
+
<li><span class="fact2-color">Number of bills: 2 (water and electric)</span></li>
|
| 239 |
+
<li><span class="fact3-color">Rebates: 3 more than bills</span></li>
|
| 240 |
+
<li><span class="fact4-color">Job applications: 2 times rebates</span></li>
|
| 241 |
+
<li><span class="fact5-color">Electric bill stamps: 2</span></li>
|
| 242 |
+
</ul>
|
| 243 |
+
<div class="what-to-find">
|
| 244 |
+
<h4>What we need to find:</h4>
|
| 245 |
+
<p>The total number of stamps Valerie needs for all her mail.</p>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
</div>
|
| 249 |
+
<div class="right-panel">
|
| 250 |
+
<div class="debugger-controls">
|
| 251 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 252 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 253 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 254 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="python-solution">
|
| 257 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 258 |
+
<div class="python-code" id="python-code">
|
| 259 |
+
<div class="code-line" data-step="0">
|
| 260 |
+
<span class="line-number">1</span>
|
| 261 |
+
<span class="comment"># Calculate number of thank you cards</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="1">
|
| 264 |
+
<span class="line-number">2</span>
|
| 265 |
+
<span><span class="var1-color">thank_you_cards</span> = 3 * 1</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="2">
|
| 268 |
+
<span class="line-number">3</span>
|
| 269 |
+
<span class="comment"># Number of bills to mail</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="3">
|
| 272 |
+
<span class="line-number">4</span>
|
| 273 |
+
<span><span class="var2-color">bills</span> = <span class="fact2-color">2</span></span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="4">
|
| 276 |
+
<span class="line-number">5</span>
|
| 277 |
+
<span class="comment"># Calculate number of rebates</span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="5">
|
| 280 |
+
<span class="line-number">6</span>
|
| 281 |
+
<span><span class="var3-color">rebates</span> = <span class="var2-color">bills</span> + <span class="fact3-color">3</span></span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="6">
|
| 284 |
+
<span class="line-number">7</span>
|
| 285 |
+
<span class="comment"># Calculate number of job applications</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="7">
|
| 288 |
+
<span class="line-number">8</span>
|
| 289 |
+
<span><span class="var4-color">applications</span> = <span class="fact4-color">2</span> * <span class="var3-color">rebates</span></span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="8">
|
| 292 |
+
<span class="line-number">9</span>
|
| 293 |
+
<span class="comment"># Calculate total pieces of mail</span>
|
| 294 |
+
</div>
|
| 295 |
+
<div class="code-line" data-step="9">
|
| 296 |
+
<span class="line-number">10</span>
|
| 297 |
+
<span><span class="var5-color">total_mail</span> = <span class="var1-color">thank_you_cards</span> + <span class="var2-color">bills</span> + <span class="var3-color">rebates</span> + <span class="var4-color">applications</span></span>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="code-line" data-step="10">
|
| 300 |
+
<span class="line-number">11</span>
|
| 301 |
+
<span class="comment"># Calculate total stamps needed (extra stamp for electric bill)</span>
|
| 302 |
+
</div>
|
| 303 |
+
<div class="code-line" data-step="11">
|
| 304 |
+
<span class="line-number">12</span>
|
| 305 |
+
<span>total_stamps = <span class="var5-color">total_mail</span> + 1</span>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="variables-display" id="variables-display">
|
| 310 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 311 |
+
<div id="variables-list">
|
| 312 |
+
<div class="variable-item">
|
| 313 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 314 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
</div>
|
| 320 |
+
|
| 321 |
+
<script>
|
| 322 |
+
class PythonDebugger {
|
| 323 |
+
constructor() {
|
| 324 |
+
this.currentStep = -1;
|
| 325 |
+
this.isPlaying = false;
|
| 326 |
+
this.playInterval = null;
|
| 327 |
+
this.totalSteps = 11;
|
| 328 |
+
this.variables = {};
|
| 329 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 330 |
+
|
| 331 |
+
this.initializeElements();
|
| 332 |
+
this.bindEvents();
|
| 333 |
+
this.updateUI();
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
initializeElements() {
|
| 337 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 338 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 339 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 340 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 341 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 342 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
bindEvents() {
|
| 346 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 347 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 348 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 349 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
togglePlay() {
|
| 353 |
+
if (this.isPlaying) {
|
| 354 |
+
this.pause();
|
| 355 |
+
} else {
|
| 356 |
+
this.play();
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
play() {
|
| 361 |
+
this.isPlaying = true;
|
| 362 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 363 |
+
|
| 364 |
+
if (this.currentStep >= this.totalSteps) {
|
| 365 |
+
this.currentStep = -1;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
this.playInterval = setInterval(() => {
|
| 369 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 370 |
+
if (nextStep !== null) {
|
| 371 |
+
this.currentStep = nextStep;
|
| 372 |
+
this.executeStep(this.currentStep);
|
| 373 |
+
this.updateUI();
|
| 374 |
+
} else {
|
| 375 |
+
this.pause();
|
| 376 |
+
}
|
| 377 |
+
}, 1500);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
pause() {
|
| 381 |
+
this.isPlaying = false;
|
| 382 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 383 |
+
if (this.playInterval) {
|
| 384 |
+
clearInterval(this.playInterval);
|
| 385 |
+
this.playInterval = null;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
stop() {
|
| 390 |
+
this.pause();
|
| 391 |
+
this.currentStep = -1;
|
| 392 |
+
this.variables = {};
|
| 393 |
+
this.updateUI();
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
nextStep() {
|
| 397 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 398 |
+
if (nextStep !== null) {
|
| 399 |
+
this.currentStep = nextStep;
|
| 400 |
+
this.executeStep(this.currentStep);
|
| 401 |
+
this.updateUI();
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
previousStep() {
|
| 406 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 407 |
+
if (prevStep !== null) {
|
| 408 |
+
this.currentStep = prevStep;
|
| 409 |
+
this.recalculateVariables();
|
| 410 |
+
this.updateUI();
|
| 411 |
+
} else if (this.currentStep !== -1) {
|
| 412 |
+
this.currentStep = -1;
|
| 413 |
+
this.variables = {};
|
| 414 |
+
this.updateUI();
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
executeStep(step) {
|
| 419 |
+
switch(step) {
|
| 420 |
+
case 1:
|
| 421 |
+
this.variables.thank_you_cards = 3 * 1;
|
| 422 |
+
break;
|
| 423 |
+
case 3:
|
| 424 |
+
this.variables.bills = 2;
|
| 425 |
+
break;
|
| 426 |
+
case 5:
|
| 427 |
+
this.variables.rebates = this.variables.bills + 3;
|
| 428 |
+
break;
|
| 429 |
+
case 7:
|
| 430 |
+
this.variables.applications = 2 * this.variables.rebates;
|
| 431 |
+
break;
|
| 432 |
+
case 9:
|
| 433 |
+
// This is the wrong step (step 5 in the unformatted info)
|
| 434 |
+
if (step === this.wrongStep) {
|
| 435 |
+
this.variables.total_mail = this.variables.thank_you_cards + this.variables.bills + this.variables.rebates + this.variables.applications;
|
| 436 |
+
} else {
|
| 437 |
+
this.variables.total_mail = this.variables.thank_you_cards + this.variables.bills + this.variables.rebates + this.variables.applications;
|
| 438 |
+
}
|
| 439 |
+
break;
|
| 440 |
+
case 11:
|
| 441 |
+
this.variables.total_stamps = this.variables.total_mail + 1;
|
| 442 |
+
break;
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
getExecutableSteps() {
|
| 447 |
+
// Returns only the steps that execute actual code (not comments)
|
| 448 |
+
return [1, 3, 5, 7, 9, 11];
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
getNextExecutableStep(currentStep) {
|
| 452 |
+
const executableSteps = this.getExecutableSteps();
|
| 453 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 454 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
getPreviousExecutableStep(currentStep) {
|
| 458 |
+
const executableSteps = this.getExecutableSteps();
|
| 459 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 460 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
recalculateVariables() {
|
| 464 |
+
this.variables = {};
|
| 465 |
+
const executableSteps = this.getExecutableSteps();
|
| 466 |
+
for (let step of executableSteps) {
|
| 467 |
+
if (step <= this.currentStep) {
|
| 468 |
+
this.executeStep(step);
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
updateUI() {
|
| 474 |
+
// Update code highlighting
|
| 475 |
+
this.codeLines.forEach((line, index) => {
|
| 476 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 477 |
+
});
|
| 478 |
+
|
| 479 |
+
// Update button states
|
| 480 |
+
const executableSteps = this.getExecutableSteps();
|
| 481 |
+
const isFirstStep = this.currentStep === -1;
|
| 482 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 483 |
+
|
| 484 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 485 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 486 |
+
|
| 487 |
+
// Update variables display
|
| 488 |
+
this.updateVariablesDisplay();
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
updateVariablesDisplay() {
|
| 492 |
+
if (Object.keys(this.variables).length === 0) {
|
| 493 |
+
this.variablesDisplay.innerHTML = `
|
| 494 |
+
<div class="variable-item">
|
| 495 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 496 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 497 |
+
</div>
|
| 498 |
+
`;
|
| 499 |
+
return;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
let html = '';
|
| 503 |
+
const variableOrder = ['thank_you_cards', 'bills', 'rebates', 'applications', 'total_mail', 'total_stamps'];
|
| 504 |
+
|
| 505 |
+
variableOrder.forEach(varName => {
|
| 506 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 507 |
+
const value = this.variables[varName];
|
| 508 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 509 |
+
|
| 510 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 511 |
+
if(varName === lastVarName){
|
| 512 |
+
varName = varName + " (Final Answer)";
|
| 513 |
+
html += `<div class="variable-item ${colorClass}">
|
| 514 |
+
<span class="variable-name">${varName}</span>
|
| 515 |
+
<span class="variable-value">${value}</span>
|
| 516 |
+
</div>`;
|
| 517 |
+
} else {
|
| 518 |
+
html += `<div class="variable-item ${colorClass}">
|
| 519 |
+
<span class="variable-name">${varName}</span>
|
| 520 |
+
<span class="variable-value">${value}</span>
|
| 521 |
+
</div>`;
|
| 522 |
+
}
|
| 523 |
+
}
|
| 524 |
+
});
|
| 525 |
+
|
| 526 |
+
this.variablesDisplay.innerHTML = html;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
getVariableColorClass(varName) {
|
| 530 |
+
const colorMap = {
|
| 531 |
+
'thank_you_cards': 'var1-color',
|
| 532 |
+
'bills': 'var2-color',
|
| 533 |
+
'rebates': 'var3-color',
|
| 534 |
+
'applications': 'var4-color',
|
| 535 |
+
'total_mail': 'var5-color',
|
| 536 |
+
'total_stamps': 'fact5-color'
|
| 537 |
+
};
|
| 538 |
+
return colorMap[varName] || '';
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
// Initialize the debugger when the page loads
|
| 543 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 544 |
+
new PythonDebugger();
|
| 545 |
+
});
|
| 546 |
+
</script>
|
| 547 |
+
</body>
|
| 548 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_15.html
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 196 |
+
.var6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
.wrong-step {
|
| 219 |
+
display: none;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
<span id="fact1" class="fact1-color">Maddox and Theo both bought 3 Polaroid Cameras</span>, each sold at <span id="fact2" class="fact2-color">$20 per camera</span> from Amazon, and decided to sell them on eBay. Maddox sold his cameras at <span id="fact3" class="fact3-color">$28 each</span>, while Theo sold his cameras at <span id="fact4" class="fact4-color">$23 each</span>. How much more profit did Maddox get from the sale of his cameras than Theo?
|
| 232 |
+
</p>
|
| 233 |
+
</div>
|
| 234 |
+
<div class="problem-understanding">
|
| 235 |
+
<div class="section-title">Problem Summary</div>
|
| 236 |
+
<ul>
|
| 237 |
+
<li><span class="fact1-color">Number of cameras bought by each person: 3</span></li>
|
| 238 |
+
<li><span class="fact2-color">Cost per camera: $20</span></li>
|
| 239 |
+
<li><span class="fact3-color">Maddox's selling price per camera: $28</span></li>
|
| 240 |
+
<li><span class="fact4-color">Theo's selling price per camera: $23</span></li>
|
| 241 |
+
</ul>
|
| 242 |
+
<div class="what-to-find">
|
| 243 |
+
<h4>What we need to find:</h4>
|
| 244 |
+
<p>How much more profit did Maddox get from the sale of his cameras than Theo?</p>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
<div class="right-panel">
|
| 249 |
+
<div class="debugger-controls">
|
| 250 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 251 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 252 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 253 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 254 |
+
</div>
|
| 255 |
+
<div class="python-solution">
|
| 256 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 257 |
+
<div class="python-code" id="python-code">
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">1</span>
|
| 260 |
+
<span class="comment"># Calculate the total cost of buying 3 cameras for each person</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="1">
|
| 263 |
+
<span class="line-number">2</span>
|
| 264 |
+
<span><span class="var1-color">total_cost_each</span> = <span class="fact1-color">3</span> * <span class="fact2-color">20</span></span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="2">
|
| 267 |
+
<span class="line-number">3</span>
|
| 268 |
+
<span class="comment"># Calculate Maddox's total revenue</span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="2">
|
| 271 |
+
<span class="line-number">4</span>
|
| 272 |
+
<span><span class="var2-color">maddox_revenue</span> = <span class="fact3-color">28</span> * <span class="fact1-color">3</span></span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="3">
|
| 275 |
+
<span class="line-number">5</span>
|
| 276 |
+
<span class="comment"># Calculate Maddox's profit</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="3">
|
| 279 |
+
<span class="line-number">6</span>
|
| 280 |
+
<span><span class="var3-color">maddox_profit</span> = <span class="var2-color">maddox_revenue</span> - <span class="var1-color">total_cost_each</span></span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="4">
|
| 283 |
+
<span class="line-number">7</span>
|
| 284 |
+
<span class="comment"># Calculate Theo's total revenue</span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="4">
|
| 287 |
+
<span class="line-number">8</span>
|
| 288 |
+
<span><span class="var4-color">theo_revenue</span> = <span class="fact4-color">23</span> * <span class="fact1-color">3</span></span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="5">
|
| 291 |
+
<span class="line-number">9</span>
|
| 292 |
+
<span class="comment"># Calculate Theo's profit</span>
|
| 293 |
+
</div>
|
| 294 |
+
<div class="code-line" data-step="5">
|
| 295 |
+
<span class="line-number">10</span>
|
| 296 |
+
<span><span class="var5-color">theo_profit</span> = <span class="var4-color">theo_revenue</span> - <span class="var1-color">total_cost_each</span></span>
|
| 297 |
+
</div>
|
| 298 |
+
<div class="code-line" data-step="6">
|
| 299 |
+
<span class="line-number">11</span>
|
| 300 |
+
<span class="comment"># Calculate how much more profit Maddox made than Theo</span>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="code-line" data-step="6">
|
| 303 |
+
<span class="line-number">12</span>
|
| 304 |
+
<span><span class="var6-color">profit_difference</span> = <span class="var3-color">maddox_profit</span> - <span class="var5-color">theo_profit</span></span>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
<div class="variables-display" id="variables-display">
|
| 309 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 310 |
+
<div id="variables-list">
|
| 311 |
+
<div class="variable-item">
|
| 312 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 313 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
|
| 320 |
+
<script>
|
| 321 |
+
class PythonDebugger {
|
| 322 |
+
constructor() {
|
| 323 |
+
this.currentStep = -1;
|
| 324 |
+
this.isPlaying = false;
|
| 325 |
+
this.playInterval = null;
|
| 326 |
+
this.totalSteps = 6;
|
| 327 |
+
this.variables = {};
|
| 328 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 329 |
+
|
| 330 |
+
this.initializeElements();
|
| 331 |
+
this.bindEvents();
|
| 332 |
+
this.updateUI();
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
initializeElements() {
|
| 336 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 337 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 338 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 339 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 340 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 341 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
bindEvents() {
|
| 345 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 346 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 347 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 348 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
togglePlay() {
|
| 352 |
+
if (this.isPlaying) {
|
| 353 |
+
this.pause();
|
| 354 |
+
} else {
|
| 355 |
+
this.play();
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
play() {
|
| 360 |
+
this.isPlaying = true;
|
| 361 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 362 |
+
|
| 363 |
+
if (this.currentStep >= this.totalSteps) {
|
| 364 |
+
this.currentStep = -1;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
this.playInterval = setInterval(() => {
|
| 368 |
+
if (this.currentStep < this.totalSteps) {
|
| 369 |
+
this.nextStep();
|
| 370 |
+
} else {
|
| 371 |
+
this.pause();
|
| 372 |
+
}
|
| 373 |
+
}, 1500);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
pause() {
|
| 377 |
+
this.isPlaying = false;
|
| 378 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 379 |
+
if (this.playInterval) {
|
| 380 |
+
clearInterval(this.playInterval);
|
| 381 |
+
this.playInterval = null;
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
stop() {
|
| 386 |
+
this.pause();
|
| 387 |
+
this.currentStep = -1;
|
| 388 |
+
this.variables = {};
|
| 389 |
+
this.updateUI();
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
nextStep() {
|
| 393 |
+
if (this.currentStep < this.totalSteps) {
|
| 394 |
+
this.currentStep++;
|
| 395 |
+
this.executeStep(this.currentStep);
|
| 396 |
+
this.updateUI();
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
previousStep() {
|
| 401 |
+
if (this.currentStep > 0) {
|
| 402 |
+
this.currentStep--;
|
| 403 |
+
this.recalculateVariables();
|
| 404 |
+
this.updateUI();
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
executeStep(step) {
|
| 409 |
+
switch(step) {
|
| 410 |
+
case 1:
|
| 411 |
+
this.variables.total_cost_each = 3 * 20;
|
| 412 |
+
break;
|
| 413 |
+
case 2:
|
| 414 |
+
this.variables.maddox_revenue = 28 * 3;
|
| 415 |
+
break;
|
| 416 |
+
case 3:
|
| 417 |
+
this.variables.maddox_profit = this.variables.maddox_revenue - this.variables.total_cost_each;
|
| 418 |
+
break;
|
| 419 |
+
case 4:
|
| 420 |
+
// This is the wrong step according to the wrongstep tag
|
| 421 |
+
this.variables.theo_revenue = 23 * 3;
|
| 422 |
+
break;
|
| 423 |
+
case 5:
|
| 424 |
+
this.variables.theo_profit = this.variables.theo_revenue - this.variables.total_cost_each;
|
| 425 |
+
break;
|
| 426 |
+
case 6:
|
| 427 |
+
this.variables.profit_difference = this.variables.maddox_profit - this.variables.theo_profit;
|
| 428 |
+
break;
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
recalculateVariables() {
|
| 433 |
+
this.variables = {};
|
| 434 |
+
for (let i = 1; i <= this.currentStep; i++) {
|
| 435 |
+
this.executeStep(i);
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
updateUI() {
|
| 440 |
+
// Update code highlighting
|
| 441 |
+
this.codeLines.forEach(line => {
|
| 442 |
+
line.classList.remove('current');
|
| 443 |
+
});
|
| 444 |
+
|
| 445 |
+
if (this.currentStep > 0) {
|
| 446 |
+
const currentLines = document.querySelectorAll(`.code-line[data-step="${this.currentStep}"]`);
|
| 447 |
+
currentLines.forEach(line => {
|
| 448 |
+
line.classList.add('current');
|
| 449 |
+
});
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
// Update button states
|
| 453 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= 0);
|
| 454 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 455 |
+
|
| 456 |
+
// Update variables display
|
| 457 |
+
this.updateVariablesDisplay();
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
updateVariablesDisplay() {
|
| 461 |
+
if (Object.keys(this.variables).length === 0) {
|
| 462 |
+
this.variablesDisplay.innerHTML = `
|
| 463 |
+
<div class="variable-item">
|
| 464 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 465 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 466 |
+
</div>
|
| 467 |
+
`;
|
| 468 |
+
return;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
let html = '';
|
| 472 |
+
const variableOrder = ['total_cost_each', 'maddox_revenue', 'maddox_profit', 'theo_revenue', 'theo_profit', 'profit_difference'];
|
| 473 |
+
const colorClasses = {
|
| 474 |
+
'total_cost_each': 'var1-color',
|
| 475 |
+
'maddox_revenue': 'var2-color',
|
| 476 |
+
'maddox_profit': 'var3-color',
|
| 477 |
+
'theo_revenue': 'var4-color',
|
| 478 |
+
'theo_profit': 'var5-color',
|
| 479 |
+
'profit_difference': 'var6-color'
|
| 480 |
+
};
|
| 481 |
+
|
| 482 |
+
variableOrder.forEach(varName => {
|
| 483 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 484 |
+
const value = this.variables[varName];
|
| 485 |
+
const colorClass = colorClasses[varName];
|
| 486 |
+
const displayValue = varName.includes('cost') || varName.includes('revenue') || varName.includes('profit') ?
|
| 487 |
+
`$${value}` : value;
|
| 488 |
+
|
| 489 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 490 |
+
if(varName === lastVarName){
|
| 491 |
+
varName = varName + " (Final Answer)";
|
| 492 |
+
html += `<div class="variable-item ${colorClass}">
|
| 493 |
+
<span class="variable-name">${varName}</span>
|
| 494 |
+
<span class="variable-value">${value}</span>
|
| 495 |
+
</div>`;
|
| 496 |
+
} else {
|
| 497 |
+
html += `<div class="variable-item ${colorClass}">
|
| 498 |
+
<span class="variable-name">${varName}</span>
|
| 499 |
+
<span class="variable-value">${value}</span>
|
| 500 |
+
</div>`;
|
| 501 |
+
}
|
| 502 |
+
}
|
| 503 |
+
});
|
| 504 |
+
|
| 505 |
+
this.variablesDisplay.innerHTML = html;
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
// Initialize the debugger when the page loads
|
| 510 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 511 |
+
new PythonDebugger();
|
| 512 |
+
});
|
| 513 |
+
</script>
|
| 514 |
+
</body>
|
| 515 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_16.html
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.fact7-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.fact8-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 195 |
+
.fact9-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 196 |
+
.var1-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var2-color { background-color: rgba(63, 81, 181, 0.5); }
|
| 198 |
+
.var3-color { background-color: rgba(255, 152, 0, 0.5); }
|
| 199 |
+
.var4-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 200 |
+
.var5-color { background-color: rgba(139, 195, 74, 0.5); }
|
| 201 |
+
.var6-color { background-color: rgba(158, 158, 158, 0.5); }
|
| 202 |
+
|
| 203 |
+
ul {
|
| 204 |
+
padding-left: 20px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
li {
|
| 208 |
+
margin-bottom: 12px;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find {
|
| 212 |
+
margin-top: 20px;
|
| 213 |
+
padding: 15px;
|
| 214 |
+
background-color: #e8f4fd;
|
| 215 |
+
border-radius: 6px;
|
| 216 |
+
border-left: 4px solid #3498db;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.what-to-find h4 {
|
| 220 |
+
color: #2c3e50;
|
| 221 |
+
margin-bottom: 8px;
|
| 222 |
+
}
|
| 223 |
+
.wrong-step {
|
| 224 |
+
display: none;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
</style>
|
| 228 |
+
</head>
|
| 229 |
+
<body>
|
| 230 |
+
<div class="wrong-step">0</div>
|
| 231 |
+
<div class="container">
|
| 232 |
+
<div class="left-panel">
|
| 233 |
+
<div class="problem-statement">
|
| 234 |
+
<div class="section-title">Problem Statement</div>
|
| 235 |
+
<p>
|
| 236 |
+
The teacher decided to rewards his students with extra recess on report card day if they got good grades. Students normally get <span id="fact1" class="fact1-color">20 minutes</span> for recess. He told the students that every A got them <span id="fact2" class="fact2-color">2 extra minutes</span> of recess. Every B got them <span id="fact3" class="fact3-color">one extra minute</span>. Every C got them <span id="fact4" class="fact4-color">zero extra minutes</span>, but every D got them <span id="fact5" class="fact5-color">1 less minute</span>. When report cards came out there were <span id="fact6" class="fact6-color">10 As</span>, <span id="fact7" class="fact7-color">12 Bs</span>, <span id="fact8" class="fact8-color">14 Cs</span>, and <span id="fact9" class="fact9-color">5 Ds</span>. In total, how much recess would the students get that day?
|
| 237 |
+
</p>
|
| 238 |
+
</div>
|
| 239 |
+
<div class="problem-understanding">
|
| 240 |
+
<div class="section-title">Problem Summary</div>
|
| 241 |
+
<ul>
|
| 242 |
+
<li><span class="fact1-color">Normal recess time: 20 minutes</span></li>
|
| 243 |
+
<li><span class="fact2-color">Extra minutes per A: 2</span></li>
|
| 244 |
+
<li><span class="fact3-color">Extra minutes per B: 1</span></li>
|
| 245 |
+
<li><span class="fact4-color">Extra minutes per C: 0</span></li>
|
| 246 |
+
<li><span class="fact5-color">Minutes lost per D: 1</span></li>
|
| 247 |
+
<li><span class="fact6-color">Number of As: 10</span></li>
|
| 248 |
+
<li><span class="fact7-color">Number of Bs: 12</span></li>
|
| 249 |
+
<li><span class="fact8-color">Number of Cs: 14</span></li>
|
| 250 |
+
<li><span class="fact9-color">Number of Ds: 5</span></li>
|
| 251 |
+
</ul>
|
| 252 |
+
<div class="what-to-find">
|
| 253 |
+
<h4>What we need to find</h4>
|
| 254 |
+
<p>The total amount of recess time the students would get that day.</p>
|
| 255 |
+
</div>
|
| 256 |
+
</div>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="right-panel">
|
| 259 |
+
<div class="debugger-controls">
|
| 260 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 261 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 262 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 263 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="python-solution">
|
| 266 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 267 |
+
<div class="python-code" id="python-code">
|
| 268 |
+
<div class="code-line" data-step="0">
|
| 269 |
+
<span class="line-number">1</span>
|
| 270 |
+
<span class="comment"># The students have 20 minutes to start</span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="1">
|
| 273 |
+
<span class="line-number">2</span>
|
| 274 |
+
<span><span class="var1-color">base_recess</span> = <span class="fact1-color">20</span></span>
|
| 275 |
+
</div>
|
| 276 |
+
<div class="code-line" data-step="2">
|
| 277 |
+
<span class="line-number">3</span>
|
| 278 |
+
<span class="comment"># Calculate extra minutes from As</span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="code-line" data-step="3">
|
| 281 |
+
<span class="line-number">4</span>
|
| 282 |
+
<span><span class="var2-color">extra_from_As</span> = <span class="fact6-color">10</span> * <span class="fact2-color">2</span></span>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="code-line" data-step="4">
|
| 285 |
+
<span class="line-number">5</span>
|
| 286 |
+
<span class="comment"># Calculate extra minutes from Bs</span>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="code-line" data-step="5">
|
| 289 |
+
<span class="line-number">6</span>
|
| 290 |
+
<span><span class="var3-color">extra_from_Bs</span> = <span class="fact7-color">12</span> * <span class="fact3-color">1</span></span>
|
| 291 |
+
</div>
|
| 292 |
+
<div class="code-line" data-step="6">
|
| 293 |
+
<span class="line-number">7</span>
|
| 294 |
+
<span class="comment"># Calculate extra minutes from Cs</span>
|
| 295 |
+
</div>
|
| 296 |
+
<div class="code-line" data-step="7">
|
| 297 |
+
<span class="line-number">8</span>
|
| 298 |
+
<span><span class="var4-color">extra_from_Cs</span> = <span class="fact8-color">14</span> * <span class="fact4-color">0</span></span>
|
| 299 |
+
</div>
|
| 300 |
+
<div class="code-line" data-step="8">
|
| 301 |
+
<span class="line-number">9</span>
|
| 302 |
+
<span class="comment"># Calculate minutes lost from Ds</span>
|
| 303 |
+
</div>
|
| 304 |
+
<div class="code-line" data-step="9">
|
| 305 |
+
<span class="line-number">10</span>
|
| 306 |
+
<span><span class="var5-color">lost_from_Ds</span> = <span class="fact9-color">5</span> * <span class="fact5-color">1</span></span>
|
| 307 |
+
</div>
|
| 308 |
+
<div class="code-line" data-step="10">
|
| 309 |
+
<span class="line-number">11</span>
|
| 310 |
+
<span class="comment"># Calculate total recess time</span>
|
| 311 |
+
</div>
|
| 312 |
+
<div class="code-line" data-step="11">
|
| 313 |
+
<span class="line-number">12</span>
|
| 314 |
+
<span><span class="var6-color">total_recess</span> = <span class="var1-color">base_recess</span> + <span class="var2-color">extra_from_As</span> + <span class="var3-color">extra_from_Bs</span> - <span class="var5-color">lost_from_Ds</span></span>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
<div class="variables-display" id="variables-display">
|
| 319 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 320 |
+
<div id="variables-list">
|
| 321 |
+
<div class="variable-item">
|
| 322 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 323 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
</div>
|
| 329 |
+
|
| 330 |
+
<script>
|
| 331 |
+
class PythonDebugger {
|
| 332 |
+
constructor() {
|
| 333 |
+
this.currentStep = -1;
|
| 334 |
+
this.isPlaying = false;
|
| 335 |
+
this.playInterval = null;
|
| 336 |
+
this.totalSteps = 11;
|
| 337 |
+
this.variables = {};
|
| 338 |
+
|
| 339 |
+
this.initializeElements();
|
| 340 |
+
this.bindEvents();
|
| 341 |
+
this.updateUI();
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
initializeElements() {
|
| 345 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 346 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 347 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 348 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 349 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 350 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
bindEvents() {
|
| 354 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 355 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 356 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 357 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
togglePlay() {
|
| 361 |
+
if (this.isPlaying) {
|
| 362 |
+
this.pause();
|
| 363 |
+
} else {
|
| 364 |
+
this.play();
|
| 365 |
+
}
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
play() {
|
| 369 |
+
this.isPlaying = true;
|
| 370 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 371 |
+
|
| 372 |
+
if (this.currentStep >= this.totalSteps) {
|
| 373 |
+
this.currentStep = -1;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
this.playInterval = setInterval(() => {
|
| 377 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 378 |
+
if (nextStep !== null) {
|
| 379 |
+
this.currentStep = nextStep;
|
| 380 |
+
this.executeStep(this.currentStep);
|
| 381 |
+
this.updateUI();
|
| 382 |
+
} else {
|
| 383 |
+
this.pause();
|
| 384 |
+
}
|
| 385 |
+
}, 1500);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
pause() {
|
| 389 |
+
this.isPlaying = false;
|
| 390 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 391 |
+
if (this.playInterval) {
|
| 392 |
+
clearInterval(this.playInterval);
|
| 393 |
+
this.playInterval = null;
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
stop() {
|
| 398 |
+
this.pause();
|
| 399 |
+
this.currentStep = -1;
|
| 400 |
+
this.variables = {};
|
| 401 |
+
this.updateUI();
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
nextStep() {
|
| 405 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 406 |
+
if (nextStep !== null) {
|
| 407 |
+
this.currentStep = nextStep;
|
| 408 |
+
this.executeStep(this.currentStep);
|
| 409 |
+
this.updateUI();
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
previousStep() {
|
| 414 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 415 |
+
if (prevStep !== null) {
|
| 416 |
+
this.currentStep = prevStep;
|
| 417 |
+
this.recalculateVariables();
|
| 418 |
+
this.updateUI();
|
| 419 |
+
} else if (this.currentStep !== -1) {
|
| 420 |
+
this.currentStep = -1;
|
| 421 |
+
this.variables = {};
|
| 422 |
+
this.updateUI();
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
executeStep(step) {
|
| 427 |
+
switch(step) {
|
| 428 |
+
case 1:
|
| 429 |
+
this.variables.base_recess = 20;
|
| 430 |
+
break;
|
| 431 |
+
case 3:
|
| 432 |
+
this.variables.extra_from_As = 10 * 2;
|
| 433 |
+
break;
|
| 434 |
+
case 5:
|
| 435 |
+
this.variables.extra_from_Bs = 12 * 1;
|
| 436 |
+
break;
|
| 437 |
+
case 7:
|
| 438 |
+
this.variables.extra_from_Cs = 14 * 0;
|
| 439 |
+
break;
|
| 440 |
+
case 9:
|
| 441 |
+
this.variables.lost_from_Ds = 5 * 1;
|
| 442 |
+
break;
|
| 443 |
+
case 11:
|
| 444 |
+
this.variables.total_recess = this.variables.base_recess + this.variables.extra_from_As + this.variables.extra_from_Bs - this.variables.lost_from_Ds;
|
| 445 |
+
break;
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
getExecutableSteps() {
|
| 450 |
+
// Returns only the steps that execute actual code (not comments)
|
| 451 |
+
return [1, 3, 5, 7, 9, 11];
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
getNextExecutableStep(currentStep) {
|
| 455 |
+
const executableSteps = this.getExecutableSteps();
|
| 456 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 457 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
getPreviousExecutableStep(currentStep) {
|
| 461 |
+
const executableSteps = this.getExecutableSteps();
|
| 462 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 463 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
recalculateVariables() {
|
| 467 |
+
this.variables = {};
|
| 468 |
+
const executableSteps = this.getExecutableSteps();
|
| 469 |
+
for (let step of executableSteps) {
|
| 470 |
+
if (step <= this.currentStep) {
|
| 471 |
+
this.executeStep(step);
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
updateUI() {
|
| 477 |
+
// Update code highlighting
|
| 478 |
+
this.codeLines.forEach((line, index) => {
|
| 479 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 480 |
+
});
|
| 481 |
+
|
| 482 |
+
// Update button states
|
| 483 |
+
const executableSteps = this.getExecutableSteps();
|
| 484 |
+
const isFirstStep = this.currentStep === -1;
|
| 485 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 486 |
+
|
| 487 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 488 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 489 |
+
|
| 490 |
+
// Update variables display
|
| 491 |
+
this.updateVariablesDisplay();
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
updateVariablesDisplay() {
|
| 495 |
+
if (Object.keys(this.variables).length === 0) {
|
| 496 |
+
this.variablesDisplay.innerHTML = `
|
| 497 |
+
<div class="variable-item">
|
| 498 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 499 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 500 |
+
</div>
|
| 501 |
+
`;
|
| 502 |
+
return;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
let html = '';
|
| 506 |
+
const variableOrder = ['base_recess', 'extra_from_As', 'extra_from_Bs', 'extra_from_Cs', 'lost_from_Ds', 'total_recess'];
|
| 507 |
+
|
| 508 |
+
variableOrder.forEach(varName => {
|
| 509 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 510 |
+
const value = this.variables[varName];
|
| 511 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 512 |
+
|
| 513 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 514 |
+
if(varName === lastVarName){
|
| 515 |
+
varName = varName + " (Final Answer)";
|
| 516 |
+
html += `<div class="variable-item ${colorClass}">
|
| 517 |
+
<span class="variable-name">${varName}</span>
|
| 518 |
+
<span class="variable-value">${value}</span>
|
| 519 |
+
</div>`;
|
| 520 |
+
} else {
|
| 521 |
+
html += `<div class="variable-item ${colorClass}">
|
| 522 |
+
<span class="variable-name">${varName}</span>
|
| 523 |
+
<span class="variable-value">${value}</span>
|
| 524 |
+
</div>`;
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
});
|
| 528 |
+
|
| 529 |
+
this.variablesDisplay.innerHTML = html;
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
getVariableColorClass(varName) {
|
| 533 |
+
const colorMap = {
|
| 534 |
+
'base_recess': 'var1-color',
|
| 535 |
+
'extra_from_As': 'var2-color',
|
| 536 |
+
'extra_from_Bs': 'var3-color',
|
| 537 |
+
'extra_from_Cs': 'var4-color',
|
| 538 |
+
'lost_from_Ds': 'var5-color',
|
| 539 |
+
'total_recess': 'var6-color'
|
| 540 |
+
};
|
| 541 |
+
return colorMap[varName] || '';
|
| 542 |
+
}
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
// Initialize the debugger when the page loads
|
| 546 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 547 |
+
new PythonDebugger();
|
| 548 |
+
});
|
| 549 |
+
</script>
|
| 550 |
+
</body>
|
| 551 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_17.html
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Hot dog buns come in packages of 8.</span> For the school picnic, <span id="fact2" class="fact2-color">Mr. Gates bought 30 packages of hot dog buns.</span> He has <span id="fact3" class="fact3-color">four classes</span> with <span id="fact4" class="fact4-color">30 students in each class.</span> How many hot dog buns can each of Mr. Gates' students get?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Buns per package: 8</span></li>
|
| 235 |
+
<li><span class="fact2-color">Packages bought: 30</span></li>
|
| 236 |
+
<li><span class="fact3-color">Number of classes: 4</span></li>
|
| 237 |
+
<li><span class="fact4-color">Students per class: 30</span></li>
|
| 238 |
+
</ul>
|
| 239 |
+
<div class="what-to-find">
|
| 240 |
+
<h4>What we need to find</h4>
|
| 241 |
+
<p>How many hot dog buns each student can get.</p>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="right-panel">
|
| 246 |
+
<div class="debugger-controls">
|
| 247 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 248 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 249 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 250 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="python-solution">
|
| 253 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 254 |
+
<div class="python-code" id="python-code">
|
| 255 |
+
<div class="code-line" data-step="0">
|
| 256 |
+
<span class="line-number">1</span>
|
| 257 |
+
<span class="comment"># Calculate the total number of hot dog buns Mr. Gates bought</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">2</span>
|
| 261 |
+
<span><span class="var1-color">total_buns</span> = <span class="fact2-color">30</span> * <span class="fact1-color">8</span></span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">3</span>
|
| 265 |
+
<span class="comment"># Calculate the total number of students in Mr. Gates' classes</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">4</span>
|
| 269 |
+
<span><span class="var2-color">total_students</span> = <span class="fact3-color">4</span> * <span class="fact4-color">30</span></span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">5</span>
|
| 273 |
+
<span class="comment"># Calculate how many hot dog buns each student can get</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">6</span>
|
| 277 |
+
<span><span class="var3-color">buns_per_student</span> = <span class="var1-color">total_buns</span> / <span class="var2-color">total_students</span></span>
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="variables-display" id="variables-display">
|
| 282 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 283 |
+
<div id="variables-list">
|
| 284 |
+
<div class="variable-item">
|
| 285 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 286 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<script>
|
| 294 |
+
class PythonDebugger {
|
| 295 |
+
constructor() {
|
| 296 |
+
this.currentStep = -1;
|
| 297 |
+
this.isPlaying = false;
|
| 298 |
+
this.playInterval = null;
|
| 299 |
+
this.totalSteps = 5;
|
| 300 |
+
this.variables = {};
|
| 301 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 302 |
+
|
| 303 |
+
this.initializeElements();
|
| 304 |
+
this.bindEvents();
|
| 305 |
+
this.updateUI();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
initializeElements() {
|
| 309 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 310 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 311 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 312 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 313 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 314 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
bindEvents() {
|
| 318 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 319 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 320 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 321 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
togglePlay() {
|
| 325 |
+
if (this.isPlaying) {
|
| 326 |
+
this.pause();
|
| 327 |
+
} else {
|
| 328 |
+
this.play();
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
play() {
|
| 333 |
+
this.isPlaying = true;
|
| 334 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 335 |
+
|
| 336 |
+
if (this.currentStep >= this.totalSteps) {
|
| 337 |
+
this.currentStep = -1;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
this.playInterval = setInterval(() => {
|
| 341 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 342 |
+
if (nextStep !== null) {
|
| 343 |
+
this.currentStep = nextStep;
|
| 344 |
+
this.executeStep(this.currentStep);
|
| 345 |
+
this.updateUI();
|
| 346 |
+
} else {
|
| 347 |
+
this.pause();
|
| 348 |
+
}
|
| 349 |
+
}, 1500);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
pause() {
|
| 353 |
+
this.isPlaying = false;
|
| 354 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 355 |
+
if (this.playInterval) {
|
| 356 |
+
clearInterval(this.playInterval);
|
| 357 |
+
this.playInterval = null;
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
stop() {
|
| 362 |
+
this.pause();
|
| 363 |
+
this.currentStep = -1;
|
| 364 |
+
this.variables = {};
|
| 365 |
+
this.updateUI();
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
nextStep() {
|
| 369 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 370 |
+
if (nextStep !== null) {
|
| 371 |
+
this.currentStep = nextStep;
|
| 372 |
+
this.executeStep(this.currentStep);
|
| 373 |
+
this.updateUI();
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
previousStep() {
|
| 378 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 379 |
+
if (prevStep !== null) {
|
| 380 |
+
this.currentStep = prevStep;
|
| 381 |
+
this.recalculateVariables();
|
| 382 |
+
this.updateUI();
|
| 383 |
+
} else if (this.currentStep !== -1) {
|
| 384 |
+
this.currentStep = -1;
|
| 385 |
+
this.variables = {};
|
| 386 |
+
this.updateUI();
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
executeStep(step) {
|
| 391 |
+
switch(step) {
|
| 392 |
+
case 1:
|
| 393 |
+
this.variables.total_buns = 30 * 8;
|
| 394 |
+
break;
|
| 395 |
+
case 3:
|
| 396 |
+
// This is the wrong step - using wrong calculation
|
| 397 |
+
if (step === this.wrongStep) {
|
| 398 |
+
this.variables.total_students = 4 * 30;
|
| 399 |
+
} else {
|
| 400 |
+
this.variables.total_students = 4 * 30;
|
| 401 |
+
}
|
| 402 |
+
break;
|
| 403 |
+
case 5:
|
| 404 |
+
this.variables.buns_per_student = this.variables.total_buns / this.variables.total_students;
|
| 405 |
+
break;
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
getExecutableSteps() {
|
| 410 |
+
// Returns only the steps that execute actual code (not comments)
|
| 411 |
+
return [1, 3, 5];
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
getNextExecutableStep(currentStep) {
|
| 415 |
+
const executableSteps = this.getExecutableSteps();
|
| 416 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 417 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
getPreviousExecutableStep(currentStep) {
|
| 421 |
+
const executableSteps = this.getExecutableSteps();
|
| 422 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 423 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
recalculateVariables() {
|
| 427 |
+
this.variables = {};
|
| 428 |
+
const executableSteps = this.getExecutableSteps();
|
| 429 |
+
for (let step of executableSteps) {
|
| 430 |
+
if (step <= this.currentStep) {
|
| 431 |
+
this.executeStep(step);
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
updateUI() {
|
| 437 |
+
// Update code highlighting
|
| 438 |
+
this.codeLines.forEach((line, index) => {
|
| 439 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 440 |
+
});
|
| 441 |
+
|
| 442 |
+
// Update button states
|
| 443 |
+
const executableSteps = this.getExecutableSteps();
|
| 444 |
+
const isFirstStep = this.currentStep === -1;
|
| 445 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 446 |
+
|
| 447 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 448 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 449 |
+
|
| 450 |
+
// Update variables display
|
| 451 |
+
this.updateVariablesDisplay();
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
updateVariablesDisplay() {
|
| 455 |
+
if (Object.keys(this.variables).length === 0) {
|
| 456 |
+
this.variablesDisplay.innerHTML = `
|
| 457 |
+
<div class="variable-item">
|
| 458 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 459 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 460 |
+
</div>
|
| 461 |
+
`;
|
| 462 |
+
return;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
let html = '';
|
| 466 |
+
const variableOrder = ['total_buns', 'total_students', 'buns_per_student'];
|
| 467 |
+
|
| 468 |
+
variableOrder.forEach(varName => {
|
| 469 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 470 |
+
const value = this.variables[varName];
|
| 471 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 472 |
+
|
| 473 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 474 |
+
if(varName === lastVarName){
|
| 475 |
+
varName = varName + " (Final Answer)";
|
| 476 |
+
html += `<div class="variable-item ${colorClass}">
|
| 477 |
+
<span class="variable-name">${varName}</span>
|
| 478 |
+
<span class="variable-value">${value}</span>
|
| 479 |
+
</div>`;
|
| 480 |
+
} else {
|
| 481 |
+
html += `<div class="variable-item ${colorClass}">
|
| 482 |
+
<span class="variable-name">${varName}</span>
|
| 483 |
+
<span class="variable-value">${value}</span>
|
| 484 |
+
</div>`;
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
});
|
| 488 |
+
|
| 489 |
+
this.variablesDisplay.innerHTML = html;
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
getVariableColorClass(varName) {
|
| 493 |
+
const colorMap = {
|
| 494 |
+
'total_buns': 'var1-color',
|
| 495 |
+
'total_students': 'var2-color',
|
| 496 |
+
'buns_per_student': 'var3-color'
|
| 497 |
+
};
|
| 498 |
+
return colorMap[varName] || '';
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
// Initialize the debugger when the page loads
|
| 503 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 504 |
+
new PythonDebugger();
|
| 505 |
+
});
|
| 506 |
+
</script>
|
| 507 |
+
</body>
|
| 508 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_18.html
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 192 |
+
|
| 193 |
+
ul {
|
| 194 |
+
padding-left: 20px;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
li {
|
| 198 |
+
margin-bottom: 12px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.what-to-find {
|
| 202 |
+
margin-top: 20px;
|
| 203 |
+
padding: 15px;
|
| 204 |
+
background-color: #e8f4fd;
|
| 205 |
+
border-radius: 6px;
|
| 206 |
+
border-left: 4px solid #3498db;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.what-to-find h4 {
|
| 210 |
+
color: #2c3e50;
|
| 211 |
+
margin-bottom: 8px;
|
| 212 |
+
}
|
| 213 |
+
.wrong-step {
|
| 214 |
+
display: none;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
</style>
|
| 218 |
+
</head>
|
| 219 |
+
<body>
|
| 220 |
+
<div class="wrong-step">0</div>
|
| 221 |
+
<div class="container">
|
| 222 |
+
<div class="left-panel">
|
| 223 |
+
<div class="problem-statement">
|
| 224 |
+
<div class="section-title">Problem Statement</div>
|
| 225 |
+
<p>
|
| 226 |
+
<span id="fact1" class="fact1-color">Every day, Lou works out by running three miles on a circular track that is one-quarter of a mile long.</span> <span id="fact2" class="fact2-color">His wife, Rosie, also runs on the same track at the same time as her husband, but she runs at twice the speed of her husband.</span> During their workout, how many times does Rosie circle the track?
|
| 227 |
+
</p>
|
| 228 |
+
</div>
|
| 229 |
+
<div class="problem-understanding">
|
| 230 |
+
<div class="section-title">Problem Summary</div>
|
| 231 |
+
<ul>
|
| 232 |
+
<li><span class="fact1-color">Lou's running distance: 3 miles</span></li>
|
| 233 |
+
<li><span class="fact1-color">Track length: 1/4 mile</span></li>
|
| 234 |
+
<li><span class="fact2-color">Rosie's speed: 2 times Lou's speed</span></li>
|
| 235 |
+
</ul>
|
| 236 |
+
<div class="what-to-find">
|
| 237 |
+
<h4>What we need to find</h4>
|
| 238 |
+
<p>During their workout, how many times does Rosie circle the track?</p>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
<div class="right-panel">
|
| 243 |
+
<div class="debugger-controls">
|
| 244 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 245 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 246 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 247 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 248 |
+
</div>
|
| 249 |
+
<div class="python-solution">
|
| 250 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 251 |
+
<div class="python-code" id="python-code">
|
| 252 |
+
<div class="code-line" data-step="0">
|
| 253 |
+
<span class="line-number">1</span>
|
| 254 |
+
<span class="comment"># Calculate how many times Lou circles the track</span>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="code-line" data-step="1">
|
| 257 |
+
<span class="line-number">2</span>
|
| 258 |
+
<span><span class="var1-color">lou_circles</span> = <span class="fact1-color">3</span> / (<span class="fact1-color">1/4</span>)</span>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="code-line" data-step="2">
|
| 261 |
+
<span class="line-number">3</span>
|
| 262 |
+
<span class="comment"># Calculate Rosie's distance based on speed ratio</span>
|
| 263 |
+
</div>
|
| 264 |
+
<div class="code-line" data-step="3">
|
| 265 |
+
<span class="line-number">4</span>
|
| 266 |
+
<span><span class="var2-color">rosie_distance</span> = <span class="fact1-color">3</span> * <span class="fact2-color">2</span></span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="code-line" data-step="4">
|
| 269 |
+
<span class="line-number">5</span>
|
| 270 |
+
<span class="comment"># Calculate how many times Rosie circles the track</span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="5">
|
| 273 |
+
<span class="line-number">6</span>
|
| 274 |
+
<span><span class="var3-color">rosie_circles</span> = <span class="var2-color">rosie_distance</span> / (<span class="fact1-color">1/4</span>)</span>
|
| 275 |
+
</div>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="variables-display" id="variables-display">
|
| 279 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 280 |
+
<div id="variables-list">
|
| 281 |
+
<div class="variable-item">
|
| 282 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 283 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 284 |
+
</div>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
|
| 290 |
+
<script>
|
| 291 |
+
class PythonDebugger {
|
| 292 |
+
constructor() {
|
| 293 |
+
this.currentStep = -1;
|
| 294 |
+
this.isPlaying = false;
|
| 295 |
+
this.playInterval = null;
|
| 296 |
+
this.totalSteps = 5;
|
| 297 |
+
this.variables = {};
|
| 298 |
+
|
| 299 |
+
this.initializeElements();
|
| 300 |
+
this.bindEvents();
|
| 301 |
+
this.updateUI();
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
initializeElements() {
|
| 305 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 306 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 307 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 308 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 309 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 310 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
bindEvents() {
|
| 314 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 315 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 316 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 317 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
togglePlay() {
|
| 321 |
+
if (this.isPlaying) {
|
| 322 |
+
this.pause();
|
| 323 |
+
} else {
|
| 324 |
+
this.play();
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
play() {
|
| 329 |
+
this.isPlaying = true;
|
| 330 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 331 |
+
|
| 332 |
+
if (this.currentStep >= this.totalSteps) {
|
| 333 |
+
this.currentStep = -1;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
this.playInterval = setInterval(() => {
|
| 337 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 338 |
+
if (nextStep !== null) {
|
| 339 |
+
this.currentStep = nextStep;
|
| 340 |
+
this.executeStep(this.currentStep);
|
| 341 |
+
this.updateUI();
|
| 342 |
+
} else {
|
| 343 |
+
this.pause();
|
| 344 |
+
}
|
| 345 |
+
}, 1500);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
pause() {
|
| 349 |
+
this.isPlaying = false;
|
| 350 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 351 |
+
if (this.playInterval) {
|
| 352 |
+
clearInterval(this.playInterval);
|
| 353 |
+
this.playInterval = null;
|
| 354 |
+
}
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
stop() {
|
| 358 |
+
this.pause();
|
| 359 |
+
this.currentStep = -1;
|
| 360 |
+
this.variables = {};
|
| 361 |
+
this.updateUI();
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
nextStep() {
|
| 365 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 366 |
+
if (nextStep !== null) {
|
| 367 |
+
this.currentStep = nextStep;
|
| 368 |
+
this.executeStep(this.currentStep);
|
| 369 |
+
this.updateUI();
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
previousStep() {
|
| 374 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 375 |
+
if (prevStep !== null) {
|
| 376 |
+
this.currentStep = prevStep;
|
| 377 |
+
this.recalculateVariables();
|
| 378 |
+
this.updateUI();
|
| 379 |
+
} else if (this.currentStep !== -1) {
|
| 380 |
+
this.currentStep = -1;
|
| 381 |
+
this.variables = {};
|
| 382 |
+
this.updateUI();
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
executeStep(step) {
|
| 387 |
+
switch(step) {
|
| 388 |
+
case 1:
|
| 389 |
+
this.variables.lou_circles = 3 / (1/4);
|
| 390 |
+
break;
|
| 391 |
+
case 3:
|
| 392 |
+
// This is the wrong step as indicated in the unformatted information
|
| 393 |
+
this.variables.rosie_distance = 3 * 2;
|
| 394 |
+
break;
|
| 395 |
+
case 5:
|
| 396 |
+
this.variables.rosie_circles = this.variables.rosie_distance / (1/4);
|
| 397 |
+
break;
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
getExecutableSteps() {
|
| 402 |
+
// Returns only the steps that execute actual code (not comments)
|
| 403 |
+
return [1, 3, 5];
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
getNextExecutableStep(currentStep) {
|
| 407 |
+
const executableSteps = this.getExecutableSteps();
|
| 408 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 409 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
getPreviousExecutableStep(currentStep) {
|
| 413 |
+
const executableSteps = this.getExecutableSteps();
|
| 414 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 415 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
recalculateVariables() {
|
| 419 |
+
this.variables = {};
|
| 420 |
+
const executableSteps = this.getExecutableSteps();
|
| 421 |
+
for (let step of executableSteps) {
|
| 422 |
+
if (step <= this.currentStep) {
|
| 423 |
+
this.executeStep(step);
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
updateUI() {
|
| 429 |
+
// Update code highlighting
|
| 430 |
+
this.codeLines.forEach((line, index) => {
|
| 431 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 432 |
+
});
|
| 433 |
+
|
| 434 |
+
// Update button states
|
| 435 |
+
const executableSteps = this.getExecutableSteps();
|
| 436 |
+
const isFirstStep = this.currentStep === -1;
|
| 437 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 438 |
+
|
| 439 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 440 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 441 |
+
|
| 442 |
+
// Update variables display
|
| 443 |
+
this.updateVariablesDisplay();
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
updateVariablesDisplay() {
|
| 447 |
+
if (Object.keys(this.variables).length === 0) {
|
| 448 |
+
this.variablesDisplay.innerHTML = `
|
| 449 |
+
<div class="variable-item">
|
| 450 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 451 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 452 |
+
</div>
|
| 453 |
+
`;
|
| 454 |
+
return;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
let html = '';
|
| 458 |
+
const variableOrder = ['lou_circles', 'rosie_distance', 'rosie_circles'];
|
| 459 |
+
|
| 460 |
+
variableOrder.forEach(varName => {
|
| 461 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 462 |
+
const value = this.variables[varName];
|
| 463 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 464 |
+
|
| 465 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 466 |
+
if(varName === lastVarName){
|
| 467 |
+
varName = varName + " (Final Answer)";
|
| 468 |
+
html += `<div class="variable-item ${colorClass}">
|
| 469 |
+
<span class="variable-name">${varName}</span>
|
| 470 |
+
<span class="variable-value">${value}</span>
|
| 471 |
+
</div>`;
|
| 472 |
+
} else {
|
| 473 |
+
html += `<div class="variable-item ${colorClass}">
|
| 474 |
+
<span class="variable-name">${varName}</span>
|
| 475 |
+
<span class="variable-value">${value}</span>
|
| 476 |
+
</div>`;
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
});
|
| 480 |
+
|
| 481 |
+
this.variablesDisplay.innerHTML = html;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
getVariableColorClass(varName) {
|
| 485 |
+
const colorMap = {
|
| 486 |
+
'lou_circles': 'var1-color',
|
| 487 |
+
'rosie_distance': 'var2-color',
|
| 488 |
+
'rosie_circles': 'var3-color'
|
| 489 |
+
};
|
| 490 |
+
return colorMap[varName] || '';
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
// Initialize the debugger when the page loads
|
| 495 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 496 |
+
new PythonDebugger();
|
| 497 |
+
});
|
| 498 |
+
</script>
|
| 499 |
+
</body>
|
| 500 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_19.html
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 192 |
+
|
| 193 |
+
ul {
|
| 194 |
+
padding-left: 20px;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
li {
|
| 198 |
+
margin-bottom: 12px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.what-to-find {
|
| 202 |
+
margin-top: 20px;
|
| 203 |
+
padding: 15px;
|
| 204 |
+
background-color: #e8f4fd;
|
| 205 |
+
border-radius: 6px;
|
| 206 |
+
border-left: 4px solid #3498db;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.what-to-find h4 {
|
| 210 |
+
color: #2c3e50;
|
| 211 |
+
margin-bottom: 8px;
|
| 212 |
+
}
|
| 213 |
+
.wrong-step {
|
| 214 |
+
display: none;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
</style>
|
| 218 |
+
</head>
|
| 219 |
+
<body>
|
| 220 |
+
<div class="wrong-step">0</div>
|
| 221 |
+
<div class="container">
|
| 222 |
+
<div class="left-panel">
|
| 223 |
+
<div class="problem-statement">
|
| 224 |
+
<div class="section-title">Problem Statement</div>
|
| 225 |
+
<p>
|
| 226 |
+
<span id="fact1" class="fact1-color">There are 325 students in a local high school.</span> <span id="fact2" class="fact2-color">40 percent of the students have glasses</span>, how many students do not have glasses?
|
| 227 |
+
</p>
|
| 228 |
+
</div>
|
| 229 |
+
<div class="problem-understanding">
|
| 230 |
+
<div class="section-title">Problem Summary</div>
|
| 231 |
+
<ul>
|
| 232 |
+
<li><span class="fact1-color">Total students: 325</span></li>
|
| 233 |
+
<li><span class="fact2-color">Percentage of students with glasses: 40%</span></li>
|
| 234 |
+
</ul>
|
| 235 |
+
<div class="what-to-find">
|
| 236 |
+
<h4>What we need to find</h4>
|
| 237 |
+
<p>How many students do not have glasses.</p>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
<div class="right-panel">
|
| 242 |
+
<div class="debugger-controls">
|
| 243 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 244 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 245 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 246 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 247 |
+
</div>
|
| 248 |
+
<div class="python-solution">
|
| 249 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 250 |
+
<div class="python-code" id="python-code">
|
| 251 |
+
<div class="code-line" data-step="0">
|
| 252 |
+
<span class="line-number">1</span>
|
| 253 |
+
<span class="comment"># Find the percentage of students who do not have glasses</span>
|
| 254 |
+
</div>
|
| 255 |
+
<div class="code-line" data-step="1">
|
| 256 |
+
<span class="line-number">2</span>
|
| 257 |
+
<span><span class="var1-color">percentage_without_glasses</span> = 100 - <span class="fact2-color">40</span></span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="2">
|
| 260 |
+
<span class="line-number">3</span>
|
| 261 |
+
<span class="comment"># Calculate 10% of the total number of students</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="3">
|
| 264 |
+
<span class="line-number">4</span>
|
| 265 |
+
<span><span class="var2-color">ten_percent</span> = <span class="fact1-color">325</span> * 0.10</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="4">
|
| 268 |
+
<span class="line-number">5</span>
|
| 269 |
+
<span class="comment"># Multiply the 10% value by 6 to get 60% (students without glasses)</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="5">
|
| 272 |
+
<span class="line-number">6</span>
|
| 273 |
+
<span><span class="var3-color">students_without_glasses</span> = <span class="var2-color">ten_percent</span> * 6</span>
|
| 274 |
+
</div>
|
| 275 |
+
</div>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="variables-display" id="variables-display">
|
| 278 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 279 |
+
<div id="variables-list">
|
| 280 |
+
<div class="variable-item">
|
| 281 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 282 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 283 |
+
</div>
|
| 284 |
+
</div>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
|
| 289 |
+
<script>
|
| 290 |
+
class PythonDebugger {
|
| 291 |
+
constructor() {
|
| 292 |
+
this.currentStep = -1;
|
| 293 |
+
this.isPlaying = false;
|
| 294 |
+
this.playInterval = null;
|
| 295 |
+
this.totalSteps = 5;
|
| 296 |
+
this.variables = {};
|
| 297 |
+
|
| 298 |
+
this.initializeElements();
|
| 299 |
+
this.bindEvents();
|
| 300 |
+
this.updateUI();
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
initializeElements() {
|
| 304 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 305 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 306 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 307 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 308 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 309 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
bindEvents() {
|
| 313 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 314 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 315 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 316 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
togglePlay() {
|
| 320 |
+
if (this.isPlaying) {
|
| 321 |
+
this.pause();
|
| 322 |
+
} else {
|
| 323 |
+
this.play();
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
play() {
|
| 328 |
+
this.isPlaying = true;
|
| 329 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 330 |
+
|
| 331 |
+
if (this.currentStep >= this.totalSteps) {
|
| 332 |
+
this.currentStep = -1;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
this.playInterval = setInterval(() => {
|
| 336 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 337 |
+
if (nextStep !== null) {
|
| 338 |
+
this.currentStep = nextStep;
|
| 339 |
+
this.executeStep(this.currentStep);
|
| 340 |
+
this.updateUI();
|
| 341 |
+
} else {
|
| 342 |
+
this.pause();
|
| 343 |
+
}
|
| 344 |
+
}, 1500);
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
pause() {
|
| 348 |
+
this.isPlaying = false;
|
| 349 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 350 |
+
if (this.playInterval) {
|
| 351 |
+
clearInterval(this.playInterval);
|
| 352 |
+
this.playInterval = null;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
stop() {
|
| 357 |
+
this.pause();
|
| 358 |
+
this.currentStep = -1;
|
| 359 |
+
this.variables = {};
|
| 360 |
+
this.updateUI();
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
nextStep() {
|
| 364 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 365 |
+
if (nextStep !== null) {
|
| 366 |
+
this.currentStep = nextStep;
|
| 367 |
+
this.executeStep(this.currentStep);
|
| 368 |
+
this.updateUI();
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
previousStep() {
|
| 373 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 374 |
+
if (prevStep !== null) {
|
| 375 |
+
this.currentStep = prevStep;
|
| 376 |
+
this.recalculateVariables();
|
| 377 |
+
this.updateUI();
|
| 378 |
+
} else if (this.currentStep !== -1) {
|
| 379 |
+
this.currentStep = -1;
|
| 380 |
+
this.variables = {};
|
| 381 |
+
this.updateUI();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
executeStep(step) {
|
| 386 |
+
switch(step) {
|
| 387 |
+
case 1:
|
| 388 |
+
this.variables.percentage_without_glasses = 100 - 40;
|
| 389 |
+
break;
|
| 390 |
+
case 3:
|
| 391 |
+
this.variables.ten_percent = 325 * 0.10;
|
| 392 |
+
break;
|
| 393 |
+
case 5:
|
| 394 |
+
this.variables.students_without_glasses = this.variables.ten_percent * 6;
|
| 395 |
+
break;
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
getExecutableSteps() {
|
| 400 |
+
// Returns only the steps that execute actual code (not comments)
|
| 401 |
+
return [1, 3, 5];
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
getNextExecutableStep(currentStep) {
|
| 405 |
+
const executableSteps = this.getExecutableSteps();
|
| 406 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 407 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
getPreviousExecutableStep(currentStep) {
|
| 411 |
+
const executableSteps = this.getExecutableSteps();
|
| 412 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 413 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
recalculateVariables() {
|
| 417 |
+
this.variables = {};
|
| 418 |
+
const executableSteps = this.getExecutableSteps();
|
| 419 |
+
for (let step of executableSteps) {
|
| 420 |
+
if (step <= this.currentStep) {
|
| 421 |
+
this.executeStep(step);
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
updateUI() {
|
| 427 |
+
// Update code highlighting
|
| 428 |
+
this.codeLines.forEach((line, index) => {
|
| 429 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 430 |
+
});
|
| 431 |
+
|
| 432 |
+
// Update button states
|
| 433 |
+
const executableSteps = this.getExecutableSteps();
|
| 434 |
+
const isFirstStep = this.currentStep === -1;
|
| 435 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 436 |
+
|
| 437 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 438 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 439 |
+
|
| 440 |
+
// Update variables display
|
| 441 |
+
this.updateVariablesDisplay();
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
updateVariablesDisplay() {
|
| 445 |
+
if (Object.keys(this.variables).length === 0) {
|
| 446 |
+
this.variablesDisplay.innerHTML = `
|
| 447 |
+
<div class="variable-item">
|
| 448 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 449 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 450 |
+
</div>
|
| 451 |
+
`;
|
| 452 |
+
return;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
let html = '';
|
| 456 |
+
const variableOrder = ['percentage_without_glasses', 'ten_percent', 'students_without_glasses'];
|
| 457 |
+
|
| 458 |
+
variableOrder.forEach(varName => {
|
| 459 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 460 |
+
const value = this.variables[varName];
|
| 461 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 462 |
+
|
| 463 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 464 |
+
if(varName === lastVarName){
|
| 465 |
+
varName = varName + " (Final Answer)";
|
| 466 |
+
html += `<div class="variable-item ${colorClass}">
|
| 467 |
+
<span class="variable-name">${varName}</span>
|
| 468 |
+
<span class="variable-value">${value}</span>
|
| 469 |
+
</div>`;
|
| 470 |
+
} else {
|
| 471 |
+
html += `<div class="variable-item ${colorClass}">
|
| 472 |
+
<span class="variable-name">${varName}</span>
|
| 473 |
+
<span class="variable-value">${value}</span>
|
| 474 |
+
</div>`;
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
});
|
| 478 |
+
|
| 479 |
+
this.variablesDisplay.innerHTML = html;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
getVariableColorClass(varName) {
|
| 483 |
+
const colorMap = {
|
| 484 |
+
'percentage_without_glasses': 'var1-color',
|
| 485 |
+
'ten_percent': 'var2-color',
|
| 486 |
+
'students_without_glasses': 'var3-color'
|
| 487 |
+
};
|
| 488 |
+
return colorMap[varName] || '';
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// Initialize the debugger when the page loads
|
| 493 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 494 |
+
new PythonDebugger();
|
| 495 |
+
});
|
| 496 |
+
</script>
|
| 497 |
+
</body>
|
| 498 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_2.html
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
|
| 194 |
+
ul {
|
| 195 |
+
padding-left: 20px;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
li {
|
| 199 |
+
margin-bottom: 12px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.what-to-find {
|
| 203 |
+
margin-top: 20px;
|
| 204 |
+
padding: 15px;
|
| 205 |
+
background-color: #e8f4fd;
|
| 206 |
+
border-radius: 6px;
|
| 207 |
+
border-left: 4px solid #3498db;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.what-to-find h4 {
|
| 211 |
+
color: #2c3e50;
|
| 212 |
+
margin-bottom: 8px;
|
| 213 |
+
}
|
| 214 |
+
.wrong-step {
|
| 215 |
+
display: none;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
</style>
|
| 219 |
+
</head>
|
| 220 |
+
<body>
|
| 221 |
+
<div class="wrong-step">0</div>
|
| 222 |
+
<div class="container">
|
| 223 |
+
<div class="left-panel">
|
| 224 |
+
<div class="problem-statement">
|
| 225 |
+
<div class="section-title">Problem Statement</div>
|
| 226 |
+
<p>
|
| 227 |
+
<span id="fact1" class="fact1-color">Jean has 60 stuffies.</span> She keeps <span id="fact2" class="fact2-color">1/3</span> of them and then gives away the rest. She gives <span id="fact3" class="fact3-color">1/4</span> of what she gave away to her sister Janet. How many stuffies did Janet get?
|
| 228 |
+
</p>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="problem-understanding">
|
| 231 |
+
<div class="section-title">Problem Summary</div>
|
| 232 |
+
<ul>
|
| 233 |
+
<li><span class="fact1-color">Total stuffies: 60</span></li>
|
| 234 |
+
<li><span class="fact2-color">Fraction kept: 1/3</span></li>
|
| 235 |
+
<li><span class="fact3-color">Fraction given to Janet: 1/4</span></li>
|
| 236 |
+
</ul>
|
| 237 |
+
<div class="what-to-find">
|
| 238 |
+
<h4>What we need to find</h4>
|
| 239 |
+
<p>How many stuffies Janet received.</p>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
<div class="right-panel">
|
| 244 |
+
<div class="debugger-controls">
|
| 245 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 246 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 247 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 248 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="python-solution">
|
| 251 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 252 |
+
<div class="python-code" id="python-code">
|
| 253 |
+
<div class="code-line" data-step="0">
|
| 254 |
+
<span class="line-number">1</span>
|
| 255 |
+
<span class="comment"># Calculate how many stuffies Jean kept</span>
|
| 256 |
+
</div>
|
| 257 |
+
<div class="code-line" data-step="1">
|
| 258 |
+
<span class="line-number">2</span>
|
| 259 |
+
<span><span class="var1-color">stuffies_kept</span> = <span class="fact1-color">60</span> / <span class="fact2-color">3</span></span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="2">
|
| 262 |
+
<span class="line-number">3</span>
|
| 263 |
+
<span class="comment"># Calculate how many stuffies Jean gave away</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="3">
|
| 266 |
+
<span class="line-number">4</span>
|
| 267 |
+
<span><span class="var2-color">stuffies_given_away</span> = <span class="fact1-color">60</span> - <span class="var1-color">stuffies_kept</span></span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="4">
|
| 270 |
+
<span class="line-number">5</span>
|
| 271 |
+
<span class="comment"># Calculate how many stuffies Janet received</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="5">
|
| 274 |
+
<span class="line-number">6</span>
|
| 275 |
+
<span><span class="var3-color">stuffies_to_janet</span> = <span class="var2-color">stuffies_given_away</span> / <span class="fact3-color">4</span></span>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="variables-display" id="variables-display">
|
| 280 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 281 |
+
<div id="variables-list">
|
| 282 |
+
<div class="variable-item">
|
| 283 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 284 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
|
| 291 |
+
<script>
|
| 292 |
+
class PythonDebugger {
|
| 293 |
+
constructor() {
|
| 294 |
+
this.currentStep = -1;
|
| 295 |
+
this.isPlaying = false;
|
| 296 |
+
this.playInterval = null;
|
| 297 |
+
this.totalSteps = 5;
|
| 298 |
+
this.variables = {};
|
| 299 |
+
|
| 300 |
+
this.initializeElements();
|
| 301 |
+
this.bindEvents();
|
| 302 |
+
this.updateUI();
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
initializeElements() {
|
| 306 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 307 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 308 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 309 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 310 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 311 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
bindEvents() {
|
| 315 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 316 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 317 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 318 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
togglePlay() {
|
| 322 |
+
if (this.isPlaying) {
|
| 323 |
+
this.pause();
|
| 324 |
+
} else {
|
| 325 |
+
this.play();
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
play() {
|
| 330 |
+
this.isPlaying = true;
|
| 331 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 332 |
+
|
| 333 |
+
if (this.currentStep >= this.totalSteps) {
|
| 334 |
+
this.currentStep = -1;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
this.playInterval = setInterval(() => {
|
| 338 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 339 |
+
if (nextStep !== null) {
|
| 340 |
+
this.currentStep = nextStep;
|
| 341 |
+
this.executeStep(this.currentStep);
|
| 342 |
+
this.updateUI();
|
| 343 |
+
} else {
|
| 344 |
+
this.pause();
|
| 345 |
+
}
|
| 346 |
+
}, 1500);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
pause() {
|
| 350 |
+
this.isPlaying = false;
|
| 351 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 352 |
+
if (this.playInterval) {
|
| 353 |
+
clearInterval(this.playInterval);
|
| 354 |
+
this.playInterval = null;
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
stop() {
|
| 359 |
+
this.pause();
|
| 360 |
+
this.currentStep = -1;
|
| 361 |
+
this.variables = {};
|
| 362 |
+
this.updateUI();
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
nextStep() {
|
| 366 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 367 |
+
if (nextStep !== null) {
|
| 368 |
+
this.currentStep = nextStep;
|
| 369 |
+
this.executeStep(this.currentStep);
|
| 370 |
+
this.updateUI();
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
previousStep() {
|
| 375 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 376 |
+
if (prevStep !== null) {
|
| 377 |
+
this.currentStep = prevStep;
|
| 378 |
+
this.recalculateVariables();
|
| 379 |
+
this.updateUI();
|
| 380 |
+
} else if (this.currentStep !== -1) {
|
| 381 |
+
this.currentStep = -1;
|
| 382 |
+
this.variables = {};
|
| 383 |
+
this.updateUI();
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
executeStep(step) {
|
| 388 |
+
switch(step) {
|
| 389 |
+
case 1:
|
| 390 |
+
this.variables.stuffies_kept = 60 / 3;
|
| 391 |
+
break;
|
| 392 |
+
case 3:
|
| 393 |
+
// This is the wrong step as indicated in the unformatted information
|
| 394 |
+
this.variables.stuffies_given_away = 60 - this.variables.stuffies_kept;
|
| 395 |
+
break;
|
| 396 |
+
case 5:
|
| 397 |
+
this.variables.stuffies_to_janet = this.variables.stuffies_given_away / 4;
|
| 398 |
+
break;
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
getExecutableSteps() {
|
| 403 |
+
// Returns only the steps that execute actual code (not comments)
|
| 404 |
+
return [1, 3, 5];
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
getNextExecutableStep(currentStep) {
|
| 408 |
+
const executableSteps = this.getExecutableSteps();
|
| 409 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 410 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
getPreviousExecutableStep(currentStep) {
|
| 414 |
+
const executableSteps = this.getExecutableSteps();
|
| 415 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 416 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
recalculateVariables() {
|
| 420 |
+
this.variables = {};
|
| 421 |
+
const executableSteps = this.getExecutableSteps();
|
| 422 |
+
for (let step of executableSteps) {
|
| 423 |
+
if (step <= this.currentStep) {
|
| 424 |
+
this.executeStep(step);
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
updateUI() {
|
| 430 |
+
// Update code highlighting
|
| 431 |
+
this.codeLines.forEach((line, index) => {
|
| 432 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 433 |
+
});
|
| 434 |
+
|
| 435 |
+
// Update button states
|
| 436 |
+
const executableSteps = this.getExecutableSteps();
|
| 437 |
+
const isFirstStep = this.currentStep === -1;
|
| 438 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 439 |
+
|
| 440 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 441 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 442 |
+
|
| 443 |
+
// Update variables display
|
| 444 |
+
this.updateVariablesDisplay();
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
updateVariablesDisplay() {
|
| 448 |
+
if (Object.keys(this.variables).length === 0) {
|
| 449 |
+
this.variablesDisplay.innerHTML = `
|
| 450 |
+
<div class="variable-item">
|
| 451 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 452 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 453 |
+
</div>
|
| 454 |
+
`;
|
| 455 |
+
return;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
let html = '';
|
| 459 |
+
const variableOrder = ['stuffies_kept', 'stuffies_given_away', 'stuffies_to_janet'];
|
| 460 |
+
|
| 461 |
+
variableOrder.forEach(varName => {
|
| 462 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 463 |
+
const value = this.variables[varName];
|
| 464 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 465 |
+
|
| 466 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 467 |
+
if(varName === lastVarName){
|
| 468 |
+
varName = varName + " (Final Answer)";
|
| 469 |
+
html += `<div class="variable-item ${colorClass}">
|
| 470 |
+
<span class="variable-name">${varName}</span>
|
| 471 |
+
<span class="variable-value">${value}</span>
|
| 472 |
+
</div>`;
|
| 473 |
+
} else {
|
| 474 |
+
html += `<div class="variable-item ${colorClass}">
|
| 475 |
+
<span class="variable-name">${varName}</span>
|
| 476 |
+
<span class="variable-value">${value}</span>
|
| 477 |
+
</div>`;
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
});
|
| 481 |
+
|
| 482 |
+
this.variablesDisplay.innerHTML = html;
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
getVariableColorClass(varName) {
|
| 486 |
+
const colorMap = {
|
| 487 |
+
'stuffies_kept': 'var1-color',
|
| 488 |
+
'stuffies_given_away': 'var2-color',
|
| 489 |
+
'stuffies_to_janet': 'var3-color'
|
| 490 |
+
};
|
| 491 |
+
return colorMap[varName] || '';
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
// Initialize the debugger when the page loads
|
| 496 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 497 |
+
new PythonDebugger();
|
| 498 |
+
});
|
| 499 |
+
</script>
|
| 500 |
+
</body>
|
| 501 |
+
</html>
|
evaluation/eval_interfaces/interactive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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 196 |
+
|
| 197 |
+
ul {
|
| 198 |
+
padding-left: 20px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
li {
|
| 202 |
+
margin-bottom: 12px;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.what-to-find {
|
| 206 |
+
margin-top: 20px;
|
| 207 |
+
padding: 15px;
|
| 208 |
+
background-color: #e8f4fd;
|
| 209 |
+
border-radius: 6px;
|
| 210 |
+
border-left: 4px solid #3498db;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.what-to-find h4 {
|
| 214 |
+
color: #2c3e50;
|
| 215 |
+
margin-bottom: 8px;
|
| 216 |
+
}
|
| 217 |
+
.wrong-step {
|
| 218 |
+
display: none;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
</style>
|
| 222 |
+
</head>
|
| 223 |
+
<body>
|
| 224 |
+
<div class="wrong-step">0</div>
|
| 225 |
+
<div class="container">
|
| 226 |
+
<div class="left-panel">
|
| 227 |
+
<div class="problem-statement">
|
| 228 |
+
<div class="section-title">Problem Statement</div>
|
| 229 |
+
<p>
|
| 230 |
+
A party of <span id="fact1" class="fact1-color">4</span> order <span id="fact2" class="fact2-color">3 dozen oysters on the half shell for $15.00 a dozen</span>, <span id="fact3" class="fact3-color">2 pounds of steamed shrimp for $14.00 a pound</span> and <span id="fact4" class="fact4-color">2 pounds of fried clams for $13.50 a pound</span>. If they split the bill equally, how much will they each owe?
|
| 231 |
+
</p>
|
| 232 |
+
</div>
|
| 233 |
+
<div class="problem-understanding">
|
| 234 |
+
<div class="section-title">Problem Summary</div>
|
| 235 |
+
<ul>
|
| 236 |
+
<li><span class="fact1-color">Number of people: 4</span></li>
|
| 237 |
+
<li><span class="fact2-color">Oysters: 3 dozen at $15.00 per dozen</span></li>
|
| 238 |
+
<li><span class="fact3-color">Shrimp: 2 pounds at $14.00 per pound</span></li>
|
| 239 |
+
<li><span class="fact4-color">Fried clams: 2 pounds at $13.50 per pound</span></li>
|
| 240 |
+
</ul>
|
| 241 |
+
<div class="what-to-find">
|
| 242 |
+
<h4>What we need to find:</h4>
|
| 243 |
+
<p>How much each person will owe when splitting the bill equally.</p>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="right-panel">
|
| 248 |
+
<div class="debugger-controls">
|
| 249 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 250 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 251 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 252 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="python-solution">
|
| 255 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 256 |
+
<div class="python-code" id="python-code">
|
| 257 |
+
<div class="code-line" data-step="0">
|
| 258 |
+
<span class="line-number">1</span>
|
| 259 |
+
<span class="comment"># Calculate cost of oysters</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="1">
|
| 262 |
+
<span class="line-number">2</span>
|
| 263 |
+
<span><span class="var1-color">oyster_cost</span> = <span class="fact2-color">3</span> * <span class="fact2-color">15.00</span></span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="2">
|
| 266 |
+
<span class="line-number">3</span>
|
| 267 |
+
<span class="comment"># Calculate cost of shrimp</span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="3">
|
| 270 |
+
<span class="line-number">4</span>
|
| 271 |
+
<span><span class="var2-color">shrimp_cost</span> = <span class="fact3-color">2</span> * <span class="fact3-color">14.00</span></span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="4">
|
| 274 |
+
<span class="line-number">5</span>
|
| 275 |
+
<span class="comment"># Calculate cost of fried clams</span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="5">
|
| 278 |
+
<span class="line-number">6</span>
|
| 279 |
+
<span><span class="var3-color">clam_cost</span> = <span class="fact4-color">2</span> * <span class="fact4-color">13.50</span></span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="6">
|
| 282 |
+
<span class="line-number">7</span>
|
| 283 |
+
<span class="comment"># Calculate total bill</span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="7">
|
| 286 |
+
<span class="line-number">8</span>
|
| 287 |
+
<span><span class="var4-color">total_bill</span> = <span class="var1-color">oyster_cost</span> + <span class="var2-color">shrimp_cost</span> + <span class="var3-color">clam_cost</span></span>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="code-line" data-step="8">
|
| 290 |
+
<span class="line-number">9</span>
|
| 291 |
+
<span class="comment"># Calculate cost per person</span>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="code-line" data-step="9">
|
| 294 |
+
<span class="line-number">10</span>
|
| 295 |
+
<span><span class="var5-color">cost_per_person</span> = <span class="var4-color">total_bill</span> / <span class="fact1-color">4</span></span>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="variables-display" id="variables-display">
|
| 300 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 301 |
+
<div id="variables-list">
|
| 302 |
+
<div class="variable-item">
|
| 303 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 304 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
|
| 311 |
+
<script>
|
| 312 |
+
class PythonDebugger {
|
| 313 |
+
constructor() {
|
| 314 |
+
this.currentStep = -1;
|
| 315 |
+
this.isPlaying = false;
|
| 316 |
+
this.playInterval = null;
|
| 317 |
+
this.totalSteps = 9;
|
| 318 |
+
this.variables = {};
|
| 319 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 320 |
+
|
| 321 |
+
this.initializeElements();
|
| 322 |
+
this.bindEvents();
|
| 323 |
+
this.updateUI();
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
initializeElements() {
|
| 327 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 328 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 329 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 330 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 331 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 332 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
bindEvents() {
|
| 336 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 337 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 338 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 339 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
togglePlay() {
|
| 343 |
+
if (this.isPlaying) {
|
| 344 |
+
this.pause();
|
| 345 |
+
} else {
|
| 346 |
+
this.play();
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
play() {
|
| 351 |
+
this.isPlaying = true;
|
| 352 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 353 |
+
|
| 354 |
+
if (this.currentStep >= this.totalSteps) {
|
| 355 |
+
this.currentStep = -1;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
this.playInterval = setInterval(() => {
|
| 359 |
+
if (this.currentStep < this.totalSteps) {
|
| 360 |
+
this.nextStep();
|
| 361 |
+
} else {
|
| 362 |
+
this.pause();
|
| 363 |
+
}
|
| 364 |
+
}, 1500);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
pause() {
|
| 368 |
+
this.isPlaying = false;
|
| 369 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 370 |
+
if (this.playInterval) {
|
| 371 |
+
clearInterval(this.playInterval);
|
| 372 |
+
this.playInterval = null;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
stop() {
|
| 377 |
+
this.pause();
|
| 378 |
+
this.currentStep = -1;
|
| 379 |
+
this.variables = {};
|
| 380 |
+
this.updateUI();
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
nextStep() {
|
| 384 |
+
if (this.currentStep < this.totalSteps) {
|
| 385 |
+
this.currentStep++;
|
| 386 |
+
this.executeStep(this.currentStep);
|
| 387 |
+
this.updateUI();
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
previousStep() {
|
| 392 |
+
if (this.currentStep > 0) {
|
| 393 |
+
this.currentStep--;
|
| 394 |
+
this.recalculateVariables();
|
| 395 |
+
this.updateUI();
|
| 396 |
+
} else if (this.currentStep === 0) {
|
| 397 |
+
this.currentStep = -1;
|
| 398 |
+
this.variables = {};
|
| 399 |
+
this.updateUI();
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
executeStep(step) {
|
| 404 |
+
switch(step) {
|
| 405 |
+
case 1:
|
| 406 |
+
this.variables.oyster_cost = 3 * 15.00;
|
| 407 |
+
break;
|
| 408 |
+
case 3:
|
| 409 |
+
this.variables.shrimp_cost = 2 * 14.00;
|
| 410 |
+
break;
|
| 411 |
+
case 5:
|
| 412 |
+
// This is the wrong step according to the unformatted information
|
| 413 |
+
this.variables.clam_cost = 2 * 13.50;
|
| 414 |
+
break;
|
| 415 |
+
case 7:
|
| 416 |
+
this.variables.total_bill = this.variables.oyster_cost + this.variables.shrimp_cost + this.variables.clam_cost;
|
| 417 |
+
break;
|
| 418 |
+
case 9:
|
| 419 |
+
this.variables.cost_per_person = this.variables.total_bill / 4;
|
| 420 |
+
break;
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
recalculateVariables() {
|
| 425 |
+
this.variables = {};
|
| 426 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 427 |
+
if (i % 2 === 1) { // Only execute code lines, not comments
|
| 428 |
+
this.executeStep(i);
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
updateUI() {
|
| 434 |
+
// Update code highlighting
|
| 435 |
+
this.codeLines.forEach((line, index) => {
|
| 436 |
+
line.classList.remove('current');
|
| 437 |
+
if (index === this.currentStep) {
|
| 438 |
+
line.classList.add('current');
|
| 439 |
+
}
|
| 440 |
+
});
|
| 441 |
+
|
| 442 |
+
// Update button states
|
| 443 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= 0);
|
| 444 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 445 |
+
|
| 446 |
+
// Update variables display
|
| 447 |
+
this.updateVariablesDisplay();
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
updateVariablesDisplay() {
|
| 451 |
+
if (Object.keys(this.variables).length === 0) {
|
| 452 |
+
this.variablesDisplay.innerHTML = `
|
| 453 |
+
<div class="variable-item">
|
| 454 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 455 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 456 |
+
</div>
|
| 457 |
+
`;
|
| 458 |
+
return;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
let html = '';
|
| 462 |
+
const variableOrder = ['oyster_cost', 'shrimp_cost', 'clam_cost', 'total_bill', 'cost_per_person'];
|
| 463 |
+
|
| 464 |
+
variableOrder.forEach(varName => {
|
| 465 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 466 |
+
const value = this.variables[varName];
|
| 467 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 468 |
+
let displayValue = value;
|
| 469 |
+
|
| 470 |
+
// Format currency values
|
| 471 |
+
if (varName.includes('cost') || varName.includes('bill')) {
|
| 472 |
+
displayValue = `$${value.toFixed(2)}`;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 476 |
+
if(varName === lastVarName){
|
| 477 |
+
varName = varName + " (Final Answer)";
|
| 478 |
+
html += `<div class="variable-item ${colorClass}">
|
| 479 |
+
<span class="variable-name">${varName}</span>
|
| 480 |
+
<span class="variable-value">${value}</span>
|
| 481 |
+
</div>`;
|
| 482 |
+
} else {
|
| 483 |
+
html += `<div class="variable-item ${colorClass}">
|
| 484 |
+
<span class="variable-name">${varName}</span>
|
| 485 |
+
<span class="variable-value">${value}</span>
|
| 486 |
+
</div>`;
|
| 487 |
+
}
|
| 488 |
+
}
|
| 489 |
+
});
|
| 490 |
+
|
| 491 |
+
this.variablesDisplay.innerHTML = html;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
getVariableColorClass(varName) {
|
| 495 |
+
const colorMap = {
|
| 496 |
+
'oyster_cost': 'var1-color',
|
| 497 |
+
'shrimp_cost': 'var2-color',
|
| 498 |
+
'clam_cost': 'var3-color',
|
| 499 |
+
'total_bill': 'var4-color',
|
| 500 |
+
'cost_per_person': 'var5-color'
|
| 501 |
+
};
|
| 502 |
+
return colorMap[varName] || '';
|
| 503 |
+
}
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
// Initialize the debugger when the page loads
|
| 507 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 508 |
+
new PythonDebugger();
|
| 509 |
+
});
|
| 510 |
+
</script>
|
| 511 |
+
</body>
|
| 512 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_21.html
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 192 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 193 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
.wrong-step {
|
| 216 |
+
display: none;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Ms. Warren ran at 6 mph for 20 minutes.</span> <span id="fact2" class="fact2-color">After the run, she walked at 2 mph for 30 minutes.</span> How many miles did she run and walk in total?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Running speed: 6 mph</span></li>
|
| 235 |
+
<li><span class="fact1-color">Running time: 20 minutes</span></li>
|
| 236 |
+
<li><span class="fact2-color">Walking speed: 2 mph</span></li>
|
| 237 |
+
<li><span class="fact2-color">Walking time: 30 minutes</span></li>
|
| 238 |
+
</ul>
|
| 239 |
+
<div class="what-to-find">
|
| 240 |
+
<h4>What we need to find</h4>
|
| 241 |
+
<p>How many miles did Ms. Warren run and walk in total?</p>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="right-panel">
|
| 246 |
+
<div class="debugger-controls">
|
| 247 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 248 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 249 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 250 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="python-solution">
|
| 253 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 254 |
+
<div class="python-code" id="python-code">
|
| 255 |
+
<div class="code-line" data-step="0">
|
| 256 |
+
<span class="line-number">1</span>
|
| 257 |
+
<span class="comment"># Convert running time from minutes to hours</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">2</span>
|
| 261 |
+
<span><span class="var1-color">running_time_hours</span> = <span class="fact1-color">20</span> / 60</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">3</span>
|
| 265 |
+
<span class="comment"># Calculate the distance Ms. Warren ran</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">4</span>
|
| 269 |
+
<span><span class="var2-color">running_distance</span> = <span class="fact1-color">6</span> / 3</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">5</span>
|
| 273 |
+
<span class="comment"># Convert walking time from minutes to hours</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">6</span>
|
| 277 |
+
<span><span class="var3-color">walking_time_hours</span> = <span class="fact2-color">30</span> / 60</span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="6">
|
| 280 |
+
<span class="line-number">7</span>
|
| 281 |
+
<span class="comment"># Calculate the distance Ms. Warren walked</span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="7">
|
| 284 |
+
<span class="line-number">8</span>
|
| 285 |
+
<span><span class="var4-color">walking_distance</span> = <span class="fact2-color">2</span> * <span class="var3-color">walking_time_hours</span></span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="8">
|
| 288 |
+
<span class="line-number">9</span>
|
| 289 |
+
<span class="comment"># Calculate the total distance</span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="9">
|
| 292 |
+
<span class="line-number">10</span>
|
| 293 |
+
<span><span class="var5-color">total_distance</span> = <span class="var2-color">running_distance</span> + <span class="var4-color">walking_distance</span></span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
<div class="variables-display" id="variables-display">
|
| 298 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 299 |
+
<div id="variables-list">
|
| 300 |
+
<div class="variable-item">
|
| 301 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 302 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
|
| 309 |
+
<script>
|
| 310 |
+
class PythonDebugger {
|
| 311 |
+
constructor() {
|
| 312 |
+
this.currentStep = -1;
|
| 313 |
+
this.isPlaying = false;
|
| 314 |
+
this.playInterval = null;
|
| 315 |
+
this.totalSteps = 9;
|
| 316 |
+
this.variables = {};
|
| 317 |
+
|
| 318 |
+
this.initializeElements();
|
| 319 |
+
this.bindEvents();
|
| 320 |
+
this.updateUI();
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
initializeElements() {
|
| 324 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 325 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 326 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 327 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 328 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 329 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
bindEvents() {
|
| 333 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 334 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 335 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 336 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
togglePlay() {
|
| 340 |
+
if (this.isPlaying) {
|
| 341 |
+
this.pause();
|
| 342 |
+
} else {
|
| 343 |
+
this.play();
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
play() {
|
| 348 |
+
this.isPlaying = true;
|
| 349 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 350 |
+
|
| 351 |
+
if (this.currentStep >= this.totalSteps) {
|
| 352 |
+
this.currentStep = -1;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
this.playInterval = setInterval(() => {
|
| 356 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 357 |
+
if (nextStep !== null) {
|
| 358 |
+
this.currentStep = nextStep;
|
| 359 |
+
this.executeStep(this.currentStep);
|
| 360 |
+
this.updateUI();
|
| 361 |
+
} else {
|
| 362 |
+
this.pause();
|
| 363 |
+
}
|
| 364 |
+
}, 1500);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
pause() {
|
| 368 |
+
this.isPlaying = false;
|
| 369 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 370 |
+
if (this.playInterval) {
|
| 371 |
+
clearInterval(this.playInterval);
|
| 372 |
+
this.playInterval = null;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
stop() {
|
| 377 |
+
this.pause();
|
| 378 |
+
this.currentStep = -1;
|
| 379 |
+
this.variables = {};
|
| 380 |
+
this.updateUI();
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
nextStep() {
|
| 384 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 385 |
+
if (nextStep !== null) {
|
| 386 |
+
this.currentStep = nextStep;
|
| 387 |
+
this.executeStep(this.currentStep);
|
| 388 |
+
this.updateUI();
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
previousStep() {
|
| 393 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 394 |
+
if (prevStep !== null) {
|
| 395 |
+
this.currentStep = prevStep;
|
| 396 |
+
this.recalculateVariables();
|
| 397 |
+
this.updateUI();
|
| 398 |
+
} else if (this.currentStep !== -1) {
|
| 399 |
+
this.currentStep = -1;
|
| 400 |
+
this.variables = {};
|
| 401 |
+
this.updateUI();
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
executeStep(step) {
|
| 406 |
+
switch(step) {
|
| 407 |
+
case 1:
|
| 408 |
+
this.variables.running_time_hours = 20 / 60;
|
| 409 |
+
break;
|
| 410 |
+
case 3:
|
| 411 |
+
// Intentionally keeping the error as per instructions
|
| 412 |
+
this.variables.running_distance = 6 / 3;
|
| 413 |
+
break;
|
| 414 |
+
case 5:
|
| 415 |
+
this.variables.walking_time_hours = 30 / 60;
|
| 416 |
+
break;
|
| 417 |
+
case 7:
|
| 418 |
+
this.variables.walking_distance = 2 * this.variables.walking_time_hours;
|
| 419 |
+
break;
|
| 420 |
+
case 9:
|
| 421 |
+
this.variables.total_distance = this.variables.running_distance + this.variables.walking_distance;
|
| 422 |
+
break;
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
getExecutableSteps() {
|
| 427 |
+
// Returns only the steps that execute actual code (not comments)
|
| 428 |
+
return [1, 3, 5, 7, 9];
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
getNextExecutableStep(currentStep) {
|
| 432 |
+
const executableSteps = this.getExecutableSteps();
|
| 433 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 434 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
getPreviousExecutableStep(currentStep) {
|
| 438 |
+
const executableSteps = this.getExecutableSteps();
|
| 439 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 440 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
recalculateVariables() {
|
| 444 |
+
this.variables = {};
|
| 445 |
+
const executableSteps = this.getExecutableSteps();
|
| 446 |
+
for (let step of executableSteps) {
|
| 447 |
+
if (step <= this.currentStep) {
|
| 448 |
+
this.executeStep(step);
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
updateUI() {
|
| 454 |
+
// Update code highlighting
|
| 455 |
+
this.codeLines.forEach((line, index) => {
|
| 456 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 457 |
+
});
|
| 458 |
+
|
| 459 |
+
// Update button states
|
| 460 |
+
const executableSteps = this.getExecutableSteps();
|
| 461 |
+
const isFirstStep = this.currentStep === -1;
|
| 462 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 463 |
+
|
| 464 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 465 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 466 |
+
|
| 467 |
+
// Update variables display
|
| 468 |
+
this.updateVariablesDisplay();
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
updateVariablesDisplay() {
|
| 472 |
+
if (Object.keys(this.variables).length === 0) {
|
| 473 |
+
this.variablesDisplay.innerHTML = `
|
| 474 |
+
<div class="variable-item">
|
| 475 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 476 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 477 |
+
</div>
|
| 478 |
+
`;
|
| 479 |
+
return;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
let html = '';
|
| 483 |
+
const variableOrder = ['running_time_hours', 'running_distance', 'walking_time_hours', 'walking_distance', 'total_distance'];
|
| 484 |
+
|
| 485 |
+
variableOrder.forEach(varName => {
|
| 486 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 487 |
+
const value = this.variables[varName];
|
| 488 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 489 |
+
|
| 490 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 491 |
+
if(varName === lastVarName){
|
| 492 |
+
varName = varName + " (Final Answer)";
|
| 493 |
+
html += `<div class="variable-item ${colorClass}">
|
| 494 |
+
<span class="variable-name">${varName}</span>
|
| 495 |
+
<span class="variable-value">${value}</span>
|
| 496 |
+
</div>`;
|
| 497 |
+
} else {
|
| 498 |
+
html += `<div class="variable-item ${colorClass}">
|
| 499 |
+
<span class="variable-name">${varName}</span>
|
| 500 |
+
<span class="variable-value">${value}</span>
|
| 501 |
+
</div>`;
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
});
|
| 505 |
+
|
| 506 |
+
this.variablesDisplay.innerHTML = html;
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
getVariableColorClass(varName) {
|
| 510 |
+
const colorMap = {
|
| 511 |
+
'running_time_hours': 'var1-color',
|
| 512 |
+
'running_distance': 'var2-color',
|
| 513 |
+
'walking_time_hours': 'var3-color',
|
| 514 |
+
'walking_distance': 'var4-color',
|
| 515 |
+
'total_distance': 'var5-color'
|
| 516 |
+
};
|
| 517 |
+
return colorMap[varName] || '';
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
// Initialize the debugger when the page loads
|
| 522 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 523 |
+
new PythonDebugger();
|
| 524 |
+
});
|
| 525 |
+
</script>
|
| 526 |
+
</body>
|
| 527 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_22.html
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 193 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 194 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 196 |
+
.var5-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
Jimmy wants to order a pizza at a new place. <span id="fact1" class="fact1-color">The large pizza costs $10.00</span> and is <span id="fact2" class="fact2-color">cut into 8 slices</span>. <span id="fact3" class="fact3-color">The first topping costs $2.00</span>, <span id="fact4" class="fact4-color">the next 2 toppings cost $1.00 each</span> and <span id="fact5" class="fact5-color">the rest of the toppings cost $0.50</span>. If he orders a large pizza with pepperoni, sausage, ham, olives, mushrooms, bell peppers and pineapple. How much will his pizza cost per slice?
|
| 232 |
+
</p>
|
| 233 |
+
</div>
|
| 234 |
+
<div class="problem-understanding">
|
| 235 |
+
<div class="section-title">Problem Summary</div>
|
| 236 |
+
<ul>
|
| 237 |
+
<li><span class="fact1-color">Large pizza cost: $10.00</span></li>
|
| 238 |
+
<li><span class="fact2-color">Number of slices: 8</span></li>
|
| 239 |
+
<li><span class="fact3-color">First topping cost: $2.00</span></li>
|
| 240 |
+
<li><span class="fact4-color">Next 2 toppings cost: $1.00 each</span></li>
|
| 241 |
+
<li><span class="fact5-color">Remaining toppings cost: $0.50 each</span></li>
|
| 242 |
+
</ul>
|
| 243 |
+
<div class="what-to-find">
|
| 244 |
+
<h4>What we need to find:</h4>
|
| 245 |
+
<p>How much will Jimmy's pizza cost per slice?</p>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
</div>
|
| 249 |
+
<div class="right-panel">
|
| 250 |
+
<div class="debugger-controls">
|
| 251 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 252 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 253 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 254 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="python-solution">
|
| 257 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 258 |
+
<div class="python-code" id="python-code">
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">1</span>
|
| 261 |
+
<span class="comment"># Calculate initial cost with base pizza and first topping</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">2</span>
|
| 265 |
+
<span><span class="var1-color">initial_cost</span> = <span class="fact1-color">10</span> + <span class="fact3-color">2</span></span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">3</span>
|
| 269 |
+
<span class="comment"># Calculate cost of the next 2 toppings</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">4</span>
|
| 273 |
+
<span><span class="var2-color">middle_toppings_cost</span> = 2 * <span class="fact4-color">1</span></span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">5</span>
|
| 277 |
+
<span class="comment"># Calculate cost of the remaining toppings</span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="6">
|
| 280 |
+
<span class="line-number">6</span>
|
| 281 |
+
<span><span class="var3-color">remaining_toppings_cost</span> = 4 * <span class="fact5-color">0.50</span></span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="7">
|
| 284 |
+
<span class="line-number">7</span>
|
| 285 |
+
<span class="comment"># Calculate total cost of the pizza with all toppings</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="8">
|
| 288 |
+
<span class="line-number">8</span>
|
| 289 |
+
<span><span class="var4-color">total_cost</span> = <span class="var1-color">initial_cost</span> + <span class="var2-color">middle_toppings_cost</span> + <span class="var3-color">remaining_toppings_cost</span></span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="9">
|
| 292 |
+
<span class="line-number">9</span>
|
| 293 |
+
<span class="comment"># Calculate cost per slice</span>
|
| 294 |
+
</div>
|
| 295 |
+
<div class="code-line" data-step="10">
|
| 296 |
+
<span class="line-number">10</span>
|
| 297 |
+
<span><span class="var5-color">cost_per_slice</span> = <span class="var4-color">total_cost</span> / <span class="fact2-color">8</span></span>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
<div class="variables-display" id="variables-display">
|
| 302 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 303 |
+
<div id="variables-list">
|
| 304 |
+
<div class="variable-item">
|
| 305 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 306 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
|
| 313 |
+
<script>
|
| 314 |
+
class PythonDebugger {
|
| 315 |
+
constructor() {
|
| 316 |
+
this.currentStep = -1;
|
| 317 |
+
this.isPlaying = false;
|
| 318 |
+
this.playInterval = null;
|
| 319 |
+
this.totalSteps = 10;
|
| 320 |
+
this.variables = {};
|
| 321 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 322 |
+
|
| 323 |
+
this.initializeElements();
|
| 324 |
+
this.bindEvents();
|
| 325 |
+
this.updateUI();
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
initializeElements() {
|
| 329 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 330 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 331 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 332 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 333 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 334 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
bindEvents() {
|
| 338 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 339 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 340 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 341 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
togglePlay() {
|
| 345 |
+
if (this.isPlaying) {
|
| 346 |
+
this.pause();
|
| 347 |
+
} else {
|
| 348 |
+
this.play();
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
play() {
|
| 353 |
+
this.isPlaying = true;
|
| 354 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 355 |
+
|
| 356 |
+
if (this.currentStep >= this.totalSteps - 1) {
|
| 357 |
+
this.currentStep = -1;
|
| 358 |
+
this.variables = {};
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
this.playInterval = setInterval(() => {
|
| 362 |
+
if (this.currentStep < this.totalSteps - 1) {
|
| 363 |
+
this.nextStep();
|
| 364 |
+
} else {
|
| 365 |
+
this.pause();
|
| 366 |
+
}
|
| 367 |
+
}, 1500);
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
pause() {
|
| 371 |
+
this.isPlaying = false;
|
| 372 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 373 |
+
if (this.playInterval) {
|
| 374 |
+
clearInterval(this.playInterval);
|
| 375 |
+
this.playInterval = null;
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
stop() {
|
| 380 |
+
this.pause();
|
| 381 |
+
this.currentStep = -1;
|
| 382 |
+
this.variables = {};
|
| 383 |
+
this.updateUI();
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
nextStep() {
|
| 387 |
+
if (this.currentStep < this.totalSteps - 1) {
|
| 388 |
+
this.currentStep++;
|
| 389 |
+
this.executeStep(this.currentStep);
|
| 390 |
+
this.updateUI();
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
previousStep() {
|
| 395 |
+
if (this.currentStep > 0) {
|
| 396 |
+
this.currentStep--;
|
| 397 |
+
this.recalculateVariables();
|
| 398 |
+
this.updateUI();
|
| 399 |
+
} else if (this.currentStep === 0) {
|
| 400 |
+
this.currentStep = -1;
|
| 401 |
+
this.variables = {};
|
| 402 |
+
this.updateUI();
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
executeStep(step) {
|
| 407 |
+
switch(step) {
|
| 408 |
+
case 1: // Comment line
|
| 409 |
+
break;
|
| 410 |
+
case 2: // initial_cost = 10 + 2
|
| 411 |
+
this.variables.initial_cost = 10 + 2;
|
| 412 |
+
break;
|
| 413 |
+
case 3: // Comment line
|
| 414 |
+
break;
|
| 415 |
+
case 4: // middle_toppings_cost = 2 * 1
|
| 416 |
+
this.variables.middle_toppings_cost = 2 * 1;
|
| 417 |
+
break;
|
| 418 |
+
case 5: // Comment line
|
| 419 |
+
break;
|
| 420 |
+
case 6: // remaining_toppings_cost = 4 * 0.50
|
| 421 |
+
// This is the wrong step (step 3 in the unformatted info)
|
| 422 |
+
if (this.wrongStep === 3) {
|
| 423 |
+
this.variables.remaining_toppings_cost = 4 * 0.50;
|
| 424 |
+
} else {
|
| 425 |
+
this.variables.remaining_toppings_cost = 4 * 0.50;
|
| 426 |
+
}
|
| 427 |
+
break;
|
| 428 |
+
case 7: // Comment line
|
| 429 |
+
break;
|
| 430 |
+
case 8: // total_cost = initial_cost + middle_toppings_cost + remaining_toppings_cost
|
| 431 |
+
this.variables.total_cost = this.variables.initial_cost + this.variables.middle_toppings_cost + this.variables.remaining_toppings_cost;
|
| 432 |
+
break;
|
| 433 |
+
case 9: // Comment line
|
| 434 |
+
break;
|
| 435 |
+
case 10: // cost_per_slice = total_cost / 8
|
| 436 |
+
this.variables.cost_per_slice = this.variables.total_cost / 8;
|
| 437 |
+
break;
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
recalculateVariables() {
|
| 442 |
+
this.variables = {};
|
| 443 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 444 |
+
this.executeStep(i);
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
updateUI() {
|
| 449 |
+
// Update code highlighting
|
| 450 |
+
this.codeLines.forEach((line, index) => {
|
| 451 |
+
line.classList.remove('current');
|
| 452 |
+
if (index === this.currentStep) {
|
| 453 |
+
line.classList.add('current');
|
| 454 |
+
}
|
| 455 |
+
});
|
| 456 |
+
|
| 457 |
+
// Update button states
|
| 458 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 459 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep === this.totalSteps - 1);
|
| 460 |
+
|
| 461 |
+
// Update variables display
|
| 462 |
+
this.updateVariablesDisplay();
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
updateVariablesDisplay() {
|
| 466 |
+
if (Object.keys(this.variables).length === 0) {
|
| 467 |
+
this.variablesDisplay.innerHTML = `
|
| 468 |
+
<div class="variable-item">
|
| 469 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 470 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 471 |
+
</div>
|
| 472 |
+
`;
|
| 473 |
+
return;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
let html = '';
|
| 477 |
+
const variableOrder = ['initial_cost', 'middle_toppings_cost', 'remaining_toppings_cost', 'total_cost', 'cost_per_slice'];
|
| 478 |
+
const colorClasses = {
|
| 479 |
+
'initial_cost': 'var1-color',
|
| 480 |
+
'middle_toppings_cost': 'var2-color',
|
| 481 |
+
'remaining_toppings_cost': 'var3-color',
|
| 482 |
+
'total_cost': 'var4-color',
|
| 483 |
+
'cost_per_slice': 'var5-color'
|
| 484 |
+
};
|
| 485 |
+
|
| 486 |
+
variableOrder.forEach(varName => {
|
| 487 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 488 |
+
const value = this.variables[varName];
|
| 489 |
+
const formattedValue = varName === 'cost_per_slice' ? `$${value.toFixed(2)}` : `$${value.toFixed(2)}`;
|
| 490 |
+
|
| 491 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 492 |
+
if(varName === lastVarName){
|
| 493 |
+
varName = varName + " (Final Answer)";
|
| 494 |
+
html += `<div class="variable-item ${colorClass}">
|
| 495 |
+
<span class="variable-name">${varName}</span>
|
| 496 |
+
<span class="variable-value">${value}</span>
|
| 497 |
+
</div>`;
|
| 498 |
+
} else {
|
| 499 |
+
html += `<div class="variable-item ${colorClass}">
|
| 500 |
+
<span class="variable-name">${varName}</span>
|
| 501 |
+
<span class="variable-value">${value}</span>
|
| 502 |
+
</div>`;
|
| 503 |
+
}
|
| 504 |
+
}
|
| 505 |
+
});
|
| 506 |
+
|
| 507 |
+
this.variablesDisplay.innerHTML = html;
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Initialize the debugger when the page loads
|
| 512 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 513 |
+
new PythonDebugger();
|
| 514 |
+
});
|
| 515 |
+
</script>
|
| 516 |
+
</body>
|
| 517 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_23.html
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.fact7-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var1-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 196 |
+
.var3-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var4-color { background-color: rgba(63, 81, 181, 0.5); }
|
| 198 |
+
|
| 199 |
+
ul {
|
| 200 |
+
padding-left: 20px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
li {
|
| 204 |
+
margin-bottom: 12px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.what-to-find {
|
| 208 |
+
margin-top: 20px;
|
| 209 |
+
padding: 15px;
|
| 210 |
+
background-color: #e8f4fd;
|
| 211 |
+
border-radius: 6px;
|
| 212 |
+
border-left: 4px solid #3498db;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.what-to-find h4 {
|
| 216 |
+
color: #2c3e50;
|
| 217 |
+
margin-bottom: 8px;
|
| 218 |
+
}
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
</style>
|
| 224 |
+
</head>
|
| 225 |
+
<body>
|
| 226 |
+
<div class="wrong-step">0</div>
|
| 227 |
+
<div class="container">
|
| 228 |
+
<div class="left-panel">
|
| 229 |
+
<div class="problem-statement">
|
| 230 |
+
<div class="section-title">Problem Statement</div>
|
| 231 |
+
<p>
|
| 232 |
+
<span id="fact1" class="fact1-color">A pet store owner had 12 birds</span>, <span id="fact2" class="fact2-color">9 puppies</span>, <span id="fact3" class="fact3-color">5 cats</span>, and <span id="fact4" class="fact4-color">15 spiders</span>. <span id="fact5" class="fact5-color">Half the birds were sold</span> and <span id="fact6" class="fact6-color">3 puppies were adopted</span>. Then, someone left the spider enclosure open and <span id="fact7" class="fact7-color">7 of them went loose</span>. How many animals does the pet store owner have left?
|
| 233 |
+
</p>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="problem-understanding">
|
| 236 |
+
<div class="section-title">Problem Summary</div>
|
| 237 |
+
<ul>
|
| 238 |
+
<li><span class="fact1-color">Starting birds: 12</span></li>
|
| 239 |
+
<li><span class="fact2-color">Starting puppies: 9</span></li>
|
| 240 |
+
<li><span class="fact3-color">Starting cats: 5</span></li>
|
| 241 |
+
<li><span class="fact4-color">Starting spiders: 15</span></li>
|
| 242 |
+
<li><span class="fact5-color">Birds sold: 1/2 of total</span></li>
|
| 243 |
+
<li><span class="fact6-color">Puppies adopted: 3</span></li>
|
| 244 |
+
<li><span class="fact7-color">Spiders escaped: 7</span></li>
|
| 245 |
+
</ul>
|
| 246 |
+
<div class="what-to-find">
|
| 247 |
+
<h4>What we need to find:</h4>
|
| 248 |
+
<p>How many animals does the pet store owner have left?</p>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="right-panel">
|
| 253 |
+
<div class="debugger-controls">
|
| 254 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 255 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 256 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 257 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="python-solution">
|
| 260 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 261 |
+
<div class="python-code" id="python-code">
|
| 262 |
+
<div class="code-line" data-step="0">
|
| 263 |
+
<span class="line-number">1</span>
|
| 264 |
+
<span class="comment"># Calculate how many birds are left after half were sold</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="1">
|
| 267 |
+
<span class="line-number">2</span>
|
| 268 |
+
<span><span class="var1-color">birds_left</span> = <span class="fact1-color">12</span> // <span class="fact5-color">2</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="2">
|
| 271 |
+
<span class="line-number">3</span>
|
| 272 |
+
<span class="comment"># Calculate how many puppies are left after 3 were adopted</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="3">
|
| 275 |
+
<span class="line-number">4</span>
|
| 276 |
+
<span><span class="var2-color">puppies_left</span> = <span class="fact2-color">9</span> - <span class="fact6-color">3</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="4">
|
| 279 |
+
<span class="line-number">5</span>
|
| 280 |
+
<span class="comment"># Calculate how many spiders are left after 7 escaped</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="5">
|
| 283 |
+
<span class="line-number">6</span>
|
| 284 |
+
<span><span class="var3-color">spiders_left</span> = <span class="fact4-color">15</span> - <span class="fact7-color">7</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="6">
|
| 287 |
+
<span class="line-number">7</span>
|
| 288 |
+
<span class="comment"># Calculate the total number of animals left</span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="7">
|
| 291 |
+
<span class="line-number">8</span>
|
| 292 |
+
<span><span class="var4-color">total_animals_left</span> = <span class="fact3-color">5</span> + <span class="var1-color">birds_left</span> + <span class="var2-color">puppies_left</span> + <span class="var3-color">spiders_left</span></span>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
<div class="variables-display" id="variables-display">
|
| 297 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 298 |
+
<div id="variables-list">
|
| 299 |
+
<div class="variable-item">
|
| 300 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 301 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 302 |
+
</div>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
|
| 308 |
+
<script>
|
| 309 |
+
class PythonDebugger {
|
| 310 |
+
constructor() {
|
| 311 |
+
this.currentStep = -1;
|
| 312 |
+
this.isPlaying = false;
|
| 313 |
+
this.playInterval = null;
|
| 314 |
+
this.totalSteps = 7;
|
| 315 |
+
this.variables = {};
|
| 316 |
+
|
| 317 |
+
this.initializeElements();
|
| 318 |
+
this.bindEvents();
|
| 319 |
+
this.updateUI();
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
initializeElements() {
|
| 323 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 324 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 325 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 326 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 327 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 328 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
bindEvents() {
|
| 332 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 333 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 334 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 335 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
togglePlay() {
|
| 339 |
+
if (this.isPlaying) {
|
| 340 |
+
this.pause();
|
| 341 |
+
} else {
|
| 342 |
+
this.play();
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
play() {
|
| 347 |
+
this.isPlaying = true;
|
| 348 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 349 |
+
|
| 350 |
+
if (this.currentStep >= 7) {
|
| 351 |
+
this.currentStep = -1;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
this.playInterval = setInterval(() => {
|
| 355 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 356 |
+
if (nextStep !== null) {
|
| 357 |
+
this.currentStep = nextStep;
|
| 358 |
+
this.executeStep(this.currentStep);
|
| 359 |
+
this.updateUI();
|
| 360 |
+
} else {
|
| 361 |
+
this.pause();
|
| 362 |
+
}
|
| 363 |
+
}, 1500);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
pause() {
|
| 367 |
+
this.isPlaying = false;
|
| 368 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 369 |
+
if (this.playInterval) {
|
| 370 |
+
clearInterval(this.playInterval);
|
| 371 |
+
this.playInterval = null;
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
stop() {
|
| 376 |
+
this.pause();
|
| 377 |
+
this.currentStep = -1;
|
| 378 |
+
this.variables = {};
|
| 379 |
+
this.updateUI();
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
nextStep() {
|
| 383 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 384 |
+
if (nextStep !== null) {
|
| 385 |
+
this.currentStep = nextStep;
|
| 386 |
+
this.executeStep(this.currentStep);
|
| 387 |
+
this.updateUI();
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
previousStep() {
|
| 392 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 393 |
+
if (prevStep !== null) {
|
| 394 |
+
this.currentStep = prevStep;
|
| 395 |
+
this.recalculateVariables();
|
| 396 |
+
this.updateUI();
|
| 397 |
+
} else if (this.currentStep !== -1) {
|
| 398 |
+
this.currentStep = -1;
|
| 399 |
+
this.variables = {};
|
| 400 |
+
this.updateUI();
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
executeStep(step) {
|
| 405 |
+
switch(step) {
|
| 406 |
+
case 1:
|
| 407 |
+
this.variables.birds_left = Math.floor(12 / 2);
|
| 408 |
+
break;
|
| 409 |
+
case 3:
|
| 410 |
+
this.variables.puppies_left = 9 - 3;
|
| 411 |
+
break;
|
| 412 |
+
case 5:
|
| 413 |
+
// This is the wrong step as indicated
|
| 414 |
+
this.variables.spiders_left = 15 - 7;
|
| 415 |
+
break;
|
| 416 |
+
case 7:
|
| 417 |
+
this.variables.total_animals_left = 5 + this.variables.birds_left + this.variables.puppies_left + this.variables.spiders_left;
|
| 418 |
+
break;
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
getExecutableSteps() {
|
| 423 |
+
// Returns only the steps that execute actual code (not comments)
|
| 424 |
+
return [1, 3, 5, 7];
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
getNextExecutableStep(currentStep) {
|
| 428 |
+
const executableSteps = this.getExecutableSteps();
|
| 429 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 430 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
getPreviousExecutableStep(currentStep) {
|
| 434 |
+
const executableSteps = this.getExecutableSteps();
|
| 435 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 436 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
recalculateVariables() {
|
| 440 |
+
this.variables = {};
|
| 441 |
+
const executableSteps = this.getExecutableSteps();
|
| 442 |
+
for (let step of executableSteps) {
|
| 443 |
+
if (step <= this.currentStep) {
|
| 444 |
+
this.executeStep(step);
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
updateUI() {
|
| 450 |
+
// Update code highlighting
|
| 451 |
+
this.codeLines.forEach((line, index) => {
|
| 452 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 453 |
+
});
|
| 454 |
+
|
| 455 |
+
// Update button states
|
| 456 |
+
const executableSteps = this.getExecutableSteps();
|
| 457 |
+
const isFirstStep = this.currentStep === -1;
|
| 458 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 459 |
+
|
| 460 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 461 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 462 |
+
|
| 463 |
+
// Update variables display
|
| 464 |
+
this.updateVariablesDisplay();
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
updateVariablesDisplay() {
|
| 468 |
+
if (Object.keys(this.variables).length === 0) {
|
| 469 |
+
this.variablesDisplay.innerHTML = `
|
| 470 |
+
<div class="variable-item">
|
| 471 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 472 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 473 |
+
</div>
|
| 474 |
+
`;
|
| 475 |
+
return;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
let html = '';
|
| 479 |
+
const variableOrder = ['birds_left', 'puppies_left', 'spiders_left', 'total_animals_left'];
|
| 480 |
+
|
| 481 |
+
variableOrder.forEach(varName => {
|
| 482 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 483 |
+
const value = this.variables[varName];
|
| 484 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 485 |
+
|
| 486 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 487 |
+
if(varName === lastVarName){
|
| 488 |
+
varName = varName + " (Final Answer)";
|
| 489 |
+
html += `<div class="variable-item ${colorClass}">
|
| 490 |
+
<span class="variable-name">${varName}</span>
|
| 491 |
+
<span class="variable-value">${value}</span>
|
| 492 |
+
</div>`;
|
| 493 |
+
} else {
|
| 494 |
+
html += `<div class="variable-item ${colorClass}">
|
| 495 |
+
<span class="variable-name">${varName}</span>
|
| 496 |
+
<span class="variable-value">${value}</span>
|
| 497 |
+
</div>`;
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
});
|
| 501 |
+
|
| 502 |
+
this.variablesDisplay.innerHTML = html;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
getVariableColorClass(varName) {
|
| 506 |
+
const colorMap = {
|
| 507 |
+
'birds_left': 'var1-color',
|
| 508 |
+
'puppies_left': 'var2-color',
|
| 509 |
+
'spiders_left': 'var3-color',
|
| 510 |
+
'total_animals_left': 'var4-color'
|
| 511 |
+
};
|
| 512 |
+
return colorMap[varName] || '';
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
// Initialize the debugger when the page loads
|
| 517 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 518 |
+
new PythonDebugger();
|
| 519 |
+
});
|
| 520 |
+
</script>
|
| 521 |
+
</body>
|
| 522 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_24.html
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Annie has 6 barrettes</span>, <span id="fact2" class="fact2-color">twice as many scrunchies as barrettes</span>, and <span id="fact3" class="fact3-color">three fewer bobby pins than barrettes</span>. What percentage of her hair decorations are bobby pins, rounded to the nearest percent?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Barrettes: 6</span></li>
|
| 235 |
+
<li><span class="fact2-color">Scrunchies: twice as many as barrettes</span></li>
|
| 236 |
+
<li><span class="fact3-color">Bobby pins: three fewer than barrettes</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find:</h4>
|
| 240 |
+
<p>The percentage of hair decorations that are bobby pins, rounded to the nearest percent.</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># First find the total number of scrunchies</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">scrunchies</span> = <span class="fact1-color">6</span> * 2</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Then subtract three fewer bobby pins than barrettes</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">bobby_pins</span> = <span class="fact1-color">6</span> - 3</span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Then add the number of each type of hair decorations to find the total number</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">total_decorations</span> = <span class="fact1-color">6</span> + <span class="var1-color">scrunchies</span> + <span class="var2-color">bobby_pins</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="6">
|
| 279 |
+
<span class="line-number">7</span>
|
| 280 |
+
<span class="comment"># Then divide the number of bobby pins by the total number of decorations and multiply by 100% to express the answer as a percentage</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="7">
|
| 283 |
+
<span class="line-number">8</span>
|
| 284 |
+
<span><span class="var4-color">percentage</span> = (<span class="var2-color">bobby_pins</span> / <span class="var3-color">total_decorations</span>) * 100</span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="variables-display" id="variables-display">
|
| 289 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 290 |
+
<div id="variables-list">
|
| 291 |
+
<div class="variable-item">
|
| 292 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 293 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
class PythonDebugger {
|
| 302 |
+
constructor() {
|
| 303 |
+
this.currentStep = -1;
|
| 304 |
+
this.isPlaying = false;
|
| 305 |
+
this.playInterval = null;
|
| 306 |
+
this.totalSteps = 7;
|
| 307 |
+
this.variables = {};
|
| 308 |
+
|
| 309 |
+
this.initializeElements();
|
| 310 |
+
this.bindEvents();
|
| 311 |
+
this.updateUI();
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
initializeElements() {
|
| 315 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 316 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 317 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 318 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 319 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 320 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
bindEvents() {
|
| 324 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 325 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 326 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 327 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
togglePlay() {
|
| 331 |
+
if (this.isPlaying) {
|
| 332 |
+
this.pause();
|
| 333 |
+
} else {
|
| 334 |
+
this.play();
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
play() {
|
| 339 |
+
this.isPlaying = true;
|
| 340 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 341 |
+
|
| 342 |
+
if (this.currentStep >= this.totalSteps) {
|
| 343 |
+
this.currentStep = -1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
this.playInterval = setInterval(() => {
|
| 347 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 348 |
+
if (nextStep !== null) {
|
| 349 |
+
this.currentStep = nextStep;
|
| 350 |
+
this.executeStep(this.currentStep);
|
| 351 |
+
this.updateUI();
|
| 352 |
+
} else {
|
| 353 |
+
this.pause();
|
| 354 |
+
}
|
| 355 |
+
}, 1500);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
pause() {
|
| 359 |
+
this.isPlaying = false;
|
| 360 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 361 |
+
if (this.playInterval) {
|
| 362 |
+
clearInterval(this.playInterval);
|
| 363 |
+
this.playInterval = null;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
stop() {
|
| 368 |
+
this.pause();
|
| 369 |
+
this.currentStep = -1;
|
| 370 |
+
this.variables = {};
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
nextStep() {
|
| 375 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 376 |
+
if (nextStep !== null) {
|
| 377 |
+
this.currentStep = nextStep;
|
| 378 |
+
this.executeStep(this.currentStep);
|
| 379 |
+
this.updateUI();
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
previousStep() {
|
| 384 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 385 |
+
if (prevStep !== null) {
|
| 386 |
+
this.currentStep = prevStep;
|
| 387 |
+
this.recalculateVariables();
|
| 388 |
+
this.updateUI();
|
| 389 |
+
} else if (this.currentStep !== -1) {
|
| 390 |
+
this.currentStep = -1;
|
| 391 |
+
this.variables = {};
|
| 392 |
+
this.updateUI();
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
executeStep(step) {
|
| 397 |
+
switch(step) {
|
| 398 |
+
case 1:
|
| 399 |
+
this.variables.scrunchies = 6 * 2;
|
| 400 |
+
break;
|
| 401 |
+
case 3:
|
| 402 |
+
// This is the wrong step - it should be 6 - 3 = 3
|
| 403 |
+
this.variables.bobby_pins = 6 - 3;
|
| 404 |
+
break;
|
| 405 |
+
case 5:
|
| 406 |
+
this.variables.total_decorations = 6 + this.variables.scrunchies + this.variables.bobby_pins;
|
| 407 |
+
break;
|
| 408 |
+
case 7:
|
| 409 |
+
this.variables.percentage = (this.variables.bobby_pins / this.variables.total_decorations) * 100;
|
| 410 |
+
break;
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
getExecutableSteps() {
|
| 415 |
+
// Returns only the steps that execute actual code (not comments)
|
| 416 |
+
return [1, 3, 5, 7];
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
getNextExecutableStep(currentStep) {
|
| 420 |
+
const executableSteps = this.getExecutableSteps();
|
| 421 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 422 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
getPreviousExecutableStep(currentStep) {
|
| 426 |
+
const executableSteps = this.getExecutableSteps();
|
| 427 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 428 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
recalculateVariables() {
|
| 432 |
+
this.variables = {};
|
| 433 |
+
const executableSteps = this.getExecutableSteps();
|
| 434 |
+
for (let step of executableSteps) {
|
| 435 |
+
if (step <= this.currentStep) {
|
| 436 |
+
this.executeStep(step);
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
updateUI() {
|
| 442 |
+
// Update code highlighting
|
| 443 |
+
this.codeLines.forEach((line, index) => {
|
| 444 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 445 |
+
});
|
| 446 |
+
|
| 447 |
+
// Update button states
|
| 448 |
+
const executableSteps = this.getExecutableSteps();
|
| 449 |
+
const isFirstStep = this.currentStep === -1;
|
| 450 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 451 |
+
|
| 452 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 453 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 454 |
+
|
| 455 |
+
// Update variables display
|
| 456 |
+
this.updateVariablesDisplay();
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
updateVariablesDisplay() {
|
| 460 |
+
if (Object.keys(this.variables).length === 0) {
|
| 461 |
+
this.variablesDisplay.innerHTML = `
|
| 462 |
+
<div class="variable-item">
|
| 463 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 464 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 465 |
+
</div>
|
| 466 |
+
`;
|
| 467 |
+
return;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
let html = '';
|
| 471 |
+
const variableOrder = ['scrunchies', 'bobby_pins', 'total_decorations', 'percentage'];
|
| 472 |
+
|
| 473 |
+
variableOrder.forEach(varName => {
|
| 474 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 475 |
+
const value = this.variables[varName];
|
| 476 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 477 |
+
const displayValue = varName === 'percentage' ? `${value.toFixed(2)}%` : value;
|
| 478 |
+
|
| 479 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 480 |
+
if(varName === lastVarName){
|
| 481 |
+
varName = varName + " (Final Answer)";
|
| 482 |
+
html += `<div class="variable-item ${colorClass}">
|
| 483 |
+
<span class="variable-name">${varName}</span>
|
| 484 |
+
<span class="variable-value">${value}</span>
|
| 485 |
+
</div>`;
|
| 486 |
+
} else {
|
| 487 |
+
html += `<div class="variable-item ${colorClass}">
|
| 488 |
+
<span class="variable-name">${varName}</span>
|
| 489 |
+
<span class="variable-value">${value}</span>
|
| 490 |
+
</div>`;
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
});
|
| 494 |
+
|
| 495 |
+
this.variablesDisplay.innerHTML = html;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
getVariableColorClass(varName) {
|
| 499 |
+
const colorMap = {
|
| 500 |
+
'scrunchies': 'var1-color',
|
| 501 |
+
'bobby_pins': 'var2-color',
|
| 502 |
+
'total_decorations': 'var3-color',
|
| 503 |
+
'percentage': 'var4-color'
|
| 504 |
+
};
|
| 505 |
+
return colorMap[varName] || '';
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
// Initialize the debugger when the page loads
|
| 510 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 511 |
+
new PythonDebugger();
|
| 512 |
+
});
|
| 513 |
+
</script>
|
| 514 |
+
</body>
|
| 515 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_25.html
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
.wrong-step {
|
| 216 |
+
display: none;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
The total number of <span id="fact1" class="fact1-color">lions in a park is twice the number of leopards in the same park</span>. The <span id="fact2" class="fact2-color">number of elephants is half the combined number of lions and leopards</span>. Calculate the total population of the three animals in the park if the <span id="fact3" class="fact3-color">number of lions is 200</span>.
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Lions : 2 × leopards</span></li>
|
| 235 |
+
<li><span class="fact2-color">Elephants : 0.5 × (lions + leopards)</span></li>
|
| 236 |
+
<li><span class="fact3-color">Lions : 200</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find:</h4>
|
| 240 |
+
<p>Calculate the total population of the three animals (lions, leopards, and elephants) in the park.</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># Calculate the number of leopards from the number of lions</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">leopards</span> = <span class="fact3-color">200</span> / 2</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Calculate the total population of lions and leopards</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">lions_and_leopards</span> = <span class="fact3-color">200</span> + <span class="var1-color">leopards</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Calculate the number of elephants</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">elephants</span> = <span class="var2-color">lions_and_leopards</span> * (1/2)</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="6">
|
| 279 |
+
<span class="line-number">7</span>
|
| 280 |
+
<span class="comment"># Calculate the total population of all three animals</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="7">
|
| 283 |
+
<span class="line-number">8</span>
|
| 284 |
+
<span><span class="var4-color">total_animals</span> = <span class="var3-color">elephants</span> + <span class="var2-color">lions_and_leopards</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="variables-display" id="variables-display">
|
| 289 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 290 |
+
<div id="variables-list">
|
| 291 |
+
<div class="variable-item">
|
| 292 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 293 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
class PythonDebugger {
|
| 302 |
+
constructor() {
|
| 303 |
+
this.currentStep = -1;
|
| 304 |
+
this.isPlaying = false;
|
| 305 |
+
this.playInterval = null;
|
| 306 |
+
this.totalSteps = 7;
|
| 307 |
+
this.variables = {};
|
| 308 |
+
|
| 309 |
+
this.initializeElements();
|
| 310 |
+
this.bindEvents();
|
| 311 |
+
this.updateUI();
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
initializeElements() {
|
| 315 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 316 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 317 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 318 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 319 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 320 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
bindEvents() {
|
| 324 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 325 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 326 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 327 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
togglePlay() {
|
| 331 |
+
if (this.isPlaying) {
|
| 332 |
+
this.pause();
|
| 333 |
+
} else {
|
| 334 |
+
this.play();
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
play() {
|
| 339 |
+
this.isPlaying = true;
|
| 340 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 341 |
+
|
| 342 |
+
if (this.currentStep >= this.totalSteps) {
|
| 343 |
+
this.currentStep = -1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
this.playInterval = setInterval(() => {
|
| 347 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 348 |
+
if (nextStep !== null) {
|
| 349 |
+
this.currentStep = nextStep;
|
| 350 |
+
this.executeStep(this.currentStep);
|
| 351 |
+
this.updateUI();
|
| 352 |
+
} else {
|
| 353 |
+
this.pause();
|
| 354 |
+
}
|
| 355 |
+
}, 1500);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
pause() {
|
| 359 |
+
this.isPlaying = false;
|
| 360 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 361 |
+
if (this.playInterval) {
|
| 362 |
+
clearInterval(this.playInterval);
|
| 363 |
+
this.playInterval = null;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
stop() {
|
| 368 |
+
this.pause();
|
| 369 |
+
this.currentStep = -1;
|
| 370 |
+
this.variables = {};
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
nextStep() {
|
| 375 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 376 |
+
if (nextStep !== null) {
|
| 377 |
+
this.currentStep = nextStep;
|
| 378 |
+
this.executeStep(this.currentStep);
|
| 379 |
+
this.updateUI();
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
previousStep() {
|
| 384 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 385 |
+
if (prevStep !== null) {
|
| 386 |
+
this.currentStep = prevStep;
|
| 387 |
+
this.recalculateVariables();
|
| 388 |
+
this.updateUI();
|
| 389 |
+
} else if (this.currentStep !== -1) {
|
| 390 |
+
this.currentStep = -1;
|
| 391 |
+
this.variables = {};
|
| 392 |
+
this.updateUI();
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
executeStep(step) {
|
| 397 |
+
switch(step) {
|
| 398 |
+
case 1:
|
| 399 |
+
this.variables.leopards = 200 / 2;
|
| 400 |
+
break;
|
| 401 |
+
case 3:
|
| 402 |
+
this.variables.lions_and_leopards = 200 + this.variables.leopards;
|
| 403 |
+
break;
|
| 404 |
+
case 5:
|
| 405 |
+
this.variables.elephants = this.variables.lions_and_leopards * (1/2);
|
| 406 |
+
break;
|
| 407 |
+
case 7:
|
| 408 |
+
this.variables.total_animals = this.variables.elephants + this.variables.lions_and_leopards;
|
| 409 |
+
break;
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
getExecutableSteps() {
|
| 414 |
+
// Returns only the steps that execute actual code (not comments)
|
| 415 |
+
return [1, 3, 5, 7];
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
getNextExecutableStep(currentStep) {
|
| 419 |
+
const executableSteps = this.getExecutableSteps();
|
| 420 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 421 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
getPreviousExecutableStep(currentStep) {
|
| 425 |
+
const executableSteps = this.getExecutableSteps();
|
| 426 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 427 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
recalculateVariables() {
|
| 431 |
+
this.variables = {};
|
| 432 |
+
const executableSteps = this.getExecutableSteps();
|
| 433 |
+
for (let step of executableSteps) {
|
| 434 |
+
if (step <= this.currentStep) {
|
| 435 |
+
this.executeStep(step);
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
updateUI() {
|
| 441 |
+
// Update code highlighting
|
| 442 |
+
this.codeLines.forEach((line, index) => {
|
| 443 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 444 |
+
});
|
| 445 |
+
|
| 446 |
+
// Update button states
|
| 447 |
+
const executableSteps = this.getExecutableSteps();
|
| 448 |
+
const isFirstStep = this.currentStep === -1;
|
| 449 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 450 |
+
|
| 451 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 452 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 453 |
+
|
| 454 |
+
// Update variables display
|
| 455 |
+
this.updateVariablesDisplay();
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
updateVariablesDisplay() {
|
| 459 |
+
if (Object.keys(this.variables).length === 0) {
|
| 460 |
+
this.variablesDisplay.innerHTML = `
|
| 461 |
+
<div class="variable-item">
|
| 462 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 463 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 464 |
+
</div>
|
| 465 |
+
`;
|
| 466 |
+
return;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
let html = '';
|
| 470 |
+
const variableOrder = ['leopards', 'lions_and_leopards', 'elephants', 'total_animals'];
|
| 471 |
+
|
| 472 |
+
variableOrder.forEach(varName => {
|
| 473 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 474 |
+
const value = this.variables[varName];
|
| 475 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 476 |
+
|
| 477 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 478 |
+
if(varName === lastVarName){
|
| 479 |
+
varName = varName + " (Final Answer)";
|
| 480 |
+
html += `<div class="variable-item ${colorClass}">
|
| 481 |
+
<span class="variable-name">${varName}</span>
|
| 482 |
+
<span class="variable-value">${value}</span>
|
| 483 |
+
</div>`;
|
| 484 |
+
} else {
|
| 485 |
+
html += `<div class="variable-item ${colorClass}">
|
| 486 |
+
<span class="variable-name">${varName}</span>
|
| 487 |
+
<span class="variable-value">${value}</span>
|
| 488 |
+
</div>`;
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
|
| 493 |
+
this.variablesDisplay.innerHTML = html;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
getVariableColorClass(varName) {
|
| 497 |
+
const colorMap = {
|
| 498 |
+
'leopards': 'var1-color',
|
| 499 |
+
'lions_and_leopards': 'var2-color',
|
| 500 |
+
'elephants': 'var3-color',
|
| 501 |
+
'total_animals': 'var4-color'
|
| 502 |
+
};
|
| 503 |
+
return colorMap[varName] || '';
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// Initialize the debugger when the page loads
|
| 508 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 509 |
+
new PythonDebugger();
|
| 510 |
+
});
|
| 511 |
+
</script>
|
| 512 |
+
</body>
|
| 513 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_26.html
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 195 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 196 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var5-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 198 |
+
|
| 199 |
+
ul {
|
| 200 |
+
padding-left: 20px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
li {
|
| 204 |
+
margin-bottom: 12px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.what-to-find {
|
| 208 |
+
margin-top: 20px;
|
| 209 |
+
padding: 15px;
|
| 210 |
+
background-color: #e8f4fd;
|
| 211 |
+
border-radius: 6px;
|
| 212 |
+
border-left: 4px solid #3498db;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.what-to-find h4 {
|
| 216 |
+
color: #2c3e50;
|
| 217 |
+
margin-bottom: 8px;
|
| 218 |
+
}
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
</style>
|
| 224 |
+
</head>
|
| 225 |
+
<body>
|
| 226 |
+
<div class="wrong-step">0</div>
|
| 227 |
+
<div class="container">
|
| 228 |
+
<div class="left-panel">
|
| 229 |
+
<div class="problem-statement">
|
| 230 |
+
<div class="section-title">Problem Statement</div>
|
| 231 |
+
<p>
|
| 232 |
+
<span id="fact1" class="fact1-color">Janice can type 6 sentences per minute.</span> Today at work, Janice continued working on a paper she started typing yesterday. <span id="fact2" class="fact2-color">She typed for 20 minutes</span>, took a break, and <span id="fact3" class="fact3-color">typed 15 minutes longer</span>. <span id="fact4" class="fact4-color">She then had to erase 40 sentences she had typed incorrectly.</span> After a meeting, <span id="fact5" class="fact5-color">she typed for 18 minutes more</span>. <span id="fact6" class="fact6-color">In all, the paper had 536 sentences by the end of today.</span> How many sentences did she start with today?
|
| 233 |
+
</p>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="problem-understanding">
|
| 236 |
+
<div class="section-title">Problem Summary</div>
|
| 237 |
+
<ul>
|
| 238 |
+
<li><span class="fact1-color">Typing speed: 6 sentences per minute</span></li>
|
| 239 |
+
<li><span class="fact2-color">First typing session: 20 minutes</span></li>
|
| 240 |
+
<li><span class="fact3-color">Second typing session: 15 minutes</span></li>
|
| 241 |
+
<li><span class="fact4-color">Erased sentences: 40 sentences</span></li>
|
| 242 |
+
<li><span class="fact5-color">Third typing session: 18 minutes</span></li>
|
| 243 |
+
<li><span class="fact6-color">Final sentence count: 536 sentences</span></li>
|
| 244 |
+
</ul>
|
| 245 |
+
<div class="what-to-find">
|
| 246 |
+
<h4>What we need to find:</h4>
|
| 247 |
+
<p>How many sentences did Janice start with today (from yesterday's work).</p>
|
| 248 |
+
</div>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="right-panel">
|
| 252 |
+
<div class="debugger-controls">
|
| 253 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 254 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 255 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 256 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="python-solution">
|
| 259 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 260 |
+
<div class="python-code" id="python-code">
|
| 261 |
+
<div class="code-line" data-step="0">
|
| 262 |
+
<span class="line-number">1</span>
|
| 263 |
+
<span class="comment"># Janice had X sentences from yesterday already typed to start with today</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="1">
|
| 266 |
+
<span class="line-number">2</span>
|
| 267 |
+
<span><span class="var1-color">X</span> = 0 # Unknown starting sentences</span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="2">
|
| 270 |
+
<span class="line-number">3</span>
|
| 271 |
+
<span class="comment"># Janice typed 6 * 20 = 120 sentences before her break</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="3">
|
| 274 |
+
<span class="line-number">4</span>
|
| 275 |
+
<span><span class="var2-color">first_session</span> = <span class="fact1-color">6</span> * <span class="fact2-color">20</span></span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="4">
|
| 278 |
+
<span class="line-number">5</span>
|
| 279 |
+
<span class="comment"># She typed 6 * 15 = 90 sentences after her break</span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="5">
|
| 282 |
+
<span class="line-number">6</span>
|
| 283 |
+
<span><span class="var3-color">second_session</span> = <span class="fact1-color">6</span> * <span class="fact3-color">15</span></span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="6">
|
| 286 |
+
<span class="line-number">7</span>
|
| 287 |
+
<span class="comment"># She typed 6 * 18 = 108 sentences after her meeting</span>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="code-line" data-step="7">
|
| 290 |
+
<span class="line-number">8</span>
|
| 291 |
+
<span><span class="var4-color">third_session</span> = <span class="fact1-color">6</span> * <span class="fact5-color">18</span></span>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="code-line" data-step="8">
|
| 294 |
+
<span class="line-number">9</span>
|
| 295 |
+
<span class="comment"># Therefore, she typed 120 + 90 + 108 = 318 sentences today in all</span>
|
| 296 |
+
</div>
|
| 297 |
+
<div class="code-line" data-step="9">
|
| 298 |
+
<span class="line-number">10</span>
|
| 299 |
+
<span><span class="var5-color">total_typed_today</span> = <span class="var2-color">first_session</span> + <span class="var3-color">second_session</span> + <span class="var4-color">third_session</span></span>
|
| 300 |
+
</div>
|
| 301 |
+
<div class="code-line" data-step="10">
|
| 302 |
+
<span class="line-number">11</span>
|
| 303 |
+
<span class="comment"># She had to erase 40 sentences, so she had 318 - 40 = 278 sentences that she typed today left</span>
|
| 304 |
+
</div>
|
| 305 |
+
<div class="code-line" data-step="11">
|
| 306 |
+
<span class="line-number">12</span>
|
| 307 |
+
<span><span class="var1-color">net_added_today</span> = <span class="var5-color">total_typed_today</span> - <span class="fact4-color">40</span></span>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="code-line" data-step="12">
|
| 310 |
+
<span class="line-number">13</span>
|
| 311 |
+
<span class="comment"># The paper had X + 278 = 536 sentences at the end of today</span>
|
| 312 |
+
</div>
|
| 313 |
+
<div class="code-line" data-step="13">
|
| 314 |
+
<span class="line-number">14</span>
|
| 315 |
+
<span><span class="fact6-color">final_count</span> = <span class="var1-color">X</span> + <span class="var1-color">net_added_today</span></span>
|
| 316 |
+
</div>
|
| 317 |
+
<div class="code-line" data-step="14">
|
| 318 |
+
<span class="line-number">15</span>
|
| 319 |
+
<span class="comment"># Thus, she had X = 536 - 278 = 258 sentences typed on the paper to start with today</span>
|
| 320 |
+
</div>
|
| 321 |
+
<div class="code-line" data-step="15">
|
| 322 |
+
<span class="line-number">16</span>
|
| 323 |
+
<span><span class="var1-color">X</span> = <span class="fact6-color">536</span> - <span class="var1-color">net_added_today</span></span>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
<div class="variables-display" id="variables-display">
|
| 328 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 329 |
+
<div id="variables-list">
|
| 330 |
+
<div class="variable-item">
|
| 331 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 332 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 333 |
+
</div>
|
| 334 |
+
</div>
|
| 335 |
+
</div>
|
| 336 |
+
</div>
|
| 337 |
+
</div>
|
| 338 |
+
|
| 339 |
+
<script>
|
| 340 |
+
class PythonDebugger {
|
| 341 |
+
constructor() {
|
| 342 |
+
this.currentStep = -1;
|
| 343 |
+
this.isPlaying = false;
|
| 344 |
+
this.playInterval = null;
|
| 345 |
+
this.totalSteps = 15;
|
| 346 |
+
this.variables = {};
|
| 347 |
+
|
| 348 |
+
this.initializeElements();
|
| 349 |
+
this.bindEvents();
|
| 350 |
+
this.updateUI();
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
initializeElements() {
|
| 354 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 355 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 356 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 357 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 358 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 359 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
bindEvents() {
|
| 363 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 364 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 365 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 366 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
togglePlay() {
|
| 370 |
+
if (this.isPlaying) {
|
| 371 |
+
this.pause();
|
| 372 |
+
} else {
|
| 373 |
+
this.play();
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
play() {
|
| 378 |
+
this.isPlaying = true;
|
| 379 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 380 |
+
|
| 381 |
+
if (this.currentStep >= this.totalSteps) {
|
| 382 |
+
this.currentStep = -1;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
this.playInterval = setInterval(() => {
|
| 386 |
+
if (this.currentStep < this.totalSteps) {
|
| 387 |
+
this.nextStep();
|
| 388 |
+
} else {
|
| 389 |
+
this.pause();
|
| 390 |
+
}
|
| 391 |
+
}, 1500);
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
pause() {
|
| 395 |
+
this.isPlaying = false;
|
| 396 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 397 |
+
if (this.playInterval) {
|
| 398 |
+
clearInterval(this.playInterval);
|
| 399 |
+
this.playInterval = null;
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
stop() {
|
| 404 |
+
this.pause();
|
| 405 |
+
this.currentStep = -1;
|
| 406 |
+
this.variables = {};
|
| 407 |
+
this.updateUI();
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
nextStep() {
|
| 411 |
+
if (this.currentStep < this.totalSteps) {
|
| 412 |
+
this.currentStep++;
|
| 413 |
+
this.executeStep(this.currentStep);
|
| 414 |
+
this.updateUI();
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
previousStep() {
|
| 419 |
+
if (this.currentStep > 0) {
|
| 420 |
+
this.currentStep--;
|
| 421 |
+
this.recalculateVariables();
|
| 422 |
+
this.updateUI();
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
executeStep(step) {
|
| 427 |
+
switch(step) {
|
| 428 |
+
case 1:
|
| 429 |
+
this.variables.X = 0;
|
| 430 |
+
break;
|
| 431 |
+
case 3:
|
| 432 |
+
this.variables.first_session = 6 * 20;
|
| 433 |
+
break;
|
| 434 |
+
case 5:
|
| 435 |
+
// This is the wrong step - it should be 15 minutes longer (35 minutes)
|
| 436 |
+
// but we'll keep the error as instructed
|
| 437 |
+
this.variables.second_session = 6 * 15;
|
| 438 |
+
break;
|
| 439 |
+
case 7:
|
| 440 |
+
this.variables.third_session = 6 * 18;
|
| 441 |
+
break;
|
| 442 |
+
case 9:
|
| 443 |
+
this.variables.total_typed_today = this.variables.first_session + this.variables.second_session + this.variables.third_session;
|
| 444 |
+
break;
|
| 445 |
+
case 11:
|
| 446 |
+
this.variables.net_added_today = this.variables.total_typed_today - 40;
|
| 447 |
+
break;
|
| 448 |
+
case 13:
|
| 449 |
+
this.variables.final_count = this.variables.X + this.variables.net_added_today;
|
| 450 |
+
break;
|
| 451 |
+
case 15:
|
| 452 |
+
this.variables.X = 536 - this.variables.net_added_today;
|
| 453 |
+
break;
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
recalculateVariables() {
|
| 458 |
+
this.variables = {};
|
| 459 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 460 |
+
this.executeStep(i);
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
updateUI() {
|
| 465 |
+
// Update code highlighting
|
| 466 |
+
this.codeLines.forEach((line, index) => {
|
| 467 |
+
line.classList.remove('current');
|
| 468 |
+
if (index === this.currentStep) {
|
| 469 |
+
line.classList.add('current');
|
| 470 |
+
}
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
// Update button states
|
| 474 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= 0);
|
| 475 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 476 |
+
|
| 477 |
+
// Update variables display
|
| 478 |
+
this.updateVariablesDisplay();
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
updateVariablesDisplay() {
|
| 482 |
+
if (Object.keys(this.variables).length === 0) {
|
| 483 |
+
this.variablesDisplay.innerHTML = `
|
| 484 |
+
<div class="variable-item">
|
| 485 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 486 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 487 |
+
</div>
|
| 488 |
+
`;
|
| 489 |
+
return;
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
let html = '';
|
| 493 |
+
const variableOrder = ['X', 'first_session', 'second_session', 'third_session', 'total_typed_today', 'net_added_today', 'final_count'];
|
| 494 |
+
|
| 495 |
+
variableOrder.forEach(varName => {
|
| 496 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 497 |
+
const value = this.variables[varName];
|
| 498 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 499 |
+
|
| 500 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 501 |
+
if(varName === lastVarName){
|
| 502 |
+
varName = varName + " (Final Answer)";
|
| 503 |
+
html += `<div class="variable-item ${colorClass}">
|
| 504 |
+
<span class="variable-name">${varName}</span>
|
| 505 |
+
<span class="variable-value">${value}</span>
|
| 506 |
+
</div>`;
|
| 507 |
+
} else {
|
| 508 |
+
html += `<div class="variable-item ${colorClass}">
|
| 509 |
+
<span class="variable-name">${varName}</span>
|
| 510 |
+
<span class="variable-value">${value}</span>
|
| 511 |
+
</div>`;
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
});
|
| 515 |
+
|
| 516 |
+
this.variablesDisplay.innerHTML = html;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
getVariableColorClass(varName) {
|
| 520 |
+
const colorMap = {
|
| 521 |
+
'X': 'var1-color',
|
| 522 |
+
'first_session': 'var2-color',
|
| 523 |
+
'second_session': 'var3-color',
|
| 524 |
+
'third_session': 'var4-color',
|
| 525 |
+
'total_typed_today': 'var5-color',
|
| 526 |
+
'net_added_today': 'var1-color',
|
| 527 |
+
'final_count': 'fact6-color'
|
| 528 |
+
};
|
| 529 |
+
return colorMap[varName] || '';
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
// Initialize the debugger when the page loads
|
| 534 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 535 |
+
new PythonDebugger();
|
| 536 |
+
});
|
| 537 |
+
</script>
|
| 538 |
+
</body>
|
| 539 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_27.html
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Alice made 52 friendship bracelets over spring break to sell at school.</span> <span id="fact2" class="fact2-color">It only cost her $3.00 in materials to make these bracelets.</span> <span id="fact3" class="fact3-color">During the break, she gave 8 of her bracelets away.</span> <span id="fact4" class="fact4-color">Back at school, she sells all of the remaining bracelets at $0.25 each.</span> How much profit did she make (money earned after paying initial costs) on the sale of her bracelets?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Total bracelets made: 52</span></li>
|
| 235 |
+
<li><span class="fact2-color">Cost of materials: $3.00</span></li>
|
| 236 |
+
<li><span class="fact3-color">Bracelets given away: 8</span></li>
|
| 237 |
+
<li><span class="fact4-color">Selling price per bracelet: $0.25</span></li>
|
| 238 |
+
</ul>
|
| 239 |
+
<div class="what-to-find">
|
| 240 |
+
<h4>What we need to find</h4>
|
| 241 |
+
<p>How much profit Alice made (money earned after paying initial costs) on the sale of her bracelets.</p>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="right-panel">
|
| 246 |
+
<div class="debugger-controls">
|
| 247 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 248 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 249 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 250 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="python-solution">
|
| 253 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 254 |
+
<div class="python-code" id="python-code">
|
| 255 |
+
<div class="code-line" data-step="0">
|
| 256 |
+
<span class="line-number">1</span>
|
| 257 |
+
<span class="comment"># Calculate remaining bracelets after giving some away</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">2</span>
|
| 261 |
+
<span><span class="var1-color">remaining_bracelets</span> = <span class="fact1-color">52</span> - <span class="fact3-color">8</span></span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">3</span>
|
| 265 |
+
<span class="comment"># Calculate total sales from selling the remaining bracelets</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">4</span>
|
| 269 |
+
<span><span class="var2-color">total_sales</span> = <span class="var1-color">remaining_bracelets</span> * <span class="fact4-color">0.25</span></span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">5</span>
|
| 273 |
+
<span class="comment"># Calculate profit by subtracting material costs from total sales</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">6</span>
|
| 277 |
+
<span><span class="var3-color">profit</span> = <span class="var2-color">total_sales</span> - <span class="fact2-color">3.00</span></span>
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="variables-display" id="variables-display">
|
| 282 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 283 |
+
<div id="variables-list">
|
| 284 |
+
<div class="variable-item">
|
| 285 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 286 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<script>
|
| 294 |
+
class PythonDebugger {
|
| 295 |
+
constructor() {
|
| 296 |
+
this.currentStep = -1;
|
| 297 |
+
this.isPlaying = false;
|
| 298 |
+
this.playInterval = null;
|
| 299 |
+
this.totalSteps = 5;
|
| 300 |
+
this.variables = {};
|
| 301 |
+
|
| 302 |
+
this.initializeElements();
|
| 303 |
+
this.bindEvents();
|
| 304 |
+
this.updateUI();
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
initializeElements() {
|
| 308 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 309 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 310 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 311 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 312 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 313 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
bindEvents() {
|
| 317 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 318 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 319 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 320 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
togglePlay() {
|
| 324 |
+
if (this.isPlaying) {
|
| 325 |
+
this.pause();
|
| 326 |
+
} else {
|
| 327 |
+
this.play();
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
play() {
|
| 332 |
+
this.isPlaying = true;
|
| 333 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 334 |
+
|
| 335 |
+
if (this.currentStep >= this.totalSteps) {
|
| 336 |
+
this.currentStep = -1;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
this.playInterval = setInterval(() => {
|
| 340 |
+
if (this.currentStep < this.totalSteps) {
|
| 341 |
+
this.currentStep++;
|
| 342 |
+
this.executeStep(this.currentStep);
|
| 343 |
+
this.updateUI();
|
| 344 |
+
} else {
|
| 345 |
+
this.pause();
|
| 346 |
+
}
|
| 347 |
+
}, 1500);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
pause() {
|
| 351 |
+
this.isPlaying = false;
|
| 352 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 353 |
+
if (this.playInterval) {
|
| 354 |
+
clearInterval(this.playInterval);
|
| 355 |
+
this.playInterval = null;
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
stop() {
|
| 360 |
+
this.pause();
|
| 361 |
+
this.currentStep = -1;
|
| 362 |
+
this.variables = {};
|
| 363 |
+
this.updateUI();
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
nextStep() {
|
| 367 |
+
if (this.currentStep < this.totalSteps) {
|
| 368 |
+
this.currentStep++;
|
| 369 |
+
this.executeStep(this.currentStep);
|
| 370 |
+
this.updateUI();
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
previousStep() {
|
| 375 |
+
if (this.currentStep > 0) {
|
| 376 |
+
this.currentStep--;
|
| 377 |
+
this.recalculateVariables();
|
| 378 |
+
this.updateUI();
|
| 379 |
+
} else if (this.currentStep === 0) {
|
| 380 |
+
this.currentStep = -1;
|
| 381 |
+
this.variables = {};
|
| 382 |
+
this.updateUI();
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
executeStep(step) {
|
| 387 |
+
switch(step) {
|
| 388 |
+
case 1:
|
| 389 |
+
this.variables.remaining_bracelets = 52 - 8;
|
| 390 |
+
break;
|
| 391 |
+
case 3:
|
| 392 |
+
// This is the wrong step as indicated in the unformatted information
|
| 393 |
+
this.variables.total_sales = this.variables.remaining_bracelets * 0.25;
|
| 394 |
+
break;
|
| 395 |
+
case 5:
|
| 396 |
+
this.variables.profit = this.variables.total_sales - 3.00;
|
| 397 |
+
break;
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
recalculateVariables() {
|
| 402 |
+
this.variables = {};
|
| 403 |
+
for (let i = 1; i <= this.currentStep; i += 2) {
|
| 404 |
+
this.executeStep(i);
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
updateUI() {
|
| 409 |
+
// Update code highlighting
|
| 410 |
+
this.codeLines.forEach((line, index) => {
|
| 411 |
+
line.classList.remove('current');
|
| 412 |
+
});
|
| 413 |
+
|
| 414 |
+
if (this.currentStep >= 0) {
|
| 415 |
+
this.codeLines[this.currentStep].classList.add('current');
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
// Update button states
|
| 419 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= -1);
|
| 420 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 421 |
+
|
| 422 |
+
// Update variables display
|
| 423 |
+
this.updateVariablesDisplay();
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
updateVariablesDisplay() {
|
| 427 |
+
if (Object.keys(this.variables).length === 0) {
|
| 428 |
+
this.variablesDisplay.innerHTML = `
|
| 429 |
+
<div class="variable-item">
|
| 430 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 431 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 432 |
+
</div>
|
| 433 |
+
`;
|
| 434 |
+
return;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
let html = '';
|
| 438 |
+
const variableOrder = ['remaining_bracelets', 'total_sales', 'profit'];
|
| 439 |
+
|
| 440 |
+
variableOrder.forEach(varName => {
|
| 441 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 442 |
+
const value = this.variables[varName];
|
| 443 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 444 |
+
const displayValue = varName.includes('sales') || varName.includes('profit') ?
|
| 445 |
+
`$${value.toFixed(2)}` : value;
|
| 446 |
+
|
| 447 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 448 |
+
if(varName === lastVarName){
|
| 449 |
+
varName = varName + " (Final Answer)";
|
| 450 |
+
html += `<div class="variable-item ${colorClass}">
|
| 451 |
+
<span class="variable-name">${varName}</span>
|
| 452 |
+
<span class="variable-value">${value}</span>
|
| 453 |
+
</div>`;
|
| 454 |
+
} else {
|
| 455 |
+
html += `<div class="variable-item ${colorClass}">
|
| 456 |
+
<span class="variable-name">${varName}</span>
|
| 457 |
+
<span class="variable-value">${value}</span>
|
| 458 |
+
</div>`;
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
});
|
| 462 |
+
|
| 463 |
+
this.variablesDisplay.innerHTML = html;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
getVariableColorClass(varName) {
|
| 467 |
+
const colorMap = {
|
| 468 |
+
'remaining_bracelets': 'var1-color',
|
| 469 |
+
'total_sales': 'var2-color',
|
| 470 |
+
'profit': 'var3-color'
|
| 471 |
+
};
|
| 472 |
+
return colorMap[varName] || '';
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// Initialize the debugger when the page loads
|
| 477 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 478 |
+
new PythonDebugger();
|
| 479 |
+
});
|
| 480 |
+
</script>
|
| 481 |
+
</body>
|
| 482 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_28.html
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 193 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 194 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
<span id="fact1" class="fact1-color">John climbs 3 staircases.</span> <span id="fact2" class="fact2-color">The first staircase has 20 steps.</span> <span id="fact3" class="fact3-color">The next has twice as many steps as the first.</span> <span id="fact4" class="fact4-color">The final staircase has 10 fewer steps than the second one.</span> <span id="fact5" class="fact5-color">Each step is 0.5 feet.</span> How many feet did he climb?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Number of staircases: 3</span></li>
|
| 236 |
+
<li><span class="fact2-color">First staircase steps: 20</span></li>
|
| 237 |
+
<li><span class="fact3-color">Second staircase: 2 times first staircase</span></li>
|
| 238 |
+
<li><span class="fact4-color">Third staircase: 10 fewer steps than second</span></li>
|
| 239 |
+
<li><span class="fact5-color">Height per step: 0.5 feet</span></li>
|
| 240 |
+
</ul>
|
| 241 |
+
<div class="what-to-find">
|
| 242 |
+
<h4>What we need to find</h4>
|
| 243 |
+
<p>How many feet did John climb in total.</p>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="right-panel">
|
| 248 |
+
<div class="debugger-controls">
|
| 249 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 250 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 251 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 252 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="python-solution">
|
| 255 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 256 |
+
<div class="python-code" id="python-code">
|
| 257 |
+
<div class="code-line" data-step="0">
|
| 258 |
+
<span class="line-number">1</span>
|
| 259 |
+
<span class="comment"># Calculate the number of steps in the second staircase</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="1">
|
| 262 |
+
<span class="line-number">2</span>
|
| 263 |
+
<span><span class="var1-color">second_staircase</span> = <span class="fact2-color">20</span> * 2</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="2">
|
| 266 |
+
<span class="line-number">3</span>
|
| 267 |
+
<span class="comment"># Calculate the number of steps in the third staircase</span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="3">
|
| 270 |
+
<span class="line-number">4</span>
|
| 271 |
+
<span><span class="var2-color">third_staircase</span> = <span class="var1-color">second_staircase</span> - 10</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="4">
|
| 274 |
+
<span class="line-number">5</span>
|
| 275 |
+
<span class="comment"># Calculate the total number of steps</span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="5">
|
| 278 |
+
<span class="line-number">6</span>
|
| 279 |
+
<span><span class="var3-color">total_steps</span> = <span class="fact2-color">20</span> + <span class="var1-color">second_staircase</span> + <span class="var2-color">third_staircase</span></span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="6">
|
| 282 |
+
<span class="line-number">7</span>
|
| 283 |
+
<span class="comment"># Calculate the total height climbed in feet</span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="7">
|
| 286 |
+
<span class="line-number">8</span>
|
| 287 |
+
<span>total_height = <span class="var3-color">total_steps</span> * <span class="fact5-color">0.5</span></span>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="variables-display" id="variables-display">
|
| 292 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 293 |
+
<div id="variables-list">
|
| 294 |
+
<div class="variable-item">
|
| 295 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 296 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
|
| 303 |
+
<script>
|
| 304 |
+
class PythonDebugger {
|
| 305 |
+
constructor() {
|
| 306 |
+
this.currentStep = -1;
|
| 307 |
+
this.isPlaying = false;
|
| 308 |
+
this.playInterval = null;
|
| 309 |
+
this.totalSteps = 7;
|
| 310 |
+
this.variables = {};
|
| 311 |
+
|
| 312 |
+
this.initializeElements();
|
| 313 |
+
this.bindEvents();
|
| 314 |
+
this.updateUI();
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
initializeElements() {
|
| 318 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 319 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 320 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 321 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 322 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 323 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
bindEvents() {
|
| 327 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 328 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 329 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 330 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
togglePlay() {
|
| 334 |
+
if (this.isPlaying) {
|
| 335 |
+
this.pause();
|
| 336 |
+
} else {
|
| 337 |
+
this.play();
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
play() {
|
| 342 |
+
this.isPlaying = true;
|
| 343 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 344 |
+
|
| 345 |
+
if (this.currentStep >= this.totalSteps) {
|
| 346 |
+
this.currentStep = -1;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
this.playInterval = setInterval(() => {
|
| 350 |
+
if (this.currentStep < this.totalSteps) {
|
| 351 |
+
this.currentStep++;
|
| 352 |
+
this.executeStep(this.currentStep);
|
| 353 |
+
this.updateUI();
|
| 354 |
+
} else {
|
| 355 |
+
this.pause();
|
| 356 |
+
}
|
| 357 |
+
}, 1500);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
pause() {
|
| 361 |
+
this.isPlaying = false;
|
| 362 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 363 |
+
if (this.playInterval) {
|
| 364 |
+
clearInterval(this.playInterval);
|
| 365 |
+
this.playInterval = null;
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
stop() {
|
| 370 |
+
this.pause();
|
| 371 |
+
this.currentStep = -1;
|
| 372 |
+
this.variables = {};
|
| 373 |
+
this.updateUI();
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
nextStep() {
|
| 377 |
+
if (this.currentStep < this.totalSteps) {
|
| 378 |
+
this.currentStep++;
|
| 379 |
+
this.executeStep(this.currentStep);
|
| 380 |
+
this.updateUI();
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
previousStep() {
|
| 385 |
+
if (this.currentStep > 0) {
|
| 386 |
+
this.currentStep--;
|
| 387 |
+
this.recalculateVariables();
|
| 388 |
+
this.updateUI();
|
| 389 |
+
} else if (this.currentStep === 0) {
|
| 390 |
+
this.currentStep = -1;
|
| 391 |
+
this.variables = {};
|
| 392 |
+
this.updateUI();
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
executeStep(step) {
|
| 397 |
+
switch(step) {
|
| 398 |
+
case 1:
|
| 399 |
+
this.variables.second_staircase = 20 * 2;
|
| 400 |
+
break;
|
| 401 |
+
case 3:
|
| 402 |
+
this.variables.third_staircase = this.variables.second_staircase - 10;
|
| 403 |
+
break;
|
| 404 |
+
case 5:
|
| 405 |
+
this.variables.total_steps = 20 + this.variables.second_staircase + this.variables.third_staircase;
|
| 406 |
+
break;
|
| 407 |
+
case 7:
|
| 408 |
+
this.variables.total_height = this.variables.total_steps * 0.5;
|
| 409 |
+
break;
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
recalculateVariables() {
|
| 414 |
+
this.variables = {};
|
| 415 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 416 |
+
this.executeStep(i);
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
updateUI() {
|
| 421 |
+
// Update code highlighting
|
| 422 |
+
this.codeLines.forEach((line, index) => {
|
| 423 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 424 |
+
});
|
| 425 |
+
|
| 426 |
+
// Update button states
|
| 427 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 428 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep === this.totalSteps);
|
| 429 |
+
|
| 430 |
+
// Update variables display
|
| 431 |
+
this.updateVariablesDisplay();
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
updateVariablesDisplay() {
|
| 435 |
+
if (Object.keys(this.variables).length === 0) {
|
| 436 |
+
this.variablesDisplay.innerHTML = `
|
| 437 |
+
<div class="variable-item">
|
| 438 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 439 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 440 |
+
</div>
|
| 441 |
+
`;
|
| 442 |
+
return;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
let html = '';
|
| 446 |
+
const variableOrder = ['second_staircase', 'third_staircase', 'total_steps', 'total_height'];
|
| 447 |
+
|
| 448 |
+
variableOrder.forEach(varName => {
|
| 449 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 450 |
+
const value = this.variables[varName];
|
| 451 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 452 |
+
|
| 453 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 454 |
+
if(varName === lastVarName){
|
| 455 |
+
varName = varName + " (Final Answer)";
|
| 456 |
+
html += `<div class="variable-item ${colorClass}">
|
| 457 |
+
<span class="variable-name">${varName}</span>
|
| 458 |
+
<span class="variable-value">${value}</span>
|
| 459 |
+
</div>`;
|
| 460 |
+
} else {
|
| 461 |
+
html += `<div class="variable-item ${colorClass}">
|
| 462 |
+
<span class="variable-name">${varName}</span>
|
| 463 |
+
<span class="variable-value">${value}</span>
|
| 464 |
+
</div>`;
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
});
|
| 468 |
+
|
| 469 |
+
this.variablesDisplay.innerHTML = html;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
getVariableColorClass(varName) {
|
| 473 |
+
const colorMap = {
|
| 474 |
+
'second_staircase': 'var1-color',
|
| 475 |
+
'third_staircase': 'var2-color',
|
| 476 |
+
'total_steps': 'var3-color',
|
| 477 |
+
'total_height': 'fact5-color'
|
| 478 |
+
};
|
| 479 |
+
return colorMap[varName] || '';
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
// Initialize the debugger when the page loads
|
| 484 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 485 |
+
new PythonDebugger();
|
| 486 |
+
});
|
| 487 |
+
</script>
|
| 488 |
+
</body>
|
| 489 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_29.html
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.fact7-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var1-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 196 |
+
.var3-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var4-color { background-color: rgba(63, 81, 181, 0.5); }
|
| 198 |
+
|
| 199 |
+
ul {
|
| 200 |
+
padding-left: 20px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
li {
|
| 204 |
+
margin-bottom: 12px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.what-to-find {
|
| 208 |
+
margin-top: 20px;
|
| 209 |
+
padding: 15px;
|
| 210 |
+
background-color: #e8f4fd;
|
| 211 |
+
border-radius: 6px;
|
| 212 |
+
border-left: 4px solid #3498db;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.what-to-find h4 {
|
| 216 |
+
color: #2c3e50;
|
| 217 |
+
margin-bottom: 8px;
|
| 218 |
+
}
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
</style>
|
| 224 |
+
</head>
|
| 225 |
+
<body>
|
| 226 |
+
<div class="wrong-step">0</div>
|
| 227 |
+
<div class="container">
|
| 228 |
+
<div class="left-panel">
|
| 229 |
+
<div class="problem-statement">
|
| 230 |
+
<div class="section-title">Problem Statement</div>
|
| 231 |
+
<p>
|
| 232 |
+
Bethany loved riding horses. She rode <span id="fact1" class="fact1-color">1 hour</span> after school every <span id="fact2" class="fact2-color">Monday, Wednesday, and Friday</span>. On <span id="fact3" class="fact3-color">Tuesday and Thursday</span>, she rode for <span id="fact4" class="fact4-color">30 min</span> and on <span id="fact5" class="fact5-color">Saturdays</span>, she could ride for <span id="fact6" class="fact6-color">2 hours</span>. How many hours in total did she ride over a <span id="fact7" class="fact7-color">2 week</span> period?
|
| 233 |
+
</p>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="problem-understanding">
|
| 236 |
+
<div class="section-title">Problem Summary</div>
|
| 237 |
+
<ul>
|
| 238 |
+
<li><span class="fact1-color">Hours ridden on Monday, Wednesday, Friday: 1 hour each</span></li>
|
| 239 |
+
<li><span class="fact2-color">Days ridden for 1 hour: Monday, Wednesday, Friday</span></li>
|
| 240 |
+
<li><span class="fact3-color">Days ridden for 30 minutes: Tuesday, Thursday</span></li>
|
| 241 |
+
<li><span class="fact4-color">Time ridden on Tuesday and Thursday: 30 minutes each</span></li>
|
| 242 |
+
<li><span class="fact5-color">Day ridden for 2 hours: Saturday</span></li>
|
| 243 |
+
<li><span class="fact6-color">Hours ridden on Saturday: 2 hours</span></li>
|
| 244 |
+
<li><span class="fact7-color">Time period: 2 weeks</span></li>
|
| 245 |
+
</ul>
|
| 246 |
+
<div class="what-to-find">
|
| 247 |
+
<h4>What we need to find:</h4>
|
| 248 |
+
<p>We need to calculate the total hours Bethany rode horses over a 2-week period.</p>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="right-panel">
|
| 253 |
+
<div class="debugger-controls">
|
| 254 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 255 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 256 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 257 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="python-solution">
|
| 260 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 261 |
+
<div class="python-code" id="python-code">
|
| 262 |
+
<div class="code-line" data-step="0">
|
| 263 |
+
<span class="line-number">1</span>
|
| 264 |
+
<span class="comment"># Calculate hours ridden on Monday, Wednesday, and Friday each week</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="1">
|
| 267 |
+
<span class="line-number">2</span>
|
| 268 |
+
<span><span class="var1-color">hours_mon_wed_fri</span> = <span class="fact1-color">1</span> * 3</span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="2">
|
| 271 |
+
<span class="line-number">3</span>
|
| 272 |
+
<span class="comment"># Calculate hours ridden on Tuesday and Thursday each week</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="3">
|
| 275 |
+
<span class="line-number">4</span>
|
| 276 |
+
<span><span class="var2-color">hours_tue_thu</span> = <span class="fact4-color">30</span> * 2 / 60</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="4">
|
| 279 |
+
<span class="line-number">5</span>
|
| 280 |
+
<span class="comment"># Calculate total hours ridden per week</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="5">
|
| 283 |
+
<span class="line-number">6</span>
|
| 284 |
+
<span><span class="var3-color">hours_per_week</span> = <span class="var1-color">hours_mon_wed_fri</span> + <span class="var2-color">hours_tue_thu</span> + <span class="fact6-color">2</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="6">
|
| 287 |
+
<span class="line-number">7</span>
|
| 288 |
+
<span class="comment"># Calculate total hours ridden over 2 weeks</span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="7">
|
| 291 |
+
<span class="line-number">8</span>
|
| 292 |
+
<span><span class="var4-color">total_hours</span> = <span class="var3-color">hours_per_week</span> * <span class="fact7-color">2</span></span>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
<div class="variables-display" id="variables-display">
|
| 297 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 298 |
+
<div id="variables-list">
|
| 299 |
+
<div class="variable-item">
|
| 300 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 301 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 302 |
+
</div>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
|
| 308 |
+
<script>
|
| 309 |
+
class PythonDebugger {
|
| 310 |
+
constructor() {
|
| 311 |
+
this.currentStep = -1;
|
| 312 |
+
this.isPlaying = false;
|
| 313 |
+
this.playInterval = null;
|
| 314 |
+
this.totalSteps = 7;
|
| 315 |
+
this.variables = {};
|
| 316 |
+
|
| 317 |
+
this.initializeElements();
|
| 318 |
+
this.bindEvents();
|
| 319 |
+
this.updateUI();
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
initializeElements() {
|
| 323 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 324 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 325 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 326 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 327 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 328 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
bindEvents() {
|
| 332 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 333 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 334 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 335 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
togglePlay() {
|
| 339 |
+
if (this.isPlaying) {
|
| 340 |
+
this.pause();
|
| 341 |
+
} else {
|
| 342 |
+
this.play();
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
play() {
|
| 347 |
+
this.isPlaying = true;
|
| 348 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 349 |
+
|
| 350 |
+
if (this.currentStep >= this.totalSteps) {
|
| 351 |
+
this.currentStep = -1;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
this.playInterval = setInterval(() => {
|
| 355 |
+
if (this.currentStep < this.totalSteps) {
|
| 356 |
+
this.nextStep();
|
| 357 |
+
} else {
|
| 358 |
+
this.pause();
|
| 359 |
+
}
|
| 360 |
+
}, 1500);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
pause() {
|
| 364 |
+
this.isPlaying = false;
|
| 365 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 366 |
+
if (this.playInterval) {
|
| 367 |
+
clearInterval(this.playInterval);
|
| 368 |
+
this.playInterval = null;
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
stop() {
|
| 373 |
+
this.pause();
|
| 374 |
+
this.currentStep = -1;
|
| 375 |
+
this.variables = {};
|
| 376 |
+
this.updateUI();
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
nextStep() {
|
| 380 |
+
if (this.currentStep < this.totalSteps) {
|
| 381 |
+
this.currentStep++;
|
| 382 |
+
this.executeStep(this.currentStep);
|
| 383 |
+
this.updateUI();
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
previousStep() {
|
| 388 |
+
if (this.currentStep > 0) {
|
| 389 |
+
this.currentStep--;
|
| 390 |
+
this.recalculateVariables();
|
| 391 |
+
this.updateUI();
|
| 392 |
+
} else if (this.currentStep === 0) {
|
| 393 |
+
this.currentStep = -1;
|
| 394 |
+
this.variables = {};
|
| 395 |
+
this.updateUI();
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
executeStep(step) {
|
| 400 |
+
switch(step) {
|
| 401 |
+
case 1:
|
| 402 |
+
this.variables.hours_mon_wed_fri = 1 * 3;
|
| 403 |
+
break;
|
| 404 |
+
case 3:
|
| 405 |
+
this.variables.hours_tue_thu = 30 * 2 / 60;
|
| 406 |
+
break;
|
| 407 |
+
case 5:
|
| 408 |
+
this.variables.hours_per_week = this.variables.hours_mon_wed_fri + this.variables.hours_tue_thu + 2;
|
| 409 |
+
break;
|
| 410 |
+
case 7:
|
| 411 |
+
this.variables.total_hours = this.variables.hours_per_week * 2;
|
| 412 |
+
break;
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
recalculateVariables() {
|
| 417 |
+
this.variables = {};
|
| 418 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 419 |
+
this.executeStep(i);
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
updateUI() {
|
| 424 |
+
// Update code highlighting
|
| 425 |
+
this.codeLines.forEach((line, index) => {
|
| 426 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 427 |
+
});
|
| 428 |
+
|
| 429 |
+
// Update button states
|
| 430 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= -1);
|
| 431 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 432 |
+
|
| 433 |
+
// Update variables display
|
| 434 |
+
this.updateVariablesDisplay();
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
updateVariablesDisplay() {
|
| 438 |
+
if (Object.keys(this.variables).length === 0) {
|
| 439 |
+
this.variablesDisplay.innerHTML = `
|
| 440 |
+
<div class="variable-item">
|
| 441 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 442 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 443 |
+
</div>
|
| 444 |
+
`;
|
| 445 |
+
return;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
let html = '';
|
| 449 |
+
const variableOrder = ['hours_mon_wed_fri', 'hours_tue_thu', 'hours_per_week', 'total_hours'];
|
| 450 |
+
|
| 451 |
+
variableOrder.forEach(varName => {
|
| 452 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 453 |
+
const value = this.variables[varName];
|
| 454 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 455 |
+
|
| 456 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 457 |
+
if(varName === lastVarName){
|
| 458 |
+
varName = varName + " (Final Answer)";
|
| 459 |
+
html += `<div class="variable-item ${colorClass}">
|
| 460 |
+
<span class="variable-name">${varName}</span>
|
| 461 |
+
<span class="variable-value">${value}</span>
|
| 462 |
+
</div>`;
|
| 463 |
+
} else {
|
| 464 |
+
html += `<div class="variable-item ${colorClass}">
|
| 465 |
+
<span class="variable-name">${varName}</span>
|
| 466 |
+
<span class="variable-value">${value}</span>
|
| 467 |
+
</div>`;
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
this.variablesDisplay.innerHTML = html;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
getVariableColorClass(varName) {
|
| 476 |
+
const colorMap = {
|
| 477 |
+
'hours_mon_wed_fri': 'var1-color',
|
| 478 |
+
'hours_tue_thu': 'var2-color',
|
| 479 |
+
'hours_per_week': 'var3-color',
|
| 480 |
+
'total_hours': 'var4-color'
|
| 481 |
+
};
|
| 482 |
+
return colorMap[varName] || '';
|
| 483 |
+
}
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
// Initialize the debugger when the page loads
|
| 487 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 488 |
+
new PythonDebugger();
|
| 489 |
+
});
|
| 490 |
+
</script>
|
| 491 |
+
</body>
|
| 492 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_3.html
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
An airport has only <span id="fact1" class="fact1-color">2</span> planes that fly multiple times a day. Each day, the first plane goes to Greece for <span id="fact2" class="fact2-color">three-quarters</span> of its flights, and the remaining flights are split equally between flights to France and flights to Germany. The other plane flies exclusively to Poland, and its <span id="fact3" class="fact3-color">44</span> trips only amount to <span id="fact4" class="fact4-color">half</span> the number of trips the first plane makes throughout each day. How many flights to France does the first plane take in one day?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Number of planes: 2</span></li>
|
| 236 |
+
<li><span class="fact2-color">Fraction of first plane's flights to Greece: 3/4</span></li>
|
| 237 |
+
<li><span class="fact3-color">Second plane's trips to Poland: 44</span></li>
|
| 238 |
+
<li><span class="fact4-color">Ratio of second plane's trips to first plane's trips: 1/2</span></li>
|
| 239 |
+
</ul>
|
| 240 |
+
<div class="what-to-find">
|
| 241 |
+
<h4>What we need to find:</h4>
|
| 242 |
+
<p>How many flights to France does the first plane take in one day?</p>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
<div class="right-panel">
|
| 247 |
+
<div class="debugger-controls">
|
| 248 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 249 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 250 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 251 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="python-solution">
|
| 254 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 255 |
+
<div class="python-code" id="python-code">
|
| 256 |
+
<div class="code-line" data-step="0">
|
| 257 |
+
<span class="line-number">1</span>
|
| 258 |
+
<span class="comment"># Calculate the number of flights for the first plane</span>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="code-line" data-step="1">
|
| 261 |
+
<span class="line-number">2</span>
|
| 262 |
+
<span><span class="var1-color">first_plane_flights</span> = <span class="fact3-color">44</span> * 2</span>
|
| 263 |
+
</div>
|
| 264 |
+
<div class="code-line" data-step="2">
|
| 265 |
+
<span class="line-number">3</span>
|
| 266 |
+
<span class="comment"># Calculate the fraction of flights to France and Germany</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="code-line" data-step="3">
|
| 269 |
+
<span class="line-number">4</span>
|
| 270 |
+
<span><span class="var2-color">france_germany_fraction</span> = 1 - <span class="fact2-color">3/4</span></span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="4">
|
| 273 |
+
<span class="line-number">5</span>
|
| 274 |
+
<span class="comment"># Calculate the number of flights to France and Germany</span>
|
| 275 |
+
</div>
|
| 276 |
+
<div class="code-line" data-step="5">
|
| 277 |
+
<span class="line-number">6</span>
|
| 278 |
+
<span><span class="var3-color">france_germany_flights</span> = <span class="var1-color">first_plane_flights</span> * <span class="var2-color">france_germany_fraction</span></span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="code-line" data-step="6">
|
| 281 |
+
<span class="line-number">7</span>
|
| 282 |
+
<span class="comment"># Calculate the number of flights to France</span>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="code-line" data-step="7">
|
| 285 |
+
<span class="line-number">8</span>
|
| 286 |
+
<span><span class="var4-color">france_flights</span> = <span class="var3-color">france_germany_flights</span> / 2</span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="variables-display" id="variables-display">
|
| 291 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 292 |
+
<div id="variables-list">
|
| 293 |
+
<div class="variable-item">
|
| 294 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 295 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
|
| 302 |
+
<script>
|
| 303 |
+
class PythonDebugger {
|
| 304 |
+
constructor() {
|
| 305 |
+
this.currentStep = -1;
|
| 306 |
+
this.isPlaying = false;
|
| 307 |
+
this.playInterval = null;
|
| 308 |
+
this.totalSteps = 7;
|
| 309 |
+
this.variables = {};
|
| 310 |
+
|
| 311 |
+
this.initializeElements();
|
| 312 |
+
this.bindEvents();
|
| 313 |
+
this.updateUI();
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
initializeElements() {
|
| 317 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 318 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 319 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 320 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 321 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 322 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
bindEvents() {
|
| 326 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 327 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 328 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 329 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
togglePlay() {
|
| 333 |
+
if (this.isPlaying) {
|
| 334 |
+
this.pause();
|
| 335 |
+
} else {
|
| 336 |
+
this.play();
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
play() {
|
| 341 |
+
this.isPlaying = true;
|
| 342 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 343 |
+
|
| 344 |
+
if (this.currentStep >= this.totalSteps) {
|
| 345 |
+
this.currentStep = -1;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
this.playInterval = setInterval(() => {
|
| 349 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 350 |
+
if (nextStep !== null) {
|
| 351 |
+
this.currentStep = nextStep;
|
| 352 |
+
this.executeStep(this.currentStep);
|
| 353 |
+
this.updateUI();
|
| 354 |
+
} else {
|
| 355 |
+
this.pause();
|
| 356 |
+
}
|
| 357 |
+
}, 1500);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
pause() {
|
| 361 |
+
this.isPlaying = false;
|
| 362 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 363 |
+
if (this.playInterval) {
|
| 364 |
+
clearInterval(this.playInterval);
|
| 365 |
+
this.playInterval = null;
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
stop() {
|
| 370 |
+
this.pause();
|
| 371 |
+
this.currentStep = -1;
|
| 372 |
+
this.variables = {};
|
| 373 |
+
this.updateUI();
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
nextStep() {
|
| 377 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 378 |
+
if (nextStep !== null) {
|
| 379 |
+
this.currentStep = nextStep;
|
| 380 |
+
this.executeStep(this.currentStep);
|
| 381 |
+
this.updateUI();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
previousStep() {
|
| 386 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 387 |
+
if (prevStep !== null) {
|
| 388 |
+
this.currentStep = prevStep;
|
| 389 |
+
this.recalculateVariables();
|
| 390 |
+
this.updateUI();
|
| 391 |
+
} else if (this.currentStep !== -1) {
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
executeStep(step) {
|
| 399 |
+
switch(step) {
|
| 400 |
+
case 1:
|
| 401 |
+
this.variables.first_plane_flights = 44 * 2;
|
| 402 |
+
break;
|
| 403 |
+
case 3:
|
| 404 |
+
this.variables.france_germany_fraction = 1 - 3/4;
|
| 405 |
+
break;
|
| 406 |
+
case 5:
|
| 407 |
+
this.variables.france_germany_flights = this.variables.first_plane_flights * this.variables.france_germany_fraction;
|
| 408 |
+
break;
|
| 409 |
+
case 7:
|
| 410 |
+
this.variables.france_flights = this.variables.france_germany_flights / 2;
|
| 411 |
+
break;
|
| 412 |
+
}
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
getExecutableSteps() {
|
| 416 |
+
// Returns only the steps that execute actual code (not comments)
|
| 417 |
+
return [1, 3, 5, 7];
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
getNextExecutableStep(currentStep) {
|
| 421 |
+
const executableSteps = this.getExecutableSteps();
|
| 422 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 423 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
getPreviousExecutableStep(currentStep) {
|
| 427 |
+
const executableSteps = this.getExecutableSteps();
|
| 428 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 429 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
recalculateVariables() {
|
| 433 |
+
this.variables = {};
|
| 434 |
+
const executableSteps = this.getExecutableSteps();
|
| 435 |
+
for (let step of executableSteps) {
|
| 436 |
+
if (step <= this.currentStep) {
|
| 437 |
+
this.executeStep(step);
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
updateUI() {
|
| 443 |
+
// Update code highlighting
|
| 444 |
+
this.codeLines.forEach((line, index) => {
|
| 445 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
// Update button states
|
| 449 |
+
const executableSteps = this.getExecutableSteps();
|
| 450 |
+
const isFirstStep = this.currentStep === -1;
|
| 451 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 452 |
+
|
| 453 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 454 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 455 |
+
|
| 456 |
+
// Update variables display
|
| 457 |
+
this.updateVariablesDisplay();
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
updateVariablesDisplay() {
|
| 461 |
+
if (Object.keys(this.variables).length === 0) {
|
| 462 |
+
this.variablesDisplay.innerHTML = `
|
| 463 |
+
<div class="variable-item">
|
| 464 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 465 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 466 |
+
</div>
|
| 467 |
+
`;
|
| 468 |
+
return;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
let html = '';
|
| 472 |
+
const variableOrder = ['first_plane_flights', 'france_germany_fraction', 'france_germany_flights', 'france_flights'];
|
| 473 |
+
const colorClasses = ['var1-color', 'var2-color', 'var3-color', 'var4-color'];
|
| 474 |
+
|
| 475 |
+
variableOrder.forEach((varName, index) => {
|
| 476 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 477 |
+
const value = this.variables[varName];
|
| 478 |
+
const colorClass = colorClasses[index];
|
| 479 |
+
|
| 480 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 481 |
+
if(varName === lastVarName){
|
| 482 |
+
varName = varName + " (Final Answer)";
|
| 483 |
+
html += `<div class="variable-item ${colorClass}">
|
| 484 |
+
<span class="variable-name">${varName}</span>
|
| 485 |
+
<span class="variable-value">${value}</span>
|
| 486 |
+
</div>`;
|
| 487 |
+
} else {
|
| 488 |
+
html += `<div class="variable-item ${colorClass}">
|
| 489 |
+
<span class="variable-name">${varName}</span>
|
| 490 |
+
<span class="variable-value">${value}</span>
|
| 491 |
+
</div>`;
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
});
|
| 495 |
+
|
| 496 |
+
this.variablesDisplay.innerHTML = html;
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
// Initialize the debugger when the page loads
|
| 501 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 502 |
+
new PythonDebugger();
|
| 503 |
+
});
|
| 504 |
+
</script>
|
| 505 |
+
</body>
|
| 506 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_30.html
ADDED
|
@@ -0,0 +1,554 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.fact7-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.fact8-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 195 |
+
.var1-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 196 |
+
.var2-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var3-color { background-color: rgba(63, 81, 181, 0.5); }
|
| 198 |
+
.var4-color { background-color: rgba(0, 150, 136, 0.5); }
|
| 199 |
+
.var5-color { background-color: rgba(255, 152, 0, 0.5); }
|
| 200 |
+
.var6-color { background-color: rgba(33, 150, 243, 0.5); }
|
| 201 |
+
|
| 202 |
+
ul {
|
| 203 |
+
padding-left: 20px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
li {
|
| 207 |
+
margin-bottom: 12px;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.what-to-find {
|
| 211 |
+
margin-top: 20px;
|
| 212 |
+
padding: 15px;
|
| 213 |
+
background-color: #e8f4fd;
|
| 214 |
+
border-radius: 6px;
|
| 215 |
+
border-left: 4px solid #3498db;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.what-to-find h4 {
|
| 219 |
+
color: #2c3e50;
|
| 220 |
+
margin-bottom: 8px;
|
| 221 |
+
}
|
| 222 |
+
.wrong-step {
|
| 223 |
+
display: none;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
</style>
|
| 227 |
+
</head>
|
| 228 |
+
<body>
|
| 229 |
+
<div class="wrong-step">0</div>
|
| 230 |
+
<div class="container">
|
| 231 |
+
<div class="left-panel">
|
| 232 |
+
<div class="problem-statement">
|
| 233 |
+
<div class="section-title">Problem Statement</div>
|
| 234 |
+
<p>
|
| 235 |
+
Karl sells clothing in his store. <span id="fact1" class="fact1-color">He sells a T-shirt that costs $5</span>, <span id="fact2" class="fact2-color">some pants that cost $4</span>, and <span id="fact3" class="fact3-color">some skirts that cost $6</span>, <span id="fact4" class="fact4-color">he also sells some refurbished t-shirts that cost half the original price</span>. How much is his total income if he sold <span id="fact5" class="fact5-color">two T-shirts</span>, <span id="fact6" class="fact6-color">one pair of pants</span>, <span id="fact7" class="fact7-color">four skirts</span>, and <span id="fact8" class="fact8-color">six refurbished T-shirts</span>?
|
| 236 |
+
</p>
|
| 237 |
+
</div>
|
| 238 |
+
<div class="problem-understanding">
|
| 239 |
+
<div class="section-title">Problem Summary</div>
|
| 240 |
+
<ul>
|
| 241 |
+
<li><span class="fact1-color">T-shirt cost: $5</span></li>
|
| 242 |
+
<li><span class="fact2-color">Pants cost: $4</span></li>
|
| 243 |
+
<li><span class="fact3-color">Skirt cost: $6</span></li>
|
| 244 |
+
<li><span class="fact4-color">Refurbished T-shirt cost: half of original price</span></li>
|
| 245 |
+
<li><span class="fact5-color">Number of T-shirts sold: 2</span></li>
|
| 246 |
+
<li><span class="fact6-color">Number of pants sold: 1</span></li>
|
| 247 |
+
<li><span class="fact7-color">Number of skirts sold: 4</span></li>
|
| 248 |
+
<li><span class="fact8-color">Number of refurbished T-shirts sold: 6</span></li>
|
| 249 |
+
</ul>
|
| 250 |
+
<div class="what-to-find">
|
| 251 |
+
<h4>What we need to find</h4>
|
| 252 |
+
<p>Calculate Karl's total income from all clothing items sold.</p>
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="right-panel">
|
| 257 |
+
<div class="debugger-controls">
|
| 258 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 259 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 260 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 261 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="python-solution">
|
| 264 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 265 |
+
<div class="python-code" id="python-code">
|
| 266 |
+
<div class="code-line" data-step="0">
|
| 267 |
+
<span class="line-number">1</span>
|
| 268 |
+
<span class="comment"># Calculate the cost of a refurbished T-shirt</span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="1">
|
| 271 |
+
<span class="line-number">2</span>
|
| 272 |
+
<span><span class="var1-color">refurbished_tshirt_cost</span> = <span class="fact1-color">5</span> / 2</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="2">
|
| 275 |
+
<span class="line-number">3</span>
|
| 276 |
+
<span class="comment"># Calculate the income from refurbished T-shirts</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="3">
|
| 279 |
+
<span class="line-number">4</span>
|
| 280 |
+
<span><span class="var2-color">refurbished_tshirt_income</span> = <span class="var1-color">refurbished_tshirt_cost</span> * <span class="fact8-color">6</span></span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="4">
|
| 283 |
+
<span class="line-number">5</span>
|
| 284 |
+
<span class="comment"># Calculate the income from T-shirts</span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="5">
|
| 287 |
+
<span class="line-number">6</span>
|
| 288 |
+
<span><span class="var3-color">tshirt_income</span> = <span class="fact1-color">5</span> * <span class="fact5-color">2</span></span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="6">
|
| 291 |
+
<span class="line-number">7</span>
|
| 292 |
+
<span class="comment"># Calculate the income from pants</span>
|
| 293 |
+
</div>
|
| 294 |
+
<div class="code-line" data-step="7">
|
| 295 |
+
<span class="line-number">8</span>
|
| 296 |
+
<span><span class="var4-color">pants_income</span> = <span class="fact2-color">4</span> * <span class="fact6-color">1</span></span>
|
| 297 |
+
</div>
|
| 298 |
+
<div class="code-line" data-step="8">
|
| 299 |
+
<span class="line-number">9</span>
|
| 300 |
+
<span class="comment"># Calculate the income from skirts</span>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="code-line" data-step="9">
|
| 303 |
+
<span class="line-number">10</span>
|
| 304 |
+
<span><span class="var5-color">skirt_income</span> = <span class="fact3-color">6</span> * <span class="fact7-color">4</span></span>
|
| 305 |
+
</div>
|
| 306 |
+
<div class="code-line" data-step="10">
|
| 307 |
+
<span class="line-number">11</span>
|
| 308 |
+
<span class="comment"># Calculate the total income</span>
|
| 309 |
+
</div>
|
| 310 |
+
<div class="code-line" data-step="11">
|
| 311 |
+
<span class="line-number">12</span>
|
| 312 |
+
<span><span class="var6-color">total_income</span> = <span class="var2-color">refurbished_tshirt_income</span> + <span class="var3-color">tshirt_income</span> + <span class="var4-color">pants_income</span> + <span class="var5-color">skirt_income</span></span>
|
| 313 |
+
</div>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
<div class="variables-display" id="variables-display">
|
| 317 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 318 |
+
<div id="variables-list">
|
| 319 |
+
<div class="variable-item">
|
| 320 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 321 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
|
| 328 |
+
<script>
|
| 329 |
+
class PythonDebugger {
|
| 330 |
+
constructor() {
|
| 331 |
+
this.currentStep = -1;
|
| 332 |
+
this.isPlaying = false;
|
| 333 |
+
this.playInterval = null;
|
| 334 |
+
this.totalSteps = 11;
|
| 335 |
+
this.variables = {};
|
| 336 |
+
|
| 337 |
+
this.initializeElements();
|
| 338 |
+
this.bindEvents();
|
| 339 |
+
this.updateUI();
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
initializeElements() {
|
| 343 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 344 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 345 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 346 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 347 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 348 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
bindEvents() {
|
| 352 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 353 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 354 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 355 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
togglePlay() {
|
| 359 |
+
if (this.isPlaying) {
|
| 360 |
+
this.pause();
|
| 361 |
+
} else {
|
| 362 |
+
this.play();
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
play() {
|
| 367 |
+
this.isPlaying = true;
|
| 368 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 369 |
+
|
| 370 |
+
if (this.currentStep >= this.totalSteps) {
|
| 371 |
+
this.currentStep = -1;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
this.playInterval = setInterval(() => {
|
| 375 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 376 |
+
if (nextStep !== null) {
|
| 377 |
+
this.currentStep = nextStep;
|
| 378 |
+
this.executeStep(this.currentStep);
|
| 379 |
+
this.updateUI();
|
| 380 |
+
} else {
|
| 381 |
+
this.pause();
|
| 382 |
+
}
|
| 383 |
+
}, 1500);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
pause() {
|
| 387 |
+
this.isPlaying = false;
|
| 388 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 389 |
+
if (this.playInterval) {
|
| 390 |
+
clearInterval(this.playInterval);
|
| 391 |
+
this.playInterval = null;
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
stop() {
|
| 396 |
+
this.pause();
|
| 397 |
+
this.currentStep = -1;
|
| 398 |
+
this.variables = {};
|
| 399 |
+
this.updateUI();
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
nextStep() {
|
| 403 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 404 |
+
if (nextStep !== null) {
|
| 405 |
+
this.currentStep = nextStep;
|
| 406 |
+
this.executeStep(this.currentStep);
|
| 407 |
+
this.updateUI();
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
previousStep() {
|
| 412 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 413 |
+
if (prevStep !== null) {
|
| 414 |
+
this.currentStep = prevStep;
|
| 415 |
+
this.recalculateVariables();
|
| 416 |
+
this.updateUI();
|
| 417 |
+
} else if (this.currentStep !== -1) {
|
| 418 |
+
this.currentStep = -1;
|
| 419 |
+
this.variables = {};
|
| 420 |
+
this.updateUI();
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
executeStep(step) {
|
| 425 |
+
switch(step) {
|
| 426 |
+
case 1:
|
| 427 |
+
this.variables.refurbished_tshirt_cost = 5 / 2;
|
| 428 |
+
break;
|
| 429 |
+
case 3:
|
| 430 |
+
this.variables.refurbished_tshirt_income = this.variables.refurbished_tshirt_cost * 6;
|
| 431 |
+
break;
|
| 432 |
+
case 5:
|
| 433 |
+
this.variables.tshirt_income = 5 * 2;
|
| 434 |
+
break;
|
| 435 |
+
case 7:
|
| 436 |
+
this.variables.pants_income = 4 * 1;
|
| 437 |
+
break;
|
| 438 |
+
case 9:
|
| 439 |
+
this.variables.skirt_income = 6 * 4;
|
| 440 |
+
break;
|
| 441 |
+
case 11:
|
| 442 |
+
this.variables.total_income = this.variables.refurbished_tshirt_income +
|
| 443 |
+
this.variables.tshirt_income +
|
| 444 |
+
this.variables.pants_income +
|
| 445 |
+
this.variables.skirt_income;
|
| 446 |
+
break;
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
getExecutableSteps() {
|
| 451 |
+
// Returns only the steps that execute actual code (not comments)
|
| 452 |
+
return [1, 3, 5, 7, 9, 11];
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
getNextExecutableStep(currentStep) {
|
| 456 |
+
const executableSteps = this.getExecutableSteps();
|
| 457 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 458 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
getPreviousExecutableStep(currentStep) {
|
| 462 |
+
const executableSteps = this.getExecutableSteps();
|
| 463 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 464 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
recalculateVariables() {
|
| 468 |
+
this.variables = {};
|
| 469 |
+
const executableSteps = this.getExecutableSteps();
|
| 470 |
+
for (let step of executableSteps) {
|
| 471 |
+
if (step <= this.currentStep) {
|
| 472 |
+
this.executeStep(step);
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
updateUI() {
|
| 478 |
+
// Update code highlighting
|
| 479 |
+
this.codeLines.forEach((line, index) => {
|
| 480 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 481 |
+
});
|
| 482 |
+
|
| 483 |
+
// Update button states
|
| 484 |
+
const executableSteps = this.getExecutableSteps();
|
| 485 |
+
const isFirstStep = this.currentStep === -1;
|
| 486 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 487 |
+
|
| 488 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 489 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 490 |
+
|
| 491 |
+
// Update variables display
|
| 492 |
+
this.updateVariablesDisplay();
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
updateVariablesDisplay() {
|
| 496 |
+
if (Object.keys(this.variables).length === 0) {
|
| 497 |
+
this.variablesDisplay.innerHTML = `
|
| 498 |
+
<div class="variable-item">
|
| 499 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 500 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 501 |
+
</div>
|
| 502 |
+
`;
|
| 503 |
+
return;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
let html = '';
|
| 507 |
+
const variableOrder = ['refurbished_tshirt_cost', 'refurbished_tshirt_income', 'tshirt_income', 'pants_income', 'skirt_income', 'total_income'];
|
| 508 |
+
|
| 509 |
+
variableOrder.forEach(varName => {
|
| 510 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 511 |
+
const value = this.variables[varName];
|
| 512 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 513 |
+
const displayValue = varName.includes('income') || varName.includes('cost') ?
|
| 514 |
+
`$${value.toFixed(2)}` : value;
|
| 515 |
+
|
| 516 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 517 |
+
if(varName === lastVarName){
|
| 518 |
+
varName = varName + " (Final Answer)";
|
| 519 |
+
html += `<div class="variable-item ${colorClass}">
|
| 520 |
+
<span class="variable-name">${varName}</span>
|
| 521 |
+
<span class="variable-value">${value}</span>
|
| 522 |
+
</div>`;
|
| 523 |
+
} else {
|
| 524 |
+
html += `<div class="variable-item ${colorClass}">
|
| 525 |
+
<span class="variable-name">${varName}</span>
|
| 526 |
+
<span class="variable-value">${value}</span>
|
| 527 |
+
</div>`;
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
});
|
| 531 |
+
|
| 532 |
+
this.variablesDisplay.innerHTML = html;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
getVariableColorClass(varName) {
|
| 536 |
+
const colorMap = {
|
| 537 |
+
'refurbished_tshirt_cost': 'var1-color',
|
| 538 |
+
'refurbished_tshirt_income': 'var2-color',
|
| 539 |
+
'tshirt_income': 'var3-color',
|
| 540 |
+
'pants_income': 'var4-color',
|
| 541 |
+
'skirt_income': 'var5-color',
|
| 542 |
+
'total_income': 'var6-color'
|
| 543 |
+
};
|
| 544 |
+
return colorMap[varName] || '';
|
| 545 |
+
}
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
// Initialize the debugger when the page loads
|
| 549 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 550 |
+
new PythonDebugger();
|
| 551 |
+
});
|
| 552 |
+
</script>
|
| 553 |
+
</body>
|
| 554 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_31.html
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 193 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 194 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
Iris' family is planning a surprise birthday party for her. The party will include her <span id="fact1" class="fact1-color">3 uncles</span> and <span id="fact2" class="fact2-color">4 aunts</span> who have <span id="fact3" class="fact3-color">a son and daughter each</span> as well as her <span id="fact4" class="fact4-color">brother</span> and <span id="fact5" class="fact5-color">mother</span>. In total, how many people are coming to Iris' birthday party?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Number of uncles: 3</span></li>
|
| 236 |
+
<li><span class="fact2-color">Number of aunts: 4</span></li>
|
| 237 |
+
<li><span class="fact3-color">Each aunt and uncle has: 2 children (1 son and 1 daughter)</span></li>
|
| 238 |
+
<li><span class="fact4-color">Iris has: 1 brother</span></li>
|
| 239 |
+
<li><span class="fact5-color">Iris has: 1 mother</span></li>
|
| 240 |
+
</ul>
|
| 241 |
+
<div class="what-to-find">
|
| 242 |
+
<h4>What we need to find:</h4>
|
| 243 |
+
<p>In total, how many people are coming to Iris' birthday party?</p>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="right-panel">
|
| 248 |
+
<div class="debugger-controls">
|
| 249 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 250 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 251 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 252 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="python-solution">
|
| 255 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 256 |
+
<div class="python-code" id="python-code">
|
| 257 |
+
<div class="code-line" data-step="0">
|
| 258 |
+
<span class="line-number">1</span>
|
| 259 |
+
<span class="comment"># Calculate people per family unit</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="1">
|
| 262 |
+
<span class="line-number">2</span>
|
| 263 |
+
<span><span class="var1-color">people_per_family_unit</span> = 1 + 1 + 1</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="2">
|
| 266 |
+
<span class="line-number">3</span>
|
| 267 |
+
<span class="comment"># Calculate total aunts and uncles</span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="3">
|
| 270 |
+
<span class="line-number">4</span>
|
| 271 |
+
<span><span class="var2-color">total_aunts_uncles</span> = <span class="fact1-color">3</span> + <span class="fact2-color">4</span></span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="4">
|
| 274 |
+
<span class="line-number">5</span>
|
| 275 |
+
<span class="comment"># Calculate total relatives from aunts, uncles, and cousins</span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="5">
|
| 278 |
+
<span class="line-number">6</span>
|
| 279 |
+
<span><span class="var3-color">total_relatives</span> = <span class="var2-color">total_aunts_uncles</span> * <span class="var1-color">people_per_family_unit</span></span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="6">
|
| 282 |
+
<span class="line-number">7</span>
|
| 283 |
+
<span class="comment"># Calculate total people including mother and brother</span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="7">
|
| 286 |
+
<span class="line-number">8</span>
|
| 287 |
+
<span>total_people = <span class="var3-color">total_relatives</span> + <span class="fact5-color">1</span> + <span class="fact4-color">1</span></span>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="variables-display" id="variables-display">
|
| 292 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 293 |
+
<div id="variables-list">
|
| 294 |
+
<div class="variable-item">
|
| 295 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 296 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
|
| 303 |
+
<script>
|
| 304 |
+
class PythonDebugger {
|
| 305 |
+
constructor() {
|
| 306 |
+
this.currentStep = -1;
|
| 307 |
+
this.isPlaying = false;
|
| 308 |
+
this.playInterval = null;
|
| 309 |
+
this.totalSteps = 7;
|
| 310 |
+
this.variables = {};
|
| 311 |
+
|
| 312 |
+
this.initializeElements();
|
| 313 |
+
this.bindEvents();
|
| 314 |
+
this.updateUI();
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
initializeElements() {
|
| 318 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 319 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 320 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 321 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 322 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 323 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
bindEvents() {
|
| 327 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 328 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 329 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 330 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
togglePlay() {
|
| 334 |
+
if (this.isPlaying) {
|
| 335 |
+
this.pause();
|
| 336 |
+
} else {
|
| 337 |
+
this.play();
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
play() {
|
| 342 |
+
this.isPlaying = true;
|
| 343 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 344 |
+
|
| 345 |
+
if (this.currentStep >= this.totalSteps) {
|
| 346 |
+
this.currentStep = -1;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
this.playInterval = setInterval(() => {
|
| 350 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 351 |
+
if (nextStep !== null) {
|
| 352 |
+
this.currentStep = nextStep;
|
| 353 |
+
this.executeStep(this.currentStep);
|
| 354 |
+
this.updateUI();
|
| 355 |
+
} else {
|
| 356 |
+
this.pause();
|
| 357 |
+
}
|
| 358 |
+
}, 1500);
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
pause() {
|
| 362 |
+
this.isPlaying = false;
|
| 363 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 364 |
+
if (this.playInterval) {
|
| 365 |
+
clearInterval(this.playInterval);
|
| 366 |
+
this.playInterval = null;
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
stop() {
|
| 371 |
+
this.pause();
|
| 372 |
+
this.currentStep = -1;
|
| 373 |
+
this.variables = {};
|
| 374 |
+
this.updateUI();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
nextStep() {
|
| 378 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 379 |
+
if (nextStep !== null) {
|
| 380 |
+
this.currentStep = nextStep;
|
| 381 |
+
this.executeStep(this.currentStep);
|
| 382 |
+
this.updateUI();
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
previousStep() {
|
| 387 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 388 |
+
if (prevStep !== null) {
|
| 389 |
+
this.currentStep = prevStep;
|
| 390 |
+
this.recalculateVariables();
|
| 391 |
+
this.updateUI();
|
| 392 |
+
} else if (this.currentStep !== -1) {
|
| 393 |
+
this.currentStep = -1;
|
| 394 |
+
this.variables = {};
|
| 395 |
+
this.updateUI();
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
executeStep(step) {
|
| 400 |
+
switch(step) {
|
| 401 |
+
case 1:
|
| 402 |
+
this.variables.people_per_family_unit = 1 + 1 + 1; // This is the wrong step
|
| 403 |
+
break;
|
| 404 |
+
case 3:
|
| 405 |
+
this.variables.total_aunts_uncles = 3 + 4;
|
| 406 |
+
break;
|
| 407 |
+
case 5:
|
| 408 |
+
this.variables.total_relatives = this.variables.total_aunts_uncles * this.variables.people_per_family_unit;
|
| 409 |
+
break;
|
| 410 |
+
case 7:
|
| 411 |
+
this.variables.total_people = this.variables.total_relatives + 1 + 1;
|
| 412 |
+
break;
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
getExecutableSteps() {
|
| 417 |
+
// Returns only the steps that execute actual code (not comments)
|
| 418 |
+
return [1, 3, 5, 7];
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
getNextExecutableStep(currentStep) {
|
| 422 |
+
const executableSteps = this.getExecutableSteps();
|
| 423 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 424 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
getPreviousExecutableStep(currentStep) {
|
| 428 |
+
const executableSteps = this.getExecutableSteps();
|
| 429 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 430 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
recalculateVariables() {
|
| 434 |
+
this.variables = {};
|
| 435 |
+
const executableSteps = this.getExecutableSteps();
|
| 436 |
+
for (let step of executableSteps) {
|
| 437 |
+
if (step <= this.currentStep) {
|
| 438 |
+
this.executeStep(step);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
updateUI() {
|
| 444 |
+
// Update code highlighting
|
| 445 |
+
this.codeLines.forEach((line, index) => {
|
| 446 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 447 |
+
});
|
| 448 |
+
|
| 449 |
+
// Update button states
|
| 450 |
+
const executableSteps = this.getExecutableSteps();
|
| 451 |
+
const isFirstStep = this.currentStep === -1;
|
| 452 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 453 |
+
|
| 454 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 455 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 456 |
+
|
| 457 |
+
// Update variables display
|
| 458 |
+
this.updateVariablesDisplay();
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
updateVariablesDisplay() {
|
| 462 |
+
if (Object.keys(this.variables).length === 0) {
|
| 463 |
+
this.variablesDisplay.innerHTML = `
|
| 464 |
+
<div class="variable-item">
|
| 465 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 466 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 467 |
+
</div>
|
| 468 |
+
`;
|
| 469 |
+
return;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
let html = '';
|
| 473 |
+
const variableOrder = ['people_per_family_unit', 'total_aunts_uncles', 'total_relatives', 'total_people'];
|
| 474 |
+
|
| 475 |
+
variableOrder.forEach(varName => {
|
| 476 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 477 |
+
const value = this.variables[varName];
|
| 478 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 479 |
+
|
| 480 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 481 |
+
if(varName === lastVarName){
|
| 482 |
+
varName = varName + " (Final Answer)";
|
| 483 |
+
html += `<div class="variable-item ${colorClass}">
|
| 484 |
+
<span class="variable-name">${varName}</span>
|
| 485 |
+
<span class="variable-value">${value}</span>
|
| 486 |
+
</div>`;
|
| 487 |
+
} else {
|
| 488 |
+
html += `<div class="variable-item ${colorClass}">
|
| 489 |
+
<span class="variable-name">${varName}</span>
|
| 490 |
+
<span class="variable-value">${value}</span>
|
| 491 |
+
</div>`;
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
});
|
| 495 |
+
|
| 496 |
+
this.variablesDisplay.innerHTML = html;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
getVariableColorClass(varName) {
|
| 500 |
+
const colorMap = {
|
| 501 |
+
'people_per_family_unit': 'var1-color',
|
| 502 |
+
'total_aunts_uncles': 'var2-color',
|
| 503 |
+
'total_relatives': 'var3-color',
|
| 504 |
+
'total_people': 'fact5-color'
|
| 505 |
+
};
|
| 506 |
+
return colorMap[varName] || '';
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
// Initialize the debugger when the page loads
|
| 511 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 512 |
+
new PythonDebugger();
|
| 513 |
+
});
|
| 514 |
+
</script>
|
| 515 |
+
</body>
|
| 516 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_32.html
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.wrong-step {
|
| 218 |
+
display: none;
|
| 219 |
+
}
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
<span id="fact1" class="fact1-color">Candy has a chair rental business. During the weekdays, 60 chairs are rented each day</span>; but <span id="fact2" class="fact2-color">during weekends, 100 chairs are rented each day</span>. If this continues, <span id="fact3" class="fact3-color">how many chairs in total will Candy be able to rent out in two 4-week months</span>?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Weekday rentals: 60 chairs per day</span></li>
|
| 236 |
+
<li><span class="fact2-color">Weekend rentals: 100 chairs per day</span></li>
|
| 237 |
+
<li><span class="fact3-color">Time period: two 4-week months</span></li>
|
| 238 |
+
</ul>
|
| 239 |
+
<div class="what-to-find">
|
| 240 |
+
<h4>What we need to find:</h4>
|
| 241 |
+
<p>The total number of chairs Candy will rent out in two 4-week months.</p>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="right-panel">
|
| 246 |
+
<div class="debugger-controls">
|
| 247 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 248 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 249 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 250 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="python-solution">
|
| 253 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 254 |
+
<div class="python-code" id="python-code">
|
| 255 |
+
<div class="code-line" data-step="0">
|
| 256 |
+
<span class="line-number">1</span>
|
| 257 |
+
<span class="comment"># Calculate total chairs rented during weekdays in a week</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">2</span>
|
| 261 |
+
<span><span class="var1-color">weekday_rentals_per_week</span> = <span class="fact1-color">60</span> * 5</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">3</span>
|
| 265 |
+
<span class="comment"># Calculate total chairs rented during weekends in a week</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">4</span>
|
| 269 |
+
<span><span class="var2-color">weekend_rentals_per_week</span> = <span class="fact2-color">100</span> * 2</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">5</span>
|
| 273 |
+
<span class="comment"># Calculate total chairs rented in a week</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">6</span>
|
| 277 |
+
<span><span class="var3-color">total_rentals_per_week</span> = <span class="var1-color">weekday_rentals_per_week</span> + <span class="var2-color">weekend_rentals_per_week</span></span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="6">
|
| 280 |
+
<span class="line-number">7</span>
|
| 281 |
+
<span class="comment"># Calculate total chairs rented in a month (4 weeks)</span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="7">
|
| 284 |
+
<span class="line-number">8</span>
|
| 285 |
+
<span><span class="var4-color">total_rentals_per_month</span> = <span class="var3-color">total_rentals_per_week</span> * 4</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="8">
|
| 288 |
+
<span class="line-number">9</span>
|
| 289 |
+
<span class="comment"># Calculate total chairs rented in two months</span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="9">
|
| 292 |
+
<span class="line-number">10</span>
|
| 293 |
+
<span><span class="var5-color">total_rentals_two_months</span> = <span class="var4-color">total_rentals_per_month</span> * 2</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
<div class="variables-display" id="variables-display">
|
| 298 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 299 |
+
<div id="variables-list">
|
| 300 |
+
<div class="variable-item">
|
| 301 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 302 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
|
| 309 |
+
<script>
|
| 310 |
+
class PythonDebugger {
|
| 311 |
+
constructor() {
|
| 312 |
+
this.currentStep = -1;
|
| 313 |
+
this.isPlaying = false;
|
| 314 |
+
this.playInterval = null;
|
| 315 |
+
this.totalSteps = 9;
|
| 316 |
+
this.variables = {};
|
| 317 |
+
|
| 318 |
+
this.initializeElements();
|
| 319 |
+
this.bindEvents();
|
| 320 |
+
this.updateUI();
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
initializeElements() {
|
| 324 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 325 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 326 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 327 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 328 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 329 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
bindEvents() {
|
| 333 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 334 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 335 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 336 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
togglePlay() {
|
| 340 |
+
if (this.isPlaying) {
|
| 341 |
+
this.pause();
|
| 342 |
+
} else {
|
| 343 |
+
this.play();
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
play() {
|
| 348 |
+
this.isPlaying = true;
|
| 349 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 350 |
+
|
| 351 |
+
if (this.currentStep >= this.totalSteps) {
|
| 352 |
+
this.currentStep = -1;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
this.playInterval = setInterval(() => {
|
| 356 |
+
if (this.currentStep < this.totalSteps) {
|
| 357 |
+
this.nextStep();
|
| 358 |
+
} else {
|
| 359 |
+
this.pause();
|
| 360 |
+
}
|
| 361 |
+
}, 1500);
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
pause() {
|
| 365 |
+
this.isPlaying = false;
|
| 366 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 367 |
+
if (this.playInterval) {
|
| 368 |
+
clearInterval(this.playInterval);
|
| 369 |
+
this.playInterval = null;
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
stop() {
|
| 374 |
+
this.pause();
|
| 375 |
+
this.currentStep = -1;
|
| 376 |
+
this.variables = {};
|
| 377 |
+
this.updateUI();
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
nextStep() {
|
| 381 |
+
if (this.currentStep < this.totalSteps) {
|
| 382 |
+
this.currentStep++;
|
| 383 |
+
this.executeStep(this.currentStep);
|
| 384 |
+
this.updateUI();
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
previousStep() {
|
| 389 |
+
if (this.currentStep > 0) {
|
| 390 |
+
this.currentStep--;
|
| 391 |
+
this.recalculateVariables();
|
| 392 |
+
this.updateUI();
|
| 393 |
+
} else if (this.currentStep === 0) {
|
| 394 |
+
this.currentStep = -1;
|
| 395 |
+
this.variables = {};
|
| 396 |
+
this.updateUI();
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
executeStep(step) {
|
| 401 |
+
switch(step) {
|
| 402 |
+
case 1:
|
| 403 |
+
this.variables.weekday_rentals_per_week = 60 * 5;
|
| 404 |
+
break;
|
| 405 |
+
case 3:
|
| 406 |
+
this.variables.weekend_rentals_per_week = 100 * 2;
|
| 407 |
+
break;
|
| 408 |
+
case 5:
|
| 409 |
+
this.variables.total_rentals_per_week = this.variables.weekday_rentals_per_week + this.variables.weekend_rentals_per_week;
|
| 410 |
+
break;
|
| 411 |
+
case 7:
|
| 412 |
+
this.variables.total_rentals_per_month = this.variables.total_rentals_per_week * 4;
|
| 413 |
+
break;
|
| 414 |
+
case 9:
|
| 415 |
+
this.variables.total_rentals_two_months = this.variables.total_rentals_per_month * 2;
|
| 416 |
+
break;
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
recalculateVariables() {
|
| 421 |
+
this.variables = {};
|
| 422 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 423 |
+
this.executeStep(i);
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
updateUI() {
|
| 428 |
+
// Update code highlighting
|
| 429 |
+
this.codeLines.forEach((line, index) => {
|
| 430 |
+
line.classList.remove('current');
|
| 431 |
+
if (index === this.currentStep) {
|
| 432 |
+
line.classList.add('current');
|
| 433 |
+
}
|
| 434 |
+
});
|
| 435 |
+
|
| 436 |
+
// Update button states
|
| 437 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= -1);
|
| 438 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 439 |
+
|
| 440 |
+
// Update variables display
|
| 441 |
+
this.updateVariablesDisplay();
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
updateVariablesDisplay() {
|
| 445 |
+
if (Object.keys(this.variables).length === 0) {
|
| 446 |
+
this.variablesDisplay.innerHTML = `
|
| 447 |
+
<div class="variable-item">
|
| 448 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 449 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 450 |
+
</div>
|
| 451 |
+
`;
|
| 452 |
+
return;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
let html = '';
|
| 456 |
+
const variableOrder = ['weekday_rentals_per_week', 'weekend_rentals_per_week', 'total_rentals_per_week', 'total_rentals_per_month', 'total_rentals_two_months'];
|
| 457 |
+
|
| 458 |
+
variableOrder.forEach(varName => {
|
| 459 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 460 |
+
const value = this.variables[varName];
|
| 461 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 462 |
+
|
| 463 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 464 |
+
if(varName === lastVarName){
|
| 465 |
+
varName = varName + " (Final Answer)";
|
| 466 |
+
html += `<div class="variable-item ${colorClass}">
|
| 467 |
+
<span class="variable-name">${varName}</span>
|
| 468 |
+
<span class="variable-value">${value}</span>
|
| 469 |
+
</div>`;
|
| 470 |
+
} else {
|
| 471 |
+
html += `<div class="variable-item ${colorClass}">
|
| 472 |
+
<span class="variable-name">${varName}</span>
|
| 473 |
+
<span class="variable-value">${value}</span>
|
| 474 |
+
</div>`;
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
});
|
| 478 |
+
|
| 479 |
+
this.variablesDisplay.innerHTML = html;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
getVariableColorClass(varName) {
|
| 483 |
+
const colorMap = {
|
| 484 |
+
'weekday_rentals_per_week': 'var1-color',
|
| 485 |
+
'weekend_rentals_per_week': 'var2-color',
|
| 486 |
+
'total_rentals_per_week': 'var3-color',
|
| 487 |
+
'total_rentals_per_month': 'var4-color',
|
| 488 |
+
'total_rentals_two_months': 'var5-color'
|
| 489 |
+
};
|
| 490 |
+
return colorMap[varName] || '';
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
// Initialize the debugger when the page loads
|
| 495 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 496 |
+
new PythonDebugger();
|
| 497 |
+
});
|
| 498 |
+
</script>
|
| 499 |
+
</body>
|
| 500 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_33.html
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Yoque borrowed money from her sister and promised to pay it back in 11 months</span> <span id="fact2" class="fact2-color">including an additional 10% of the money she borrowed</span>. <span id="fact3" class="fact3-color">If she pays $15 per month</span>, how much money did she borrow?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Repayment period: 11 months</span></li>
|
| 235 |
+
<li><span class="fact2-color">Additional payment: 10%</span></li>
|
| 236 |
+
<li><span class="fact3-color">Monthly payment: $15</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find</h4>
|
| 240 |
+
<p>How much money did Yoque borrow from her sister?</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># Calculate total payment over 11 months</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">total_payment</span> = <span class="fact3-color">15</span> * <span class="fact1-color">11</span></span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Calculate the percentage of the borrowed amount</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">percentage</span> = 100 + <span class="fact2-color">10</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Calculate the value of 1%</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">one_percent</span> = <span class="var1-color">total_payment</span> / <span class="var2-color">percentage</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="6">
|
| 279 |
+
<span class="line-number">7</span>
|
| 280 |
+
<span class="comment"># Calculate the borrowed amount</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="7">
|
| 283 |
+
<span class="line-number">8</span>
|
| 284 |
+
<span><span class="var4-color">borrowed_amount</span> = <span class="var3-color">one_percent</span> * 100</span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="variables-display" id="variables-display">
|
| 289 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 290 |
+
<div id="variables-list">
|
| 291 |
+
<div class="variable-item">
|
| 292 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 293 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
class PythonDebugger {
|
| 302 |
+
constructor() {
|
| 303 |
+
this.currentStep = -1;
|
| 304 |
+
this.isPlaying = false;
|
| 305 |
+
this.playInterval = null;
|
| 306 |
+
this.totalSteps = 7;
|
| 307 |
+
this.variables = {};
|
| 308 |
+
|
| 309 |
+
this.initializeElements();
|
| 310 |
+
this.bindEvents();
|
| 311 |
+
this.updateUI();
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
initializeElements() {
|
| 315 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 316 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 317 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 318 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 319 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 320 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
bindEvents() {
|
| 324 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 325 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 326 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 327 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
togglePlay() {
|
| 331 |
+
if (this.isPlaying) {
|
| 332 |
+
this.pause();
|
| 333 |
+
} else {
|
| 334 |
+
this.play();
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
play() {
|
| 339 |
+
this.isPlaying = true;
|
| 340 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 341 |
+
|
| 342 |
+
if (this.currentStep >= this.totalSteps) {
|
| 343 |
+
this.currentStep = -1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
this.playInterval = setInterval(() => {
|
| 347 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 348 |
+
if (nextStep !== null) {
|
| 349 |
+
this.currentStep = nextStep;
|
| 350 |
+
this.executeStep(this.currentStep);
|
| 351 |
+
this.updateUI();
|
| 352 |
+
} else {
|
| 353 |
+
this.pause();
|
| 354 |
+
}
|
| 355 |
+
}, 1500);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
pause() {
|
| 359 |
+
this.isPlaying = false;
|
| 360 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 361 |
+
if (this.playInterval) {
|
| 362 |
+
clearInterval(this.playInterval);
|
| 363 |
+
this.playInterval = null;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
stop() {
|
| 368 |
+
this.pause();
|
| 369 |
+
this.currentStep = -1;
|
| 370 |
+
this.variables = {};
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
nextStep() {
|
| 375 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 376 |
+
if (nextStep !== null) {
|
| 377 |
+
this.currentStep = nextStep;
|
| 378 |
+
this.executeStep(this.currentStep);
|
| 379 |
+
this.updateUI();
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
previousStep() {
|
| 384 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 385 |
+
if (prevStep !== null) {
|
| 386 |
+
this.currentStep = prevStep;
|
| 387 |
+
this.recalculateVariables();
|
| 388 |
+
this.updateUI();
|
| 389 |
+
} else if (this.currentStep !== -1) {
|
| 390 |
+
this.currentStep = -1;
|
| 391 |
+
this.variables = {};
|
| 392 |
+
this.updateUI();
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
executeStep(step) {
|
| 397 |
+
switch(step) {
|
| 398 |
+
case 1:
|
| 399 |
+
this.variables.total_payment = 15 * 11;
|
| 400 |
+
break;
|
| 401 |
+
case 3:
|
| 402 |
+
this.variables.percentage = 100 + 10;
|
| 403 |
+
break;
|
| 404 |
+
case 5:
|
| 405 |
+
this.variables.one_percent = this.variables.total_payment / this.variables.percentage;
|
| 406 |
+
break;
|
| 407 |
+
case 7:
|
| 408 |
+
this.variables.borrowed_amount = this.variables.one_percent * 100;
|
| 409 |
+
break;
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
getExecutableSteps() {
|
| 414 |
+
// Returns only the steps that execute actual code (not comments)
|
| 415 |
+
return [1, 3, 5, 7];
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
getNextExecutableStep(currentStep) {
|
| 419 |
+
const executableSteps = this.getExecutableSteps();
|
| 420 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 421 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
getPreviousExecutableStep(currentStep) {
|
| 425 |
+
const executableSteps = this.getExecutableSteps();
|
| 426 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 427 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
recalculateVariables() {
|
| 431 |
+
this.variables = {};
|
| 432 |
+
const executableSteps = this.getExecutableSteps();
|
| 433 |
+
for (let step of executableSteps) {
|
| 434 |
+
if (step <= this.currentStep) {
|
| 435 |
+
this.executeStep(step);
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
updateUI() {
|
| 441 |
+
// Update code highlighting
|
| 442 |
+
this.codeLines.forEach((line, index) => {
|
| 443 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 444 |
+
});
|
| 445 |
+
|
| 446 |
+
// Update button states
|
| 447 |
+
const executableSteps = this.getExecutableSteps();
|
| 448 |
+
const isFirstStep = this.currentStep === -1;
|
| 449 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 450 |
+
|
| 451 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 452 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 453 |
+
|
| 454 |
+
// Update variables display
|
| 455 |
+
this.updateVariablesDisplay();
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
updateVariablesDisplay() {
|
| 459 |
+
if (Object.keys(this.variables).length === 0) {
|
| 460 |
+
this.variablesDisplay.innerHTML = `
|
| 461 |
+
<div class="variable-item">
|
| 462 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 463 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 464 |
+
</div>
|
| 465 |
+
`;
|
| 466 |
+
return;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
let html = '';
|
| 470 |
+
const variableOrder = ['total_payment', 'percentage', 'one_percent', 'borrowed_amount'];
|
| 471 |
+
|
| 472 |
+
variableOrder.forEach(varName => {
|
| 473 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 474 |
+
const value = this.variables[varName];
|
| 475 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 476 |
+
const displayValue = varName.includes('payment') || varName.includes('amount') || varName.includes('percent') ?
|
| 477 |
+
`$${value.toFixed(2)}` : value;
|
| 478 |
+
|
| 479 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 480 |
+
if(varName === lastVarName){
|
| 481 |
+
varName = varName + " (Final Answer)";
|
| 482 |
+
html += `<div class="variable-item ${colorClass}">
|
| 483 |
+
<span class="variable-name">${varName}</span>
|
| 484 |
+
<span class="variable-value">${value}</span>
|
| 485 |
+
</div>`;
|
| 486 |
+
} else {
|
| 487 |
+
html += `<div class="variable-item ${colorClass}">
|
| 488 |
+
<span class="variable-name">${varName}</span>
|
| 489 |
+
<span class="variable-value">${value}</span>
|
| 490 |
+
</div>`;
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
});
|
| 494 |
+
|
| 495 |
+
this.variablesDisplay.innerHTML = html;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
getVariableColorClass(varName) {
|
| 499 |
+
const colorMap = {
|
| 500 |
+
'total_payment': 'var1-color',
|
| 501 |
+
'percentage': 'var2-color',
|
| 502 |
+
'one_percent': 'var3-color',
|
| 503 |
+
'borrowed_amount': 'var4-color'
|
| 504 |
+
};
|
| 505 |
+
return colorMap[varName] || '';
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
// Initialize the debugger when the page loads
|
| 510 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 511 |
+
new PythonDebugger();
|
| 512 |
+
});
|
| 513 |
+
</script>
|
| 514 |
+
</body>
|
| 515 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_34.html
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 195 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 196 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var5-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 198 |
+
|
| 199 |
+
ul {
|
| 200 |
+
padding-left: 20px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
li {
|
| 204 |
+
margin-bottom: 12px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.what-to-find {
|
| 208 |
+
margin-top: 20px;
|
| 209 |
+
padding: 15px;
|
| 210 |
+
background-color: #e8f4fd;
|
| 211 |
+
border-radius: 6px;
|
| 212 |
+
border-left: 4px solid #3498db;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.what-to-find h4 {
|
| 216 |
+
color: #2c3e50;
|
| 217 |
+
margin-bottom: 8px;
|
| 218 |
+
}
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
</style>
|
| 224 |
+
</head>
|
| 225 |
+
<body>
|
| 226 |
+
<div class="wrong-step">0</div>
|
| 227 |
+
<div class="container">
|
| 228 |
+
<div class="left-panel">
|
| 229 |
+
<div class="problem-statement">
|
| 230 |
+
<div class="section-title">Problem Statement</div>
|
| 231 |
+
<p>
|
| 232 |
+
<span id="fact1" class="fact1-color">Steve bought $25 worth of groceries.</span> He bought <span id="fact2" class="fact2-color">a gallon of milk for $3</span>, <span id="fact3" class="fact3-color">two boxes of cereal for $3.5 each</span>, <span id="fact4" class="fact4-color">4 bananas for $.25 each</span>, <span id="fact5" class="fact5-color">four apples that cost $.5 each</span> and a number of boxes of cookies. <span id="fact6" class="fact6-color">The cookies cost twice as much per box as the gallon of milk.</span> How many boxes of cookies did he get?
|
| 233 |
+
</p>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="problem-understanding">
|
| 236 |
+
<div class="section-title">Problem Summary</div>
|
| 237 |
+
<ul>
|
| 238 |
+
<li><span class="fact1-color">Total grocery cost: $25</span></li>
|
| 239 |
+
<li><span class="fact2-color">Milk cost: $3</span></li>
|
| 240 |
+
<li><span class="fact3-color">Cereal: 2 boxes at $3.5 each</span></li>
|
| 241 |
+
<li><span class="fact4-color">Bananas: 4 at $0.25 each</span></li>
|
| 242 |
+
<li><span class="fact5-color">Apples: 4 at $0.5 each</span></li>
|
| 243 |
+
<li><span class="fact6-color">Cookie cost per box: 2 times milk cost</span></li>
|
| 244 |
+
</ul>
|
| 245 |
+
<div class="what-to-find">
|
| 246 |
+
<h4>What we need to find</h4>
|
| 247 |
+
<p>How many boxes of cookies did Steve get?</p>
|
| 248 |
+
</div>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="right-panel">
|
| 252 |
+
<div class="debugger-controls">
|
| 253 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 254 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 255 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 256 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="python-solution">
|
| 259 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 260 |
+
<div class="python-code" id="python-code">
|
| 261 |
+
<div class="code-line" data-step="0">
|
| 262 |
+
<span class="line-number">1</span>
|
| 263 |
+
<span class="comment"># Calculate the total cost of cereal</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="1">
|
| 266 |
+
<span class="line-number">2</span>
|
| 267 |
+
<span><span class="var1-color">cereal_cost</span> = <span class="fact3-color">2</span> * <span class="fact3-color">3.5</span></span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="2">
|
| 270 |
+
<span class="line-number">3</span>
|
| 271 |
+
<span class="comment"># Calculate the total cost of bananas</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="3">
|
| 274 |
+
<span class="line-number">4</span>
|
| 275 |
+
<span><span class="var2-color">banana_cost</span> = <span class="fact4-color">4</span> * <span class="fact4-color">0.25</span></span>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="code-line" data-step="4">
|
| 278 |
+
<span class="line-number">5</span>
|
| 279 |
+
<span class="comment"># Calculate the total cost of apples</span>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="code-line" data-step="5">
|
| 282 |
+
<span class="line-number">6</span>
|
| 283 |
+
<span><span class="var3-color">apple_cost</span> = <span class="fact5-color">4</span> * <span class="fact5-color">0.5</span></span>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="code-line" data-step="6">
|
| 286 |
+
<span class="line-number">7</span>
|
| 287 |
+
<span class="comment"># Calculate the cost of everything but cookies</span>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="code-line" data-step="7">
|
| 290 |
+
<span class="line-number">8</span>
|
| 291 |
+
<span><span class="var4-color">non_cookie_cost</span> = <span class="fact2-color">3</span> + <span class="var1-color">cereal_cost</span> + <span class="var2-color">banana_cost</span> + <span class="var3-color">apple_cost</span></span>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="code-line" data-step="8">
|
| 294 |
+
<span class="line-number">9</span>
|
| 295 |
+
<span class="comment"># Calculate the cost spent on cookies</span>
|
| 296 |
+
</div>
|
| 297 |
+
<div class="code-line" data-step="9">
|
| 298 |
+
<span class="line-number">10</span>
|
| 299 |
+
<span><span class="var5-color">cookie_cost</span> = <span class="fact1-color">25</span> - <span class="var4-color">non_cookie_cost</span></span>
|
| 300 |
+
</div>
|
| 301 |
+
<div class="code-line" data-step="10">
|
| 302 |
+
<span class="line-number">11</span>
|
| 303 |
+
<span class="comment"># Calculate the cost of each box of cookies</span>
|
| 304 |
+
</div>
|
| 305 |
+
<div class="code-line" data-step="11">
|
| 306 |
+
<span class="line-number">12</span>
|
| 307 |
+
<span><span class="fact6-color">cookie_box_cost</span> = <span class="fact2-color">3</span> * <span class="fact6-color">2</span></span>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="code-line" data-step="12">
|
| 310 |
+
<span class="line-number">13</span>
|
| 311 |
+
<span class="comment"># Calculate the number of cookie boxes</span>
|
| 312 |
+
</div>
|
| 313 |
+
<div class="code-line" data-step="13">
|
| 314 |
+
<span class="line-number">14</span>
|
| 315 |
+
<span>cookie_boxes = <span class="var5-color">cookie_cost</span> / <span class="fact6-color">cookie_box_cost</span></span>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
<div class="variables-display" id="variables-display">
|
| 320 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 321 |
+
<div id="variables-list">
|
| 322 |
+
<div class="variable-item">
|
| 323 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 324 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
</div>
|
| 329 |
+
</div>
|
| 330 |
+
|
| 331 |
+
<script>
|
| 332 |
+
class PythonDebugger {
|
| 333 |
+
constructor() {
|
| 334 |
+
this.currentStep = -1;
|
| 335 |
+
this.isPlaying = false;
|
| 336 |
+
this.playInterval = null;
|
| 337 |
+
this.totalSteps = 13;
|
| 338 |
+
this.variables = {};
|
| 339 |
+
|
| 340 |
+
this.initializeElements();
|
| 341 |
+
this.bindEvents();
|
| 342 |
+
this.updateUI();
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
initializeElements() {
|
| 346 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 347 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 348 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 349 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 350 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 351 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
bindEvents() {
|
| 355 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 356 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 357 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 358 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
togglePlay() {
|
| 362 |
+
if (this.isPlaying) {
|
| 363 |
+
this.pause();
|
| 364 |
+
} else {
|
| 365 |
+
this.play();
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
play() {
|
| 370 |
+
this.isPlaying = true;
|
| 371 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 372 |
+
|
| 373 |
+
if (this.currentStep >= this.totalSteps) {
|
| 374 |
+
this.currentStep = -1;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
this.playInterval = setInterval(() => {
|
| 378 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 379 |
+
if (nextStep !== null) {
|
| 380 |
+
this.currentStep = nextStep;
|
| 381 |
+
this.executeStep(this.currentStep);
|
| 382 |
+
this.updateUI();
|
| 383 |
+
} else {
|
| 384 |
+
this.pause();
|
| 385 |
+
}
|
| 386 |
+
}, 1500);
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
pause() {
|
| 390 |
+
this.isPlaying = false;
|
| 391 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 392 |
+
if (this.playInterval) {
|
| 393 |
+
clearInterval(this.playInterval);
|
| 394 |
+
this.playInterval = null;
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
stop() {
|
| 399 |
+
this.pause();
|
| 400 |
+
this.currentStep = -1;
|
| 401 |
+
this.variables = {};
|
| 402 |
+
this.updateUI();
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
nextStep() {
|
| 406 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 407 |
+
if (nextStep !== null) {
|
| 408 |
+
this.currentStep = nextStep;
|
| 409 |
+
this.executeStep(this.currentStep);
|
| 410 |
+
this.updateUI();
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
previousStep() {
|
| 415 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 416 |
+
if (prevStep !== null) {
|
| 417 |
+
this.currentStep = prevStep;
|
| 418 |
+
this.recalculateVariables();
|
| 419 |
+
this.updateUI();
|
| 420 |
+
} else if (this.currentStep !== -1) {
|
| 421 |
+
this.currentStep = -1;
|
| 422 |
+
this.variables = {};
|
| 423 |
+
this.updateUI();
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
executeStep(step) {
|
| 428 |
+
switch(step) {
|
| 429 |
+
case 1:
|
| 430 |
+
this.variables.cereal_cost = 2 * 3.5;
|
| 431 |
+
break;
|
| 432 |
+
case 3:
|
| 433 |
+
this.variables.banana_cost = 4 * 0.25;
|
| 434 |
+
break;
|
| 435 |
+
case 5:
|
| 436 |
+
this.variables.apple_cost = 4 * 0.5;
|
| 437 |
+
break;
|
| 438 |
+
case 7:
|
| 439 |
+
// This is the wrong step (step 4 in the unformatted information)
|
| 440 |
+
this.variables.non_cookie_cost = 3 + this.variables.cereal_cost + this.variables.banana_cost + this.variables.apple_cost;
|
| 441 |
+
break;
|
| 442 |
+
case 9:
|
| 443 |
+
this.variables.cookie_cost = 25 - this.variables.non_cookie_cost;
|
| 444 |
+
break;
|
| 445 |
+
case 11:
|
| 446 |
+
this.variables.cookie_box_cost = 3 * 2;
|
| 447 |
+
break;
|
| 448 |
+
case 13:
|
| 449 |
+
this.variables.cookie_boxes = this.variables.cookie_cost / this.variables.cookie_box_cost;
|
| 450 |
+
break;
|
| 451 |
+
}
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
getExecutableSteps() {
|
| 455 |
+
// Returns only the steps that execute actual code (not comments)
|
| 456 |
+
return [1, 3, 5, 7, 9, 11, 13];
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
getNextExecutableStep(currentStep) {
|
| 460 |
+
const executableSteps = this.getExecutableSteps();
|
| 461 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 462 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
getPreviousExecutableStep(currentStep) {
|
| 466 |
+
const executableSteps = this.getExecutableSteps();
|
| 467 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 468 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
recalculateVariables() {
|
| 472 |
+
this.variables = {};
|
| 473 |
+
const executableSteps = this.getExecutableSteps();
|
| 474 |
+
for (let step of executableSteps) {
|
| 475 |
+
if (step <= this.currentStep) {
|
| 476 |
+
this.executeStep(step);
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
updateUI() {
|
| 482 |
+
// Update code highlighting
|
| 483 |
+
this.codeLines.forEach((line, index) => {
|
| 484 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 485 |
+
});
|
| 486 |
+
|
| 487 |
+
// Update button states
|
| 488 |
+
const executableSteps = this.getExecutableSteps();
|
| 489 |
+
const isFirstStep = this.currentStep === -1;
|
| 490 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 491 |
+
|
| 492 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 493 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 494 |
+
|
| 495 |
+
// Update variables display
|
| 496 |
+
this.updateVariablesDisplay();
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
updateVariablesDisplay() {
|
| 500 |
+
if (Object.keys(this.variables).length === 0) {
|
| 501 |
+
this.variablesDisplay.innerHTML = `
|
| 502 |
+
<div class="variable-item">
|
| 503 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 504 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 505 |
+
</div>
|
| 506 |
+
`;
|
| 507 |
+
return;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
let html = '';
|
| 511 |
+
const variableOrder = ['cereal_cost', 'banana_cost', 'apple_cost', 'non_cookie_cost', 'cookie_cost', 'cookie_box_cost', 'cookie_boxes'];
|
| 512 |
+
|
| 513 |
+
variableOrder.forEach(varName => {
|
| 514 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 515 |
+
const value = this.variables[varName];
|
| 516 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 517 |
+
const displayValue = typeof value === 'number' ?
|
| 518 |
+
(varName.includes('cost') ? `$${value.toFixed(2)}` : value) :
|
| 519 |
+
value;
|
| 520 |
+
|
| 521 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 522 |
+
if(varName === lastVarName){
|
| 523 |
+
varName = varName + " (Final Answer)";
|
| 524 |
+
html += `<div class="variable-item ${colorClass}">
|
| 525 |
+
<span class="variable-name">${varName}</span>
|
| 526 |
+
<span class="variable-value">${value}</span>
|
| 527 |
+
</div>`;
|
| 528 |
+
} else {
|
| 529 |
+
html += `<div class="variable-item ${colorClass}">
|
| 530 |
+
<span class="variable-name">${varName}</span>
|
| 531 |
+
<span class="variable-value">${value}</span>
|
| 532 |
+
</div>`;
|
| 533 |
+
}
|
| 534 |
+
}
|
| 535 |
+
});
|
| 536 |
+
|
| 537 |
+
this.variablesDisplay.innerHTML = html;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
getVariableColorClass(varName) {
|
| 541 |
+
const colorMap = {
|
| 542 |
+
'cereal_cost': 'var1-color',
|
| 543 |
+
'banana_cost': 'var2-color',
|
| 544 |
+
'apple_cost': 'var3-color',
|
| 545 |
+
'non_cookie_cost': 'var4-color',
|
| 546 |
+
'cookie_cost': 'var5-color',
|
| 547 |
+
'cookie_box_cost': 'fact6-color',
|
| 548 |
+
'cookie_boxes': 'fact1-color'
|
| 549 |
+
};
|
| 550 |
+
return colorMap[varName] || '';
|
| 551 |
+
}
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
// Initialize the debugger when the page loads
|
| 555 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 556 |
+
new PythonDebugger();
|
| 557 |
+
});
|
| 558 |
+
</script>
|
| 559 |
+
</body>
|
| 560 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_35.html
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.wrong-step {
|
| 217 |
+
display: none;
|
| 218 |
+
}
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">Martin went on an eight-hour business trip.</span> During the first half of the trip, he traveled at a speed of <span id="fact2" class="fact2-color">70 kilometers per hour</span> and during the second half at a speed of <span id="fact3" class="fact3-color">85 kilometers per hour</span>. How many kilometers did he travel during the journey?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Trip duration: 8 hours</span></li>
|
| 235 |
+
<li><span class="fact2-color">First half speed: 70 kilometers per hour</span></li>
|
| 236 |
+
<li><span class="fact3-color">Second half speed: 85 kilometers per hour</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find</h4>
|
| 240 |
+
<p>The total distance Martin traveled during his business trip.</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># Calculate half of the trip duration</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">half_trip_duration</span> = <span class="fact1-color">8</span> * 0.5</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Calculate distance traveled during first half</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">first_half_distance</span> = <span class="var1-color">half_trip_duration</span> * <span class="fact2-color">70</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Calculate distance traveled during second half</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">second_half_distance</span> = <span class="var1-color">half_trip_duration</span> * <span class="fact3-color">85</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="6">
|
| 279 |
+
<span class="line-number">7</span>
|
| 280 |
+
<span class="comment"># Calculate total distance traveled</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="7">
|
| 283 |
+
<span class="line-number">8</span>
|
| 284 |
+
<span><span class="var4-color">total_distance</span> = <span class="var2-color">first_half_distance</span> + <span class="var3-color">second_half_distance</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="variables-display" id="variables-display">
|
| 289 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 290 |
+
<div id="variables-list">
|
| 291 |
+
<div class="variable-item">
|
| 292 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 293 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
class PythonDebugger {
|
| 302 |
+
constructor() {
|
| 303 |
+
this.currentStep = -1;
|
| 304 |
+
this.isPlaying = false;
|
| 305 |
+
this.playInterval = null;
|
| 306 |
+
this.totalSteps = 7;
|
| 307 |
+
this.variables = {};
|
| 308 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 309 |
+
|
| 310 |
+
this.initializeElements();
|
| 311 |
+
this.bindEvents();
|
| 312 |
+
this.updateUI();
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
initializeElements() {
|
| 316 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 317 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 318 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 319 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 320 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 321 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
bindEvents() {
|
| 325 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 326 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 327 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 328 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
togglePlay() {
|
| 332 |
+
if (this.isPlaying) {
|
| 333 |
+
this.pause();
|
| 334 |
+
} else {
|
| 335 |
+
this.play();
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
play() {
|
| 340 |
+
this.isPlaying = true;
|
| 341 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 342 |
+
|
| 343 |
+
if (this.currentStep >= this.totalSteps) {
|
| 344 |
+
this.currentStep = -1;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
this.playInterval = setInterval(() => {
|
| 348 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 349 |
+
if (nextStep !== null) {
|
| 350 |
+
this.currentStep = nextStep;
|
| 351 |
+
this.executeStep(this.currentStep);
|
| 352 |
+
this.updateUI();
|
| 353 |
+
} else {
|
| 354 |
+
this.pause();
|
| 355 |
+
}
|
| 356 |
+
}, 1500);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
pause() {
|
| 360 |
+
this.isPlaying = false;
|
| 361 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 362 |
+
if (this.playInterval) {
|
| 363 |
+
clearInterval(this.playInterval);
|
| 364 |
+
this.playInterval = null;
|
| 365 |
+
}
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
stop() {
|
| 369 |
+
this.pause();
|
| 370 |
+
this.currentStep = -1;
|
| 371 |
+
this.variables = {};
|
| 372 |
+
this.updateUI();
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
nextStep() {
|
| 376 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 377 |
+
if (nextStep !== null) {
|
| 378 |
+
this.currentStep = nextStep;
|
| 379 |
+
this.executeStep(this.currentStep);
|
| 380 |
+
this.updateUI();
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
previousStep() {
|
| 385 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 386 |
+
if (prevStep !== null) {
|
| 387 |
+
this.currentStep = prevStep;
|
| 388 |
+
this.recalculateVariables();
|
| 389 |
+
this.updateUI();
|
| 390 |
+
} else if (this.currentStep !== -1) {
|
| 391 |
+
this.currentStep = -1;
|
| 392 |
+
this.variables = {};
|
| 393 |
+
this.updateUI();
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
executeStep(step) {
|
| 398 |
+
switch(step) {
|
| 399 |
+
case 1:
|
| 400 |
+
this.variables.half_trip_duration = 8 * 0.5;
|
| 401 |
+
break;
|
| 402 |
+
case 3:
|
| 403 |
+
this.variables.first_half_distance = this.variables.half_trip_duration * 70;
|
| 404 |
+
break;
|
| 405 |
+
case 5:
|
| 406 |
+
// Intentional error in step 3 (which is step 5 in our code)
|
| 407 |
+
if (step === this.wrongStep) {
|
| 408 |
+
this.variables.second_half_distance = this.variables.half_trip_duration * 85;
|
| 409 |
+
} else {
|
| 410 |
+
this.variables.second_half_distance = this.variables.half_trip_duration * 85;
|
| 411 |
+
}
|
| 412 |
+
break;
|
| 413 |
+
case 7:
|
| 414 |
+
this.variables.total_distance = this.variables.first_half_distance + this.variables.second_half_distance;
|
| 415 |
+
break;
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
getExecutableSteps() {
|
| 420 |
+
// Returns only the steps that execute actual code (not comments)
|
| 421 |
+
return [1, 3, 5, 7];
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
getNextExecutableStep(currentStep) {
|
| 425 |
+
const executableSteps = this.getExecutableSteps();
|
| 426 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 427 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
getPreviousExecutableStep(currentStep) {
|
| 431 |
+
const executableSteps = this.getExecutableSteps();
|
| 432 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 433 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
recalculateVariables() {
|
| 437 |
+
this.variables = {};
|
| 438 |
+
const executableSteps = this.getExecutableSteps();
|
| 439 |
+
for (let step of executableSteps) {
|
| 440 |
+
if (step <= this.currentStep) {
|
| 441 |
+
this.executeStep(step);
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
updateUI() {
|
| 447 |
+
// Update code highlighting
|
| 448 |
+
this.codeLines.forEach((line, index) => {
|
| 449 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 450 |
+
});
|
| 451 |
+
|
| 452 |
+
// Update button states
|
| 453 |
+
const executableSteps = this.getExecutableSteps();
|
| 454 |
+
const isFirstStep = this.currentStep === -1;
|
| 455 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 456 |
+
|
| 457 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 458 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 459 |
+
|
| 460 |
+
// Update variables display
|
| 461 |
+
this.updateVariablesDisplay();
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
updateVariablesDisplay() {
|
| 465 |
+
if (Object.keys(this.variables).length === 0) {
|
| 466 |
+
this.variablesDisplay.innerHTML = `
|
| 467 |
+
<div class="variable-item">
|
| 468 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 469 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 470 |
+
</div>
|
| 471 |
+
`;
|
| 472 |
+
return;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
let html = '';
|
| 476 |
+
const variableOrder = ['half_trip_duration', 'first_half_distance', 'second_half_distance', 'total_distance'];
|
| 477 |
+
|
| 478 |
+
variableOrder.forEach(varName => {
|
| 479 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 480 |
+
const value = this.variables[varName];
|
| 481 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 482 |
+
|
| 483 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 484 |
+
if(varName === lastVarName){
|
| 485 |
+
varName = varName + " (Final Answer)";
|
| 486 |
+
html += `<div class="variable-item ${colorClass}">
|
| 487 |
+
<span class="variable-name">${varName}</span>
|
| 488 |
+
<span class="variable-value">${value}</span>
|
| 489 |
+
</div>`;
|
| 490 |
+
} else {
|
| 491 |
+
html += `<div class="variable-item ${colorClass}">
|
| 492 |
+
<span class="variable-name">${varName}</span>
|
| 493 |
+
<span class="variable-value">${value}</span>
|
| 494 |
+
</div>`;
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
});
|
| 498 |
+
|
| 499 |
+
this.variablesDisplay.innerHTML = html;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
getVariableColorClass(varName) {
|
| 503 |
+
const colorMap = {
|
| 504 |
+
'half_trip_duration': 'var1-color',
|
| 505 |
+
'first_half_distance': 'var2-color',
|
| 506 |
+
'second_half_distance': 'var3-color',
|
| 507 |
+
'total_distance': 'var4-color'
|
| 508 |
+
};
|
| 509 |
+
return colorMap[varName] || '';
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
// Initialize the debugger when the page loads
|
| 514 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 515 |
+
new PythonDebugger();
|
| 516 |
+
});
|
| 517 |
+
</script>
|
| 518 |
+
</body>
|
| 519 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_36.html
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
.var5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 196 |
+
.var6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 197 |
+
|
| 198 |
+
ul {
|
| 199 |
+
padding-left: 20px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
li {
|
| 203 |
+
margin-bottom: 12px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.what-to-find {
|
| 207 |
+
margin-top: 20px;
|
| 208 |
+
padding: 15px;
|
| 209 |
+
background-color: #e8f4fd;
|
| 210 |
+
border-radius: 6px;
|
| 211 |
+
border-left: 4px solid #3498db;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.what-to-find h4 {
|
| 215 |
+
color: #2c3e50;
|
| 216 |
+
margin-bottom: 8px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.wrong-step {
|
| 220 |
+
display: none;
|
| 221 |
+
}
|
| 222 |
+
</style>
|
| 223 |
+
</head>
|
| 224 |
+
<body>
|
| 225 |
+
<div class="wrong-step">0</div>
|
| 226 |
+
<div class="container">
|
| 227 |
+
<div class="left-panel">
|
| 228 |
+
<div class="problem-statement">
|
| 229 |
+
<div class="section-title">Problem Statement</div>
|
| 230 |
+
<p>
|
| 231 |
+
<span id="fact1" class="fact1-color">Jackson's mom promises $5 per hour spent on chores.</span>
|
| 232 |
+
<span id="fact2" class="fact2-color">Jackson spends 2 hours vacuuming, and decides to do this twice.</span>
|
| 233 |
+
<span id="fact3" class="fact3-color">He also spends 0.5 hours washing dishes.</span>
|
| 234 |
+
<span id="fact4" class="fact4-color">He spends three times as long cleaning the bathroom as washing dishes.</span>
|
| 235 |
+
</p>
|
| 236 |
+
</div>
|
| 237 |
+
<div class="problem-understanding">
|
| 238 |
+
<div class="section-title">Problem Summary</div>
|
| 239 |
+
<ul>
|
| 240 |
+
<li><span class="fact1-color">Rate per hour: $5</span></li>
|
| 241 |
+
<li><span class="fact2-color">Hours vacuuming (each time): 2</span></li>
|
| 242 |
+
<li><span class="fact2-color">Number of times vacuuming: 2</span></li>
|
| 243 |
+
<li><span class="fact3-color">Hours washing dishes: 0.5</span></li>
|
| 244 |
+
<li><span class="fact4-color">Bathroom cleaning multiplier: 3</span></li>
|
| 245 |
+
</ul>
|
| 246 |
+
<div class="what-to-find">
|
| 247 |
+
<h4>What we need to find:</h4>
|
| 248 |
+
<p>We need to calculate the total amount of money Jackson earned from all chores.</p>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="right-panel">
|
| 253 |
+
<div class="debugger-controls">
|
| 254 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 255 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 256 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 257 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="python-solution">
|
| 260 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 261 |
+
<div class="python-code" id="python-code">
|
| 262 |
+
<div class="code-line" data-step="1">
|
| 263 |
+
<span class="line-number">1</span>
|
| 264 |
+
<span class="comment"># Calculate total hours spent vacuuming</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="1">
|
| 267 |
+
<span class="line-number">2</span>
|
| 268 |
+
<span><span class="var1-color">hours_vacuuming</span> = <span class="fact2-color">2</span> * <span class="fact2-color">2</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="2">
|
| 271 |
+
<span class="line-number">3</span>
|
| 272 |
+
<span class="comment"># Calculate money earned from vacuuming</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="2">
|
| 275 |
+
<span class="line-number">4</span>
|
| 276 |
+
<span><span class="var2-color">vacuuming_money</span> = <span class="var1-color">hours_vacuuming</span> * <span class="fact1-color">5</span></span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="3">
|
| 279 |
+
<span class="line-number">5</span>
|
| 280 |
+
<span class="comment"># Calculate money earned from washing dishes</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="3">
|
| 283 |
+
<span class="line-number">6</span>
|
| 284 |
+
<span><span class="var3-color">dishes_money</span> = <span class="fact3-color">0.5</span> * <span class="fact1-color">5</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="code-line" data-step="4">
|
| 287 |
+
<span class="line-number">7</span>
|
| 288 |
+
<span class="comment"># Calculate time spent cleaning the bathroom</span>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="code-line" data-step="4">
|
| 291 |
+
<span class="line-number">8</span>
|
| 292 |
+
<span><span class="var4-color">bathroom_time</span> = <span class="fact3-color">0.5</span> * <span class="fact4-color">3</span></span>
|
| 293 |
+
</div>
|
| 294 |
+
<div class="code-line" data-step="5">
|
| 295 |
+
<span class="line-number">9</span>
|
| 296 |
+
<span class="comment"># Calculate money earned from cleaning the bathroom</span>
|
| 297 |
+
</div>
|
| 298 |
+
<div class="code-line" data-step="5">
|
| 299 |
+
<span class="line-number">10</span>
|
| 300 |
+
<span><span class="var5-color">bathroom_money</span> = <span class="var4-color">bathroom_time</span> * <span class="fact1-color">5</span></span>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="code-line" data-step="6">
|
| 303 |
+
<span class="line-number">11</span>
|
| 304 |
+
<span class="comment"># Calculate total money earned from all chores</span>
|
| 305 |
+
</div>
|
| 306 |
+
<div class="code-line" data-step="6">
|
| 307 |
+
<span class="line-number">12</span>
|
| 308 |
+
<span><span class="var6-color">total_money</span> = <span class="var2-color">vacuuming_money</span> + <span class="var3-color">dishes_money</span> + <span class="var5-color">bathroom_money</span></span>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
<div class="variables-display" id="variables-display">
|
| 313 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 314 |
+
<div id="variables-list">
|
| 315 |
+
<div class="variable-item">
|
| 316 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 317 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 318 |
+
</div>
|
| 319 |
+
</div>
|
| 320 |
+
</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
|
| 324 |
+
<script>
|
| 325 |
+
class PythonDebugger {
|
| 326 |
+
constructor() {
|
| 327 |
+
this.currentStep = -1;
|
| 328 |
+
this.isPlaying = false;
|
| 329 |
+
this.playInterval = null;
|
| 330 |
+
this.totalSteps = 6;
|
| 331 |
+
this.variables = {};
|
| 332 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 333 |
+
|
| 334 |
+
this.initializeElements();
|
| 335 |
+
this.bindEvents();
|
| 336 |
+
this.updateUI();
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
initializeElements() {
|
| 340 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 341 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 342 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 343 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 344 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 345 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
bindEvents() {
|
| 349 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 350 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 351 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 352 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
togglePlay() {
|
| 356 |
+
if (this.isPlaying) {
|
| 357 |
+
this.pause();
|
| 358 |
+
} else {
|
| 359 |
+
this.play();
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
play() {
|
| 364 |
+
this.isPlaying = true;
|
| 365 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 366 |
+
|
| 367 |
+
if (this.currentStep >= this.totalSteps) {
|
| 368 |
+
this.currentStep = -1;
|
| 369 |
+
this.variables = {};
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
this.playInterval = setInterval(() => {
|
| 373 |
+
if (this.currentStep < this.totalSteps) {
|
| 374 |
+
this.nextStep();
|
| 375 |
+
} else {
|
| 376 |
+
this.pause();
|
| 377 |
+
}
|
| 378 |
+
}, 1500);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
pause() {
|
| 382 |
+
this.isPlaying = false;
|
| 383 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 384 |
+
if (this.playInterval) {
|
| 385 |
+
clearInterval(this.playInterval);
|
| 386 |
+
this.playInterval = null;
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
stop() {
|
| 391 |
+
this.pause();
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
nextStep() {
|
| 398 |
+
if (this.currentStep < this.totalSteps) {
|
| 399 |
+
this.currentStep++;
|
| 400 |
+
this.executeStep(this.currentStep);
|
| 401 |
+
this.updateUI();
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
previousStep() {
|
| 406 |
+
if (this.currentStep > 0) {
|
| 407 |
+
this.currentStep--;
|
| 408 |
+
this.recalculateVariables();
|
| 409 |
+
this.updateUI();
|
| 410 |
+
} else if (this.currentStep === 0) {
|
| 411 |
+
this.currentStep = -1;
|
| 412 |
+
this.variables = {};
|
| 413 |
+
this.updateUI();
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
executeStep(step) {
|
| 418 |
+
switch(step) {
|
| 419 |
+
case 1:
|
| 420 |
+
this.variables.hours_vacuuming = 2 * 2;
|
| 421 |
+
break;
|
| 422 |
+
case 2:
|
| 423 |
+
this.variables.vacuuming_money = this.variables.hours_vacuuming * 5;
|
| 424 |
+
break;
|
| 425 |
+
case 3:
|
| 426 |
+
this.variables.dishes_money = 0.5 * 5;
|
| 427 |
+
break;
|
| 428 |
+
case 4:
|
| 429 |
+
// This is the wrong step
|
| 430 |
+
this.variables.bathroom_time = 0.5 * 3;
|
| 431 |
+
break;
|
| 432 |
+
case 5:
|
| 433 |
+
this.variables.bathroom_money = this.variables.bathroom_time * 5;
|
| 434 |
+
break;
|
| 435 |
+
case 6:
|
| 436 |
+
this.variables.total_money = this.variables.vacuuming_money + this.variables.dishes_money + this.variables.bathroom_money;
|
| 437 |
+
break;
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
recalculateVariables() {
|
| 442 |
+
const oldVariables = {...this.variables};
|
| 443 |
+
this.variables = {};
|
| 444 |
+
for (let i = 1; i <= this.currentStep; i++) {
|
| 445 |
+
this.executeStep(i);
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
updateUI() {
|
| 450 |
+
// Update code highlighting
|
| 451 |
+
this.codeLines.forEach(line => {
|
| 452 |
+
line.classList.remove('current');
|
| 453 |
+
});
|
| 454 |
+
|
| 455 |
+
if (this.currentStep >= 0) {
|
| 456 |
+
const currentLines = document.querySelectorAll(`.code-line[data-step="${this.currentStep}"]`);
|
| 457 |
+
currentLines.forEach(line => {
|
| 458 |
+
line.classList.add('current');
|
| 459 |
+
});
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
// Update button states
|
| 463 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 464 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep === this.totalSteps);
|
| 465 |
+
|
| 466 |
+
// Update variables display
|
| 467 |
+
this.updateVariablesDisplay();
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
updateVariablesDisplay() {
|
| 471 |
+
if (Object.keys(this.variables).length === 0) {
|
| 472 |
+
this.variablesDisplay.innerHTML = `
|
| 473 |
+
<div class="variable-item">
|
| 474 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 475 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 476 |
+
</div>
|
| 477 |
+
`;
|
| 478 |
+
return;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
let html = '';
|
| 482 |
+
const variableOrder = ['hours_vacuuming', 'vacuuming_money', 'dishes_money', 'bathroom_time', 'bathroom_money', 'total_money'];
|
| 483 |
+
|
| 484 |
+
variableOrder.forEach(varName => {
|
| 485 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 486 |
+
const value = this.variables[varName];
|
| 487 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 488 |
+
const displayValue = varName.includes('money') ? `$${value}` : value;
|
| 489 |
+
|
| 490 |
+
let itemClass = "variable-item " + colorClass;
|
| 491 |
+
if (this.currentStep === this.wrongStep && varName === 'bathroom_time') {
|
| 492 |
+
itemClass += " error-highlight";
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 496 |
+
if(varName === lastVarName){
|
| 497 |
+
varName = varName + " (Final Answer)";
|
| 498 |
+
html += `<div class="variable-item ${colorClass}">
|
| 499 |
+
<span class="variable-name">${varName}</span>
|
| 500 |
+
<span class="variable-value">${value}</span>
|
| 501 |
+
</div>`;
|
| 502 |
+
} else {
|
| 503 |
+
html += `<div class="variable-item ${colorClass}">
|
| 504 |
+
<span class="variable-name">${varName}</span>
|
| 505 |
+
<span class="variable-value">${value}</span>
|
| 506 |
+
</div>`;
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
});
|
| 510 |
+
|
| 511 |
+
this.variablesDisplay.innerHTML = html;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
getVariableColorClass(varName) {
|
| 515 |
+
const colorMap = {
|
| 516 |
+
'hours_vacuuming': 'var1-color',
|
| 517 |
+
'vacuuming_money': 'var2-color',
|
| 518 |
+
'dishes_money': 'var3-color',
|
| 519 |
+
'bathroom_time': 'var4-color',
|
| 520 |
+
'bathroom_money': 'var5-color',
|
| 521 |
+
'total_money': 'var6-color'
|
| 522 |
+
};
|
| 523 |
+
return colorMap[varName] || '';
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// Initialize the debugger when the page loads
|
| 528 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 529 |
+
new PythonDebugger();
|
| 530 |
+
});
|
| 531 |
+
</script>
|
| 532 |
+
</body>
|
| 533 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_37.html
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
.wrong-step {
|
| 216 |
+
display: none;
|
| 217 |
+
}
|
| 218 |
+
</style>
|
| 219 |
+
</head>
|
| 220 |
+
<body>
|
| 221 |
+
<div class="wrong-step">0</div>
|
| 222 |
+
<div class="container">
|
| 223 |
+
<div class="left-panel">
|
| 224 |
+
<div class="problem-statement">
|
| 225 |
+
<div class="section-title">Problem Statement</div>
|
| 226 |
+
<p>
|
| 227 |
+
<span id="fact1" class="fact1-color">Florida is starting a promotion where every car that arrives gets one orange per passenger.</span> A family of <span id="fact2" class="fact2-color">4</span> arrives and gets their oranges. They had planned to stop for a snack later where they would spend <span id="fact3" class="fact3-color">$15</span> in total, but now that they have the oranges they don't have to buy them at the stop. When they get to the stop they see that the oranges would've cost <span id="fact4" class="fact4-color">$1.5</span> each. What percentage of the money they planned to spend did they save instead?
|
| 228 |
+
</p>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="problem-understanding">
|
| 231 |
+
<div class="section-title">Problem Summary</div>
|
| 232 |
+
<ul>
|
| 233 |
+
<li><span class="fact1-color">Oranges per passenger: 1</span></li>
|
| 234 |
+
<li><span class="fact2-color">Number of family members: 4</span></li>
|
| 235 |
+
<li><span class="fact3-color">Planned spending: $15</span></li>
|
| 236 |
+
<li><span class="fact4-color">Cost per orange: $1.5</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find:</h4>
|
| 240 |
+
<p>The percentage of the money they planned to spend that they saved instead.</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># Calculate the total cost of oranges</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">total_orange_cost</span> = <span class="fact2-color">4</span> * <span class="fact4-color">1.5</span></span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Calculate the proportion of their original spending plan</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">proportion_saved</span> = <span class="var1-color">total_orange_cost</span> / <span class="fact3-color">15</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Convert the proportion to a percentage</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">percentage_saved</span> = <span class="var2-color">proportion_saved</span> * 100</span>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="variables-display" id="variables-display">
|
| 281 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 282 |
+
<div id="variables-list">
|
| 283 |
+
<div class="variable-item">
|
| 284 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 285 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
|
| 292 |
+
<script>
|
| 293 |
+
class PythonDebugger {
|
| 294 |
+
constructor() {
|
| 295 |
+
this.currentStep = -1;
|
| 296 |
+
this.isPlaying = false;
|
| 297 |
+
this.playInterval = null;
|
| 298 |
+
this.totalSteps = 5;
|
| 299 |
+
this.variables = {};
|
| 300 |
+
|
| 301 |
+
this.initializeElements();
|
| 302 |
+
this.bindEvents();
|
| 303 |
+
this.updateUI();
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
initializeElements() {
|
| 307 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 308 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 309 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 310 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 311 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 312 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
bindEvents() {
|
| 316 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 317 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 318 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 319 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
togglePlay() {
|
| 323 |
+
if (this.isPlaying) {
|
| 324 |
+
this.pause();
|
| 325 |
+
} else {
|
| 326 |
+
this.play();
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
play() {
|
| 331 |
+
this.isPlaying = true;
|
| 332 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 333 |
+
|
| 334 |
+
if (this.currentStep >= this.totalSteps) {
|
| 335 |
+
this.currentStep = -1;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
this.playInterval = setInterval(() => {
|
| 339 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 340 |
+
if (nextStep !== null) {
|
| 341 |
+
this.currentStep = nextStep;
|
| 342 |
+
this.executeStep(this.currentStep);
|
| 343 |
+
this.updateUI();
|
| 344 |
+
} else {
|
| 345 |
+
this.pause();
|
| 346 |
+
}
|
| 347 |
+
}, 1500);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
pause() {
|
| 351 |
+
this.isPlaying = false;
|
| 352 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 353 |
+
if (this.playInterval) {
|
| 354 |
+
clearInterval(this.playInterval);
|
| 355 |
+
this.playInterval = null;
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
stop() {
|
| 360 |
+
this.pause();
|
| 361 |
+
this.currentStep = -1;
|
| 362 |
+
this.variables = {};
|
| 363 |
+
this.updateUI();
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
nextStep() {
|
| 367 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 368 |
+
if (nextStep !== null) {
|
| 369 |
+
this.currentStep = nextStep;
|
| 370 |
+
this.executeStep(this.currentStep);
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
previousStep() {
|
| 376 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 377 |
+
if (prevStep !== null) {
|
| 378 |
+
this.currentStep = prevStep;
|
| 379 |
+
this.recalculateVariables();
|
| 380 |
+
this.updateUI();
|
| 381 |
+
} else if (this.currentStep !== -1) {
|
| 382 |
+
this.currentStep = -1;
|
| 383 |
+
this.variables = {};
|
| 384 |
+
this.updateUI();
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
executeStep(step) {
|
| 389 |
+
switch(step) {
|
| 390 |
+
case 1:
|
| 391 |
+
this.variables.total_orange_cost = 4 * 1.5;
|
| 392 |
+
break;
|
| 393 |
+
case 3:
|
| 394 |
+
// This is the wrong step as indicated in the wrongstep tag
|
| 395 |
+
this.variables.proportion_saved = this.variables.total_orange_cost / 15;
|
| 396 |
+
break;
|
| 397 |
+
case 5:
|
| 398 |
+
this.variables.percentage_saved = this.variables.proportion_saved * 100;
|
| 399 |
+
break;
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
getExecutableSteps() {
|
| 404 |
+
// Returns only the steps that execute actual code (not comments)
|
| 405 |
+
return [1, 3, 5];
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
getNextExecutableStep(currentStep) {
|
| 409 |
+
const executableSteps = this.getExecutableSteps();
|
| 410 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 411 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
getPreviousExecutableStep(currentStep) {
|
| 415 |
+
const executableSteps = this.getExecutableSteps();
|
| 416 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 417 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
recalculateVariables() {
|
| 421 |
+
this.variables = {};
|
| 422 |
+
const executableSteps = this.getExecutableSteps();
|
| 423 |
+
for (let step of executableSteps) {
|
| 424 |
+
if (step <= this.currentStep) {
|
| 425 |
+
this.executeStep(step);
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
updateUI() {
|
| 431 |
+
// Update code highlighting
|
| 432 |
+
this.codeLines.forEach((line, index) => {
|
| 433 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 434 |
+
});
|
| 435 |
+
|
| 436 |
+
// Update button states
|
| 437 |
+
const executableSteps = this.getExecutableSteps();
|
| 438 |
+
const isFirstStep = this.currentStep === -1;
|
| 439 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 440 |
+
|
| 441 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 442 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 443 |
+
|
| 444 |
+
// Update variables display
|
| 445 |
+
this.updateVariablesDisplay();
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
updateVariablesDisplay() {
|
| 449 |
+
if (Object.keys(this.variables).length === 0) {
|
| 450 |
+
this.variablesDisplay.innerHTML = `
|
| 451 |
+
<div class="variable-item">
|
| 452 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 453 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 454 |
+
</div>
|
| 455 |
+
`;
|
| 456 |
+
return;
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
let html = '';
|
| 460 |
+
const variableOrder = ['total_orange_cost', 'proportion_saved', 'percentage_saved'];
|
| 461 |
+
|
| 462 |
+
variableOrder.forEach(varName => {
|
| 463 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 464 |
+
const value = this.variables[varName];
|
| 465 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 466 |
+
const displayValue = varName.includes('percentage') ? `${value}%` : value;
|
| 467 |
+
|
| 468 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 469 |
+
if(varName === lastVarName){
|
| 470 |
+
varName = varName + " (Final Answer)";
|
| 471 |
+
html += `<div class="variable-item ${colorClass}">
|
| 472 |
+
<span class="variable-name">${varName}</span>
|
| 473 |
+
<span class="variable-value">${value}</span>
|
| 474 |
+
</div>`;
|
| 475 |
+
} else {
|
| 476 |
+
html += `<div class="variable-item ${colorClass}">
|
| 477 |
+
<span class="variable-name">${varName}</span>
|
| 478 |
+
<span class="variable-value">${value}</span>
|
| 479 |
+
</div>`;
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
});
|
| 483 |
+
|
| 484 |
+
this.variablesDisplay.innerHTML = html;
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
getVariableColorClass(varName) {
|
| 488 |
+
const colorMap = {
|
| 489 |
+
'total_orange_cost': 'var1-color',
|
| 490 |
+
'proportion_saved': 'var2-color',
|
| 491 |
+
'percentage_saved': 'var3-color'
|
| 492 |
+
};
|
| 493 |
+
return colorMap[varName] || '';
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
// Initialize the debugger when the page loads
|
| 498 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 499 |
+
new PythonDebugger();
|
| 500 |
+
});
|
| 501 |
+
</script>
|
| 502 |
+
</body>
|
| 503 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_38.html
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 195 |
+
|
| 196 |
+
ul {
|
| 197 |
+
padding-left: 20px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
li {
|
| 201 |
+
margin-bottom: 12px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.what-to-find {
|
| 205 |
+
margin-top: 20px;
|
| 206 |
+
padding: 15px;
|
| 207 |
+
background-color: #e8f4fd;
|
| 208 |
+
border-radius: 6px;
|
| 209 |
+
border-left: 4px solid #3498db;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.what-to-find h4 {
|
| 213 |
+
color: #2c3e50;
|
| 214 |
+
margin-bottom: 8px;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.wrong-step {
|
| 218 |
+
display: none;
|
| 219 |
+
}
|
| 220 |
+
</style>
|
| 221 |
+
</head>
|
| 222 |
+
<body>
|
| 223 |
+
<div class="wrong-step">0</div>
|
| 224 |
+
<div class="container">
|
| 225 |
+
<div class="left-panel">
|
| 226 |
+
<div class="problem-statement">
|
| 227 |
+
<div class="section-title">Problem Statement</div>
|
| 228 |
+
<p>
|
| 229 |
+
A cheetah can run at a top speed of <span id="fact1" class="fact1-color">60 mph</span>. The gazelle can run for speeds of up to <span id="fact2" class="fact2-color">40 miles per hour</span>. If <span id="fact3" class="fact3-color">one mile per hour is about 1.5 feet per second</span>, then how many seconds would it take for a cheetah traveling at top speed to catch up to a fleeing gazelle also running at top speed if the two animals were initially <span id="fact4" class="fact4-color">210 feet apart</span> and they both traveled in the same direction?
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="problem-understanding">
|
| 233 |
+
<div class="section-title">Problem Summary</div>
|
| 234 |
+
<ul>
|
| 235 |
+
<li><span class="fact1-color">Cheetah speed: 60 mph</span></li>
|
| 236 |
+
<li><span class="fact2-color">Gazelle speed: 40 mph</span></li>
|
| 237 |
+
<li><span class="fact3-color">Conversion rate: 1.5 feet per second per mph</span></li>
|
| 238 |
+
<li><span class="fact4-color">Initial distance: 210 feet</span></li>
|
| 239 |
+
</ul>
|
| 240 |
+
<div class="what-to-find">
|
| 241 |
+
<h4>What we need to find:</h4>
|
| 242 |
+
<p>How many seconds it would take for the cheetah to catch up to the gazelle.</p>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
<div class="right-panel">
|
| 247 |
+
<div class="debugger-controls">
|
| 248 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 249 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 250 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 251 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="python-solution">
|
| 254 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 255 |
+
<div class="python-code" id="python-code">
|
| 256 |
+
<div class="code-line" data-step="0">
|
| 257 |
+
<span class="line-number">1</span>
|
| 258 |
+
<span class="comment"># Convert cheetah speed from mph to feet per second</span>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="code-line" data-step="1">
|
| 261 |
+
<span class="line-number">2</span>
|
| 262 |
+
<span><span class="var1-color">cheetah_speed_fps</span> = <span class="fact1-color">60</span> * <span class="fact3-color">1.5</span></span>
|
| 263 |
+
</div>
|
| 264 |
+
<div class="code-line" data-step="2">
|
| 265 |
+
<span class="line-number">3</span>
|
| 266 |
+
<span class="comment"># Convert gazelle speed from mph to feet per second</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="code-line" data-step="3">
|
| 269 |
+
<span class="line-number">4</span>
|
| 270 |
+
<span><span class="var2-color">gazelle_speed_fps</span> = <span class="fact2-color">40</span> * <span class="fact3-color">1.5</span></span>
|
| 271 |
+
</div>
|
| 272 |
+
<div class="code-line" data-step="4">
|
| 273 |
+
<span class="line-number">5</span>
|
| 274 |
+
<span class="comment"># Calculate the relative speed between cheetah and gazelle</span>
|
| 275 |
+
</div>
|
| 276 |
+
<div class="code-line" data-step="5">
|
| 277 |
+
<span class="line-number">6</span>
|
| 278 |
+
<span><span class="var3-color">relative_speed</span> = <span class="var1-color">cheetah_speed_fps</span> - <span class="var2-color">gazelle_speed_fps</span></span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="code-line" data-step="6">
|
| 281 |
+
<span class="line-number">7</span>
|
| 282 |
+
<span class="comment"># Calculate time needed for cheetah to catch gazelle</span>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="code-line" data-step="7">
|
| 285 |
+
<span class="line-number">8</span>
|
| 286 |
+
<span><span class="var4-color">time_to_catch</span> = <span class="fact4-color">210</span> / <span class="var3-color">relative_speed</span></span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="variables-display" id="variables-display">
|
| 291 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 292 |
+
<div id="variables-list">
|
| 293 |
+
<div class="variable-item">
|
| 294 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 295 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
|
| 302 |
+
<script>
|
| 303 |
+
class PythonDebugger {
|
| 304 |
+
constructor() {
|
| 305 |
+
this.currentStep = -1;
|
| 306 |
+
this.isPlaying = false;
|
| 307 |
+
this.playInterval = null;
|
| 308 |
+
this.totalSteps = 7;
|
| 309 |
+
this.variables = {};
|
| 310 |
+
|
| 311 |
+
this.initializeElements();
|
| 312 |
+
this.bindEvents();
|
| 313 |
+
this.updateUI();
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
initializeElements() {
|
| 317 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 318 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 319 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 320 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 321 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 322 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
bindEvents() {
|
| 326 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 327 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 328 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 329 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
togglePlay() {
|
| 333 |
+
if (this.isPlaying) {
|
| 334 |
+
this.pause();
|
| 335 |
+
} else {
|
| 336 |
+
this.play();
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
play() {
|
| 341 |
+
this.isPlaying = true;
|
| 342 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 343 |
+
|
| 344 |
+
if (this.currentStep >= this.totalSteps) {
|
| 345 |
+
this.currentStep = -1;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
this.playInterval = setInterval(() => {
|
| 349 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 350 |
+
if (nextStep !== null) {
|
| 351 |
+
this.currentStep = nextStep;
|
| 352 |
+
this.executeStep(this.currentStep);
|
| 353 |
+
this.updateUI();
|
| 354 |
+
} else {
|
| 355 |
+
this.pause();
|
| 356 |
+
}
|
| 357 |
+
}, 1500);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
pause() {
|
| 361 |
+
this.isPlaying = false;
|
| 362 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 363 |
+
if (this.playInterval) {
|
| 364 |
+
clearInterval(this.playInterval);
|
| 365 |
+
this.playInterval = null;
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
stop() {
|
| 370 |
+
this.pause();
|
| 371 |
+
this.currentStep = -1;
|
| 372 |
+
this.variables = {};
|
| 373 |
+
this.updateUI();
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
nextStep() {
|
| 377 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 378 |
+
if (nextStep !== null) {
|
| 379 |
+
this.currentStep = nextStep;
|
| 380 |
+
this.executeStep(this.currentStep);
|
| 381 |
+
this.updateUI();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
previousStep() {
|
| 386 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 387 |
+
if (prevStep !== null) {
|
| 388 |
+
this.currentStep = prevStep;
|
| 389 |
+
this.recalculateVariables();
|
| 390 |
+
this.updateUI();
|
| 391 |
+
} else if (this.currentStep !== -1) {
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
executeStep(step) {
|
| 399 |
+
switch(step) {
|
| 400 |
+
case 1:
|
| 401 |
+
this.variables.cheetah_speed_fps = 60 * 1.5;
|
| 402 |
+
break;
|
| 403 |
+
case 3:
|
| 404 |
+
this.variables.gazelle_speed_fps = 40 * 1.5;
|
| 405 |
+
break;
|
| 406 |
+
case 5:
|
| 407 |
+
this.variables.relative_speed = this.variables.cheetah_speed_fps - this.variables.gazelle_speed_fps;
|
| 408 |
+
break;
|
| 409 |
+
case 7:
|
| 410 |
+
// Intentionally keeping the error as per the wrong step
|
| 411 |
+
this.variables.time_to_catch = 210 / this.variables.relative_speed;
|
| 412 |
+
break;
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
getExecutableSteps() {
|
| 417 |
+
// Returns only the steps that execute actual code (not comments)
|
| 418 |
+
return [1, 3, 5, 7];
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
getNextExecutableStep(currentStep) {
|
| 422 |
+
const executableSteps = this.getExecutableSteps();
|
| 423 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 424 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
getPreviousExecutableStep(currentStep) {
|
| 428 |
+
const executableSteps = this.getExecutableSteps();
|
| 429 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 430 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
recalculateVariables() {
|
| 434 |
+
this.variables = {};
|
| 435 |
+
const executableSteps = this.getExecutableSteps();
|
| 436 |
+
for (let step of executableSteps) {
|
| 437 |
+
if (step <= this.currentStep) {
|
| 438 |
+
this.executeStep(step);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
updateUI() {
|
| 444 |
+
// Update code highlighting
|
| 445 |
+
this.codeLines.forEach((line, index) => {
|
| 446 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 447 |
+
});
|
| 448 |
+
|
| 449 |
+
// Update button states
|
| 450 |
+
const executableSteps = this.getExecutableSteps();
|
| 451 |
+
const isFirstStep = this.currentStep === -1;
|
| 452 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 453 |
+
|
| 454 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 455 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 456 |
+
|
| 457 |
+
// Update variables display
|
| 458 |
+
this.updateVariablesDisplay();
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
updateVariablesDisplay() {
|
| 462 |
+
if (Object.keys(this.variables).length === 0) {
|
| 463 |
+
this.variablesDisplay.innerHTML = `
|
| 464 |
+
<div class="variable-item">
|
| 465 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 466 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 467 |
+
</div>
|
| 468 |
+
`;
|
| 469 |
+
return;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
let html = '';
|
| 473 |
+
const variableOrder = ['cheetah_speed_fps', 'gazelle_speed_fps', 'relative_speed', 'time_to_catch'];
|
| 474 |
+
|
| 475 |
+
variableOrder.forEach(varName => {
|
| 476 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 477 |
+
const value = this.variables[varName];
|
| 478 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 479 |
+
|
| 480 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 481 |
+
if(varName === lastVarName){
|
| 482 |
+
varName = varName + " (Final Answer)";
|
| 483 |
+
html += `<div class="variable-item ${colorClass}">
|
| 484 |
+
<span class="variable-name">${varName}</span>
|
| 485 |
+
<span class="variable-value">${value}</span>
|
| 486 |
+
</div>`;
|
| 487 |
+
} else {
|
| 488 |
+
html += `<div class="variable-item ${colorClass}">
|
| 489 |
+
<span class="variable-name">${varName}</span>
|
| 490 |
+
<span class="variable-value">${value}</span>
|
| 491 |
+
</div>`;
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
});
|
| 495 |
+
|
| 496 |
+
this.variablesDisplay.innerHTML = html;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
getVariableColorClass(varName) {
|
| 500 |
+
const colorMap = {
|
| 501 |
+
'cheetah_speed_fps': 'var1-color',
|
| 502 |
+
'gazelle_speed_fps': 'var2-color',
|
| 503 |
+
'relative_speed': 'var3-color',
|
| 504 |
+
'time_to_catch': 'var4-color'
|
| 505 |
+
};
|
| 506 |
+
return colorMap[varName] || '';
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
// Initialize the debugger when the page loads
|
| 511 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 512 |
+
new PythonDebugger();
|
| 513 |
+
});
|
| 514 |
+
</script>
|
| 515 |
+
</body>
|
| 516 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_39.html
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
.var4-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
.wrong-step {
|
| 216 |
+
display: none;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
At football tryouts, the coach wanted to see who could throw the ball the farthest. <span id="fact1" class="fact1-color">Parker threw the ball 16 yards</span>. <span id="fact2" class="fact2-color">Grant threw the ball 25 percent farther than Parker</span> and <span id="fact3" class="fact3-color">Kyle threw the ball 2 times farther than Grant</span>. Compared to Parker, how much farther did Kyle throw the ball?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Parker's throw: 16 yards</span></li>
|
| 235 |
+
<li><span class="fact2-color">Grant's throw: 25% farther than Parker</span></li>
|
| 236 |
+
<li><span class="fact3-color">Kyle's throw: 2 times farther than Grant</span></li>
|
| 237 |
+
</ul>
|
| 238 |
+
<div class="what-to-find">
|
| 239 |
+
<h4>What we need to find:</h4>
|
| 240 |
+
<p>Compared to Parker, how much farther did Kyle throw the ball?</p>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
<div class="right-panel">
|
| 245 |
+
<div class="debugger-controls">
|
| 246 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 247 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 248 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 249 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="python-solution">
|
| 252 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 253 |
+
<div class="python-code" id="python-code">
|
| 254 |
+
<div class="code-line" data-step="0">
|
| 255 |
+
<span class="line-number">1</span>
|
| 256 |
+
<span class="comment"># Calculate how much farther Grant threw compared to Parker</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="1">
|
| 259 |
+
<span class="line-number">2</span>
|
| 260 |
+
<span><span class="var1-color">grant_extra</span> = <span class="fact1-color">16</span> * 0.25</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="2">
|
| 263 |
+
<span class="line-number">3</span>
|
| 264 |
+
<span class="comment"># Calculate Grant's total throw distance</span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="3">
|
| 267 |
+
<span class="line-number">4</span>
|
| 268 |
+
<span><span class="var2-color">grant_throw</span> = <span class="fact1-color">16</span> + <span class="var1-color">grant_extra</span></span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="4">
|
| 271 |
+
<span class="line-number">5</span>
|
| 272 |
+
<span class="comment"># Calculate Kyle's throw distance</span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="5">
|
| 275 |
+
<span class="line-number">6</span>
|
| 276 |
+
<span><span class="var3-color">kyle_throw</span> = <span class="var2-color">grant_throw</span> * 2</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="6">
|
| 279 |
+
<span class="line-number">7</span>
|
| 280 |
+
<span class="comment"># Calculate how much farther Kyle threw compared to Parker</span>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="code-line" data-step="7">
|
| 283 |
+
<span class="line-number">8</span>
|
| 284 |
+
<span><span class="var4-color">kyle_extra</span> = <span class="var3-color">kyle_throw</span> - <span class="fact1-color">16</span></span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div class="variables-display" id="variables-display">
|
| 289 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 290 |
+
<div id="variables-list">
|
| 291 |
+
<div class="variable-item">
|
| 292 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 293 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
class PythonDebugger {
|
| 302 |
+
constructor() {
|
| 303 |
+
this.currentStep = -1;
|
| 304 |
+
this.isPlaying = false;
|
| 305 |
+
this.playInterval = null;
|
| 306 |
+
this.totalSteps = 7;
|
| 307 |
+
this.variables = {};
|
| 308 |
+
|
| 309 |
+
this.initializeElements();
|
| 310 |
+
this.bindEvents();
|
| 311 |
+
this.updateUI();
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
initializeElements() {
|
| 315 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 316 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 317 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 318 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 319 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 320 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
bindEvents() {
|
| 324 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 325 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 326 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 327 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
togglePlay() {
|
| 331 |
+
if (this.isPlaying) {
|
| 332 |
+
this.pause();
|
| 333 |
+
} else {
|
| 334 |
+
this.play();
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
play() {
|
| 339 |
+
this.isPlaying = true;
|
| 340 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 341 |
+
|
| 342 |
+
if (this.currentStep >= 7) {
|
| 343 |
+
this.currentStep = -1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
this.playInterval = setInterval(() => {
|
| 347 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 348 |
+
if (nextStep !== null) {
|
| 349 |
+
this.currentStep = nextStep;
|
| 350 |
+
this.executeStep(this.currentStep);
|
| 351 |
+
this.updateUI();
|
| 352 |
+
} else {
|
| 353 |
+
this.pause();
|
| 354 |
+
}
|
| 355 |
+
}, 1500);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
pause() {
|
| 359 |
+
this.isPlaying = false;
|
| 360 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 361 |
+
if (this.playInterval) {
|
| 362 |
+
clearInterval(this.playInterval);
|
| 363 |
+
this.playInterval = null;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
stop() {
|
| 368 |
+
this.pause();
|
| 369 |
+
this.currentStep = -1;
|
| 370 |
+
this.variables = {};
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
nextStep() {
|
| 375 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 376 |
+
if (nextStep !== null) {
|
| 377 |
+
this.currentStep = nextStep;
|
| 378 |
+
this.executeStep(this.currentStep);
|
| 379 |
+
this.updateUI();
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
previousStep() {
|
| 384 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 385 |
+
if (prevStep !== null) {
|
| 386 |
+
this.currentStep = prevStep;
|
| 387 |
+
this.recalculateVariables();
|
| 388 |
+
this.updateUI();
|
| 389 |
+
} else if (this.currentStep !== -1) {
|
| 390 |
+
this.currentStep = -1;
|
| 391 |
+
this.variables = {};
|
| 392 |
+
this.updateUI();
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
executeStep(step) {
|
| 397 |
+
switch(step) {
|
| 398 |
+
case 1:
|
| 399 |
+
this.variables.grant_extra = 16 * 0.25;
|
| 400 |
+
break;
|
| 401 |
+
case 3:
|
| 402 |
+
this.variables.grant_throw = 16 + this.variables.grant_extra;
|
| 403 |
+
break;
|
| 404 |
+
case 5:
|
| 405 |
+
this.variables.kyle_throw = this.variables.grant_throw * 2;
|
| 406 |
+
break;
|
| 407 |
+
case 7:
|
| 408 |
+
this.variables.kyle_extra = this.variables.kyle_throw - 16;
|
| 409 |
+
break;
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
getExecutableSteps() {
|
| 414 |
+
// Returns only the steps that execute actual code (not comments)
|
| 415 |
+
return [1, 3, 5, 7];
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
getNextExecutableStep(currentStep) {
|
| 419 |
+
const executableSteps = this.getExecutableSteps();
|
| 420 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 421 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
getPreviousExecutableStep(currentStep) {
|
| 425 |
+
const executableSteps = this.getExecutableSteps();
|
| 426 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 427 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
recalculateVariables() {
|
| 431 |
+
this.variables = {};
|
| 432 |
+
const executableSteps = this.getExecutableSteps();
|
| 433 |
+
for (let step of executableSteps) {
|
| 434 |
+
if (step <= this.currentStep) {
|
| 435 |
+
this.executeStep(step);
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
updateUI() {
|
| 441 |
+
// Update code highlighting
|
| 442 |
+
this.codeLines.forEach((line, index) => {
|
| 443 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 444 |
+
});
|
| 445 |
+
|
| 446 |
+
// Update button states
|
| 447 |
+
const executableSteps = this.getExecutableSteps();
|
| 448 |
+
const isFirstStep = this.currentStep === -1;
|
| 449 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 450 |
+
|
| 451 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 452 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 453 |
+
|
| 454 |
+
// Update variables display
|
| 455 |
+
this.updateVariablesDisplay();
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
updateVariablesDisplay() {
|
| 459 |
+
if (Object.keys(this.variables).length === 0) {
|
| 460 |
+
this.variablesDisplay.innerHTML = `
|
| 461 |
+
<div class="variable-item">
|
| 462 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 463 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 464 |
+
</div>
|
| 465 |
+
`;
|
| 466 |
+
return;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
let html = '';
|
| 470 |
+
const variableOrder = ['grant_extra', 'grant_throw', 'kyle_throw', 'kyle_extra'];
|
| 471 |
+
|
| 472 |
+
variableOrder.forEach(varName => {
|
| 473 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 474 |
+
const value = this.variables[varName];
|
| 475 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 476 |
+
|
| 477 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 478 |
+
if(varName === lastVarName){
|
| 479 |
+
varName = varName + " (Final Answer)";
|
| 480 |
+
html += `<div class="variable-item ${colorClass}">
|
| 481 |
+
<span class="variable-name">${varName}</span>
|
| 482 |
+
<span class="variable-value">${value}</span>
|
| 483 |
+
</div>`;
|
| 484 |
+
} else {
|
| 485 |
+
html += `<div class="variable-item ${colorClass}">
|
| 486 |
+
<span class="variable-name">${varName}</span>
|
| 487 |
+
<span class="variable-value">${value}</span>
|
| 488 |
+
</div>`;
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
|
| 493 |
+
this.variablesDisplay.innerHTML = html;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
getVariableColorClass(varName) {
|
| 497 |
+
const colorMap = {
|
| 498 |
+
'grant_extra': 'var1-color',
|
| 499 |
+
'grant_throw': 'var2-color',
|
| 500 |
+
'kyle_throw': 'var3-color',
|
| 501 |
+
'kyle_extra': 'var4-color'
|
| 502 |
+
};
|
| 503 |
+
return colorMap[varName] || '';
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// Initialize the debugger when the page loads
|
| 508 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 509 |
+
new Python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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 191 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 192 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 193 |
+
|
| 194 |
+
ul {
|
| 195 |
+
padding-left: 20px;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
li {
|
| 199 |
+
margin-bottom: 12px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.what-to-find {
|
| 203 |
+
margin-top: 20px;
|
| 204 |
+
padding: 15px;
|
| 205 |
+
background-color: #e8f4fd;
|
| 206 |
+
border-radius: 6px;
|
| 207 |
+
border-left: 4px solid #3498db;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.what-to-find h4 {
|
| 211 |
+
color: #2c3e50;
|
| 212 |
+
margin-bottom: 8px;
|
| 213 |
+
}
|
| 214 |
+
.wrong-step {
|
| 215 |
+
display: none;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
</style>
|
| 219 |
+
</head>
|
| 220 |
+
<body>
|
| 221 |
+
<div class="wrong-step">0</div>
|
| 222 |
+
<div class="container">
|
| 223 |
+
<div class="left-panel">
|
| 224 |
+
<div class="problem-statement">
|
| 225 |
+
<div class="section-title">Problem Statement</div>
|
| 226 |
+
<p>
|
| 227 |
+
<span id="fact1" class="fact1-color">Harry decided to buy some balloons for his friend's birthday party. One balloon costs $0.5</span>, and <span id="fact2" class="fact2-color">a pack of 10 balloons is cheaper and costs only $3</span>. Finally, <span id="fact3" class="fact3-color">Harry wants to bring to the party exactly 14 balloons</span>. How much did he need to pay for them?
|
| 228 |
+
</p>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="problem-understanding">
|
| 231 |
+
<div class="section-title">Problem Summary</div>
|
| 232 |
+
<ul>
|
| 233 |
+
<li><span class="fact1-color">Cost of one balloon: $0.5</span></li>
|
| 234 |
+
<li><span class="fact2-color">Cost of a pack of 10 balloons: $3</span></li>
|
| 235 |
+
<li><span class="fact3-color">Number of balloons needed: 14</span></li>
|
| 236 |
+
</ul>
|
| 237 |
+
<div class="what-to-find">
|
| 238 |
+
<h4>What we need to find</h4>
|
| 239 |
+
<p>How much Harry needed to pay for the balloons.</p>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
<div class="right-panel">
|
| 244 |
+
<div class="debugger-controls">
|
| 245 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 246 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 247 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 248 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="python-solution">
|
| 251 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 252 |
+
<div class="python-code" id="python-code">
|
| 253 |
+
<div class="code-line" data-step="0">
|
| 254 |
+
<span class="line-number">1</span>
|
| 255 |
+
<span class="comment"># Calculate how many separate balloons Harry needs to buy</span>
|
| 256 |
+
</div>
|
| 257 |
+
<div class="code-line" data-step="1">
|
| 258 |
+
<span class="line-number">2</span>
|
| 259 |
+
<span><span class="var1-color">separate_balloons</span> = <span class="fact3-color">14</span> - 10</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="2">
|
| 262 |
+
<span class="line-number">3</span>
|
| 263 |
+
<span class="comment"># Calculate the cost of separate balloons</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="3">
|
| 266 |
+
<span class="line-number">4</span>
|
| 267 |
+
<span><span class="var2-color">cost_of_separate_balloons</span> = <span class="var1-color">separate_balloons</span> * <span class="fact1-color">0.5</span></span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="4">
|
| 270 |
+
<span class="line-number">5</span>
|
| 271 |
+
<span class="comment"># Calculate the total cost</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="5">
|
| 274 |
+
<span class="line-number">6</span>
|
| 275 |
+
<span><span class="var3-color">total_cost</span> = <span class="fact2-color">3</span> + <span class="var2-color">cost_of_separate_balloons</span></span>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="variables-display" id="variables-display">
|
| 280 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 281 |
+
<div id="variables-list">
|
| 282 |
+
<div class="variable-item">
|
| 283 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 284 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
|
| 291 |
+
<script>
|
| 292 |
+
class PythonDebugger {
|
| 293 |
+
constructor() {
|
| 294 |
+
this.currentStep = -1;
|
| 295 |
+
this.isPlaying = false;
|
| 296 |
+
this.playInterval = null;
|
| 297 |
+
this.totalSteps = 5;
|
| 298 |
+
this.variables = {};
|
| 299 |
+
this.wrongStep = parseInt(document.querySelector('.wrong-step').textContent);
|
| 300 |
+
|
| 301 |
+
this.initializeElements();
|
| 302 |
+
this.bindEvents();
|
| 303 |
+
this.updateUI();
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
initializeElements() {
|
| 307 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 308 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 309 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 310 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 311 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 312 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
bindEvents() {
|
| 316 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 317 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 318 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 319 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
togglePlay() {
|
| 323 |
+
if (this.isPlaying) {
|
| 324 |
+
this.pause();
|
| 325 |
+
} else {
|
| 326 |
+
this.play();
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
play() {
|
| 331 |
+
this.isPlaying = true;
|
| 332 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 333 |
+
|
| 334 |
+
if (this.currentStep >= this.totalSteps) {
|
| 335 |
+
this.currentStep = -1;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
this.playInterval = setInterval(() => {
|
| 339 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 340 |
+
if (nextStep !== null) {
|
| 341 |
+
this.currentStep = nextStep;
|
| 342 |
+
this.executeStep(this.currentStep);
|
| 343 |
+
this.updateUI();
|
| 344 |
+
} else {
|
| 345 |
+
this.pause();
|
| 346 |
+
}
|
| 347 |
+
}, 1500);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
pause() {
|
| 351 |
+
this.isPlaying = false;
|
| 352 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 353 |
+
if (this.playInterval) {
|
| 354 |
+
clearInterval(this.playInterval);
|
| 355 |
+
this.playInterval = null;
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
stop() {
|
| 360 |
+
this.pause();
|
| 361 |
+
this.currentStep = -1;
|
| 362 |
+
this.variables = {};
|
| 363 |
+
this.updateUI();
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
nextStep() {
|
| 367 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 368 |
+
if (nextStep !== null) {
|
| 369 |
+
this.currentStep = nextStep;
|
| 370 |
+
this.executeStep(this.currentStep);
|
| 371 |
+
this.updateUI();
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
previousStep() {
|
| 376 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 377 |
+
if (prevStep !== null) {
|
| 378 |
+
this.currentStep = prevStep;
|
| 379 |
+
this.recalculateVariables();
|
| 380 |
+
this.updateUI();
|
| 381 |
+
} else if (this.currentStep !== -1) {
|
| 382 |
+
this.currentStep = -1;
|
| 383 |
+
this.variables = {};
|
| 384 |
+
this.updateUI();
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
executeStep(step) {
|
| 389 |
+
switch(step) {
|
| 390 |
+
case 1:
|
| 391 |
+
this.variables.separate_balloons = 14 - 10;
|
| 392 |
+
break;
|
| 393 |
+
case 3:
|
| 394 |
+
// This is the wrong step (step 2 in the unformatted information)
|
| 395 |
+
if (this.wrongStep === 2) {
|
| 396 |
+
this.variables.cost_of_separate_balloons = 4 * 0.5;
|
| 397 |
+
} else {
|
| 398 |
+
this.variables.cost_of_separate_balloons = this.variables.separate_balloons * 0.5;
|
| 399 |
+
}
|
| 400 |
+
break;
|
| 401 |
+
case 5:
|
| 402 |
+
this.variables.total_cost = 3 + this.variables.cost_of_separate_balloons;
|
| 403 |
+
break;
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
getExecutableSteps() {
|
| 408 |
+
// Returns only the steps that execute actual code (not comments)
|
| 409 |
+
return [1, 3, 5];
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
getNextExecutableStep(currentStep) {
|
| 413 |
+
const executableSteps = this.getExecutableSteps();
|
| 414 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 415 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
getPreviousExecutableStep(currentStep) {
|
| 419 |
+
const executableSteps = this.getExecutableSteps();
|
| 420 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 421 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
recalculateVariables() {
|
| 425 |
+
this.variables = {};
|
| 426 |
+
const executableSteps = this.getExecutableSteps();
|
| 427 |
+
for (let step of executableSteps) {
|
| 428 |
+
if (step <= this.currentStep) {
|
| 429 |
+
this.executeStep(step);
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
updateUI() {
|
| 435 |
+
// Update code highlighting
|
| 436 |
+
this.codeLines.forEach((line, index) => {
|
| 437 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 438 |
+
});
|
| 439 |
+
|
| 440 |
+
// Update button states
|
| 441 |
+
const executableSteps = this.getExecutableSteps();
|
| 442 |
+
const isFirstStep = this.currentStep === -1;
|
| 443 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 444 |
+
|
| 445 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 446 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 447 |
+
|
| 448 |
+
// Update variables display
|
| 449 |
+
this.updateVariablesDisplay();
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
updateVariablesDisplay() {
|
| 453 |
+
if (Object.keys(this.variables).length === 0) {
|
| 454 |
+
this.variablesDisplay.innerHTML = `
|
| 455 |
+
<div class="variable-item">
|
| 456 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 457 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 458 |
+
</div>
|
| 459 |
+
`;
|
| 460 |
+
return;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
let html = '';
|
| 464 |
+
const variableOrder = ['separate_balloons', 'cost_of_separate_balloons', 'total_cost'];
|
| 465 |
+
|
| 466 |
+
variableOrder.forEach(varName => {
|
| 467 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 468 |
+
const value = this.variables[varName];
|
| 469 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 470 |
+
const displayValue = varName.includes('cost') ? `$${value}` : value;
|
| 471 |
+
|
| 472 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 473 |
+
if(varName === lastVarName){
|
| 474 |
+
varName = varName + " (Final Answer)";
|
| 475 |
+
html += `<div class="variable-item ${colorClass}">
|
| 476 |
+
<span class="variable-name">${varName}</span>
|
| 477 |
+
<span class="variable-value">${value}</span>
|
| 478 |
+
</div>`;
|
| 479 |
+
} else {
|
| 480 |
+
html += `<div class="variable-item ${colorClass}">
|
| 481 |
+
<span class="variable-name">${varName}</span>
|
| 482 |
+
<span class="variable-value">${value}</span>
|
| 483 |
+
</div>`;
|
| 484 |
+
}
|
| 485 |
+
}
|
| 486 |
+
});
|
| 487 |
+
|
| 488 |
+
this.variablesDisplay.innerHTML = html;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
getVariableColorClass(varName) {
|
| 492 |
+
const colorMap = {
|
| 493 |
+
'separate_balloons': 'var1-color',
|
| 494 |
+
'cost_of_separate_balloons': 'var2-color',
|
| 495 |
+
'total_cost': 'var3-color'
|
| 496 |
+
};
|
| 497 |
+
return colorMap[varName] || '';
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
// Initialize the debugger when the page loads
|
| 502 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 503 |
+
new PythonDebugger();
|
| 504 |
+
});
|
| 505 |
+
</script>
|
| 506 |
+
</body>
|
| 507 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_40.html
ADDED
|
@@ -0,0 +1,504 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 192 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 193 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 194 |
+
|
| 195 |
+
ul {
|
| 196 |
+
padding-left: 20px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
li {
|
| 200 |
+
margin-bottom: 12px;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.what-to-find {
|
| 204 |
+
margin-top: 20px;
|
| 205 |
+
padding: 15px;
|
| 206 |
+
background-color: #e8f4fd;
|
| 207 |
+
border-radius: 6px;
|
| 208 |
+
border-left: 4px solid #3498db;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.what-to-find h4 {
|
| 212 |
+
color: #2c3e50;
|
| 213 |
+
margin-bottom: 8px;
|
| 214 |
+
}
|
| 215 |
+
.wrong-step {
|
| 216 |
+
display: none;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
</style>
|
| 220 |
+
</head>
|
| 221 |
+
<body>
|
| 222 |
+
<div class="wrong-step">0</div>
|
| 223 |
+
<div class="container">
|
| 224 |
+
<div class="left-panel">
|
| 225 |
+
<div class="problem-statement">
|
| 226 |
+
<div class="section-title">Problem Statement</div>
|
| 227 |
+
<p>
|
| 228 |
+
<span id="fact1" class="fact1-color">John raises emu. He has 4 pens for emu</span> and <span id="fact2" class="fact2-color">each pen has 6 emus in it</span>. <span id="fact3" class="fact3-color">Each female emu lays 1 egg per day</span>. <span id="fact4" class="fact4-color">If half the emu are females</span> how many eggs does he get a week?
|
| 229 |
+
</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="problem-understanding">
|
| 232 |
+
<div class="section-title">Problem Summary</div>
|
| 233 |
+
<ul>
|
| 234 |
+
<li><span class="fact1-color">Number of pens: 4</span></li>
|
| 235 |
+
<li><span class="fact2-color">Number of emus per pen: 6</span></li>
|
| 236 |
+
<li><span class="fact3-color">Eggs per female emu per day: 1</span></li>
|
| 237 |
+
<li><span class="fact4-color">Proportion of female emus: 1/2</span></li>
|
| 238 |
+
</ul>
|
| 239 |
+
<div class="what-to-find">
|
| 240 |
+
<h4>What we need to find</h4>
|
| 241 |
+
<p>How many eggs John gets in a week.</p>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="right-panel">
|
| 246 |
+
<div class="debugger-controls">
|
| 247 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 248 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 249 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 250 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 251 |
+
</div>
|
| 252 |
+
<div class="python-solution">
|
| 253 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 254 |
+
<div class="python-code" id="python-code">
|
| 255 |
+
<div class="code-line" data-step="0">
|
| 256 |
+
<span class="line-number">1</span>
|
| 257 |
+
<span class="comment"># Calculate the total number of emus</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="1">
|
| 260 |
+
<span class="line-number">2</span>
|
| 261 |
+
<span><span class="var1-color">total_emus</span> = <span class="fact2-color">6</span> * <span class="fact1-color">4</span></span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="2">
|
| 264 |
+
<span class="line-number">3</span>
|
| 265 |
+
<span class="comment"># Calculate the number of female emus</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="3">
|
| 268 |
+
<span class="line-number">4</span>
|
| 269 |
+
<span><span class="var2-color">female_emus</span> = <span class="var1-color">total_emus</span> / <span class="fact4-color">2</span></span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="4">
|
| 272 |
+
<span class="line-number">5</span>
|
| 273 |
+
<span class="comment"># Calculate the total number of eggs in a week</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="5">
|
| 276 |
+
<span class="line-number">6</span>
|
| 277 |
+
<span><span class="var3-color">total_eggs</span> = <span class="var2-color">female_emus</span> * <span class="fact3-color">7</span></span>
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="variables-display" id="variables-display">
|
| 282 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 283 |
+
<div id="variables-list">
|
| 284 |
+
<div class="variable-item">
|
| 285 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 286 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<script>
|
| 294 |
+
class PythonDebugger {
|
| 295 |
+
constructor() {
|
| 296 |
+
this.currentStep = -1;
|
| 297 |
+
this.isPlaying = false;
|
| 298 |
+
this.playInterval = null;
|
| 299 |
+
this.totalSteps = 5;
|
| 300 |
+
this.variables = {};
|
| 301 |
+
|
| 302 |
+
this.initializeElements();
|
| 303 |
+
this.bindEvents();
|
| 304 |
+
this.updateUI();
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
initializeElements() {
|
| 308 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 309 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 310 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 311 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 312 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 313 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
bindEvents() {
|
| 317 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 318 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 319 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 320 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
togglePlay() {
|
| 324 |
+
if (this.isPlaying) {
|
| 325 |
+
this.pause();
|
| 326 |
+
} else {
|
| 327 |
+
this.play();
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
play() {
|
| 332 |
+
this.isPlaying = true;
|
| 333 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 334 |
+
|
| 335 |
+
if (this.currentStep >= this.totalSteps) {
|
| 336 |
+
this.currentStep = -1;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
this.playInterval = setInterval(() => {
|
| 340 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 341 |
+
if (nextStep !== null) {
|
| 342 |
+
this.currentStep = nextStep;
|
| 343 |
+
this.executeStep(this.currentStep);
|
| 344 |
+
this.updateUI();
|
| 345 |
+
} else {
|
| 346 |
+
this.pause();
|
| 347 |
+
}
|
| 348 |
+
}, 1500);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
pause() {
|
| 352 |
+
this.isPlaying = false;
|
| 353 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 354 |
+
if (this.playInterval) {
|
| 355 |
+
clearInterval(this.playInterval);
|
| 356 |
+
this.playInterval = null;
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
stop() {
|
| 361 |
+
this.pause();
|
| 362 |
+
this.currentStep = -1;
|
| 363 |
+
this.variables = {};
|
| 364 |
+
this.updateUI();
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
nextStep() {
|
| 368 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 369 |
+
if (nextStep !== null) {
|
| 370 |
+
this.currentStep = nextStep;
|
| 371 |
+
this.executeStep(this.currentStep);
|
| 372 |
+
this.updateUI();
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
previousStep() {
|
| 377 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 378 |
+
if (prevStep !== null) {
|
| 379 |
+
this.currentStep = prevStep;
|
| 380 |
+
this.recalculateVariables();
|
| 381 |
+
this.updateUI();
|
| 382 |
+
} else if (this.currentStep !== -1) {
|
| 383 |
+
this.currentStep = -1;
|
| 384 |
+
this.variables = {};
|
| 385 |
+
this.updateUI();
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
executeStep(step) {
|
| 390 |
+
switch(step) {
|
| 391 |
+
case 1:
|
| 392 |
+
this.variables.total_emus = 6 * 4;
|
| 393 |
+
break;
|
| 394 |
+
case 3:
|
| 395 |
+
this.variables.female_emus = this.variables.total_emus / 2;
|
| 396 |
+
break;
|
| 397 |
+
case 5:
|
| 398 |
+
// This is the wrong step as indicated in the unformatted information
|
| 399 |
+
// It should be female_emus * days_in_week, but we're using 7 directly
|
| 400 |
+
this.variables.total_eggs = this.variables.female_emus * 7;
|
| 401 |
+
break;
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
getExecutableSteps() {
|
| 406 |
+
// Returns only the steps that execute actual code (not comments)
|
| 407 |
+
return [1, 3, 5];
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
getNextExecutableStep(currentStep) {
|
| 411 |
+
const executableSteps = this.getExecutableSteps();
|
| 412 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 413 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
getPreviousExecutableStep(currentStep) {
|
| 417 |
+
const executableSteps = this.getExecutableSteps();
|
| 418 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 419 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
recalculateVariables() {
|
| 423 |
+
this.variables = {};
|
| 424 |
+
const executableSteps = this.getExecutableSteps();
|
| 425 |
+
for (let step of executableSteps) {
|
| 426 |
+
if (step <= this.currentStep) {
|
| 427 |
+
this.executeStep(step);
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
updateUI() {
|
| 433 |
+
// Update code highlighting
|
| 434 |
+
this.codeLines.forEach((line, index) => {
|
| 435 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 436 |
+
});
|
| 437 |
+
|
| 438 |
+
// Update button states
|
| 439 |
+
const executableSteps = this.getExecutableSteps();
|
| 440 |
+
const isFirstStep = this.currentStep === -1;
|
| 441 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 442 |
+
|
| 443 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 444 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 445 |
+
|
| 446 |
+
// Update variables display
|
| 447 |
+
this.updateVariablesDisplay();
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
updateVariablesDisplay() {
|
| 451 |
+
if (Object.keys(this.variables).length === 0) {
|
| 452 |
+
this.variablesDisplay.innerHTML = `
|
| 453 |
+
<div class="variable-item">
|
| 454 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 455 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 456 |
+
</div>
|
| 457 |
+
`;
|
| 458 |
+
return;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
let html = '';
|
| 462 |
+
const variableOrder = ['total_emus', 'female_emus', 'total_eggs'];
|
| 463 |
+
|
| 464 |
+
variableOrder.forEach(varName => {
|
| 465 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 466 |
+
const value = this.variables[varName];
|
| 467 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 468 |
+
|
| 469 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 470 |
+
if(varName === lastVarName){
|
| 471 |
+
varName = varName + " (Final Answer)";
|
| 472 |
+
html += `<div class="variable-item ${colorClass}">
|
| 473 |
+
<span class="variable-name">${varName}</span>
|
| 474 |
+
<span class="variable-value">${value}</span>
|
| 475 |
+
</div>`;
|
| 476 |
+
} else {
|
| 477 |
+
html += `<div class="variable-item ${colorClass}">
|
| 478 |
+
<span class="variable-name">${varName}</span>
|
| 479 |
+
<span class="variable-value">${value}</span>
|
| 480 |
+
</div>`;
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
});
|
| 484 |
+
|
| 485 |
+
this.variablesDisplay.innerHTML = html;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
getVariableColorClass(varName) {
|
| 489 |
+
const colorMap = {
|
| 490 |
+
'total_emus': 'var1-color',
|
| 491 |
+
'female_emus': 'var2-color',
|
| 492 |
+
'total_eggs': 'var3-color'
|
| 493 |
+
};
|
| 494 |
+
return colorMap[varName] || '';
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
// Initialize the debugger when the page loads
|
| 499 |
+
document.addEventListener('DOMContentLoaded', () => {
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 192 |
+
|
| 193 |
+
ul {
|
| 194 |
+
padding-left: 20px;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
li {
|
| 198 |
+
margin-bottom: 12px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.what-to-find {
|
| 202 |
+
margin-top: 20px;
|
| 203 |
+
padding: 15px;
|
| 204 |
+
background-color: #e8f4fd;
|
| 205 |
+
border-radius: 6px;
|
| 206 |
+
border-left: 4px solid #3498db;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.what-to-find h4 {
|
| 210 |
+
color: #2c3e50;
|
| 211 |
+
margin-bottom: 8px;
|
| 212 |
+
}
|
| 213 |
+
.wrong-step {
|
| 214 |
+
display: none;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
</style>
|
| 218 |
+
</head>
|
| 219 |
+
<body>
|
| 220 |
+
<div class="wrong-step">0</div>
|
| 221 |
+
<div class="container">
|
| 222 |
+
<div class="left-panel">
|
| 223 |
+
<div class="problem-statement">
|
| 224 |
+
<div class="section-title">Problem Statement</div>
|
| 225 |
+
<p>
|
| 226 |
+
On a highway, <span id="fact1" class="fact1-color">the total number of vehicles passing is 300</span>. If <span id="fact2" class="fact2-color">the number of cars on the highway is twice the number of trucks</span>, find out the total number of trucks on the highway?
|
| 227 |
+
</p>
|
| 228 |
+
</div>
|
| 229 |
+
<div class="problem-understanding">
|
| 230 |
+
<div class="section-title">Problem Summary</div>
|
| 231 |
+
<ul>
|
| 232 |
+
<li><span class="fact1-color">Total vehicles: 300</span></li>
|
| 233 |
+
<li><span class="fact2-color">Cars = 2 × Trucks</span></li>
|
| 234 |
+
</ul>
|
| 235 |
+
<div class="what-to-find">
|
| 236 |
+
<h4>What we need to find</h4>
|
| 237 |
+
<p>Find out the total number of trucks on the highway.</p>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
<div class="right-panel">
|
| 242 |
+
<div class="debugger-controls">
|
| 243 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 244 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 245 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 246 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 247 |
+
</div>
|
| 248 |
+
<div class="python-solution">
|
| 249 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 250 |
+
<div class="python-code" id="python-code">
|
| 251 |
+
<div class="code-line" data-step="0">
|
| 252 |
+
<span class="line-number">1</span>
|
| 253 |
+
<span class="comment"># If we assume that the number of trucks on the highway is t</span>
|
| 254 |
+
</div>
|
| 255 |
+
<div class="code-line" data-step="1">
|
| 256 |
+
<span class="line-number">2</span>
|
| 257 |
+
<span><span class="var1-color">t</span> = 0 # Initial value for trucks</span>
|
| 258 |
+
</div>
|
| 259 |
+
<div class="code-line" data-step="2">
|
| 260 |
+
<span class="line-number">3</span>
|
| 261 |
+
<span class="comment"># The total number of cars and trucks on the road is 2t+t= 300</span>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="code-line" data-step="3">
|
| 264 |
+
<span class="line-number">4</span>
|
| 265 |
+
<span><span class="var2-color">cars</span> = 2 * <span class="var1-color">t</span> # Number of cars is twice the number of trucks</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="4">
|
| 268 |
+
<span class="line-number">5</span>
|
| 269 |
+
<span class="comment"># The number of vehicles on the road is 3t=300</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="5">
|
| 272 |
+
<span class="line-number">6</span>
|
| 273 |
+
<span><span class="var3-color">total_vehicles</span> = <span class="var2-color">cars</span> + <span class="var1-color">t</span> # Total vehicles is cars plus trucks</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="6">
|
| 276 |
+
<span class="line-number">7</span>
|
| 277 |
+
<span class="comment"># The are t=300/3 trucks on the highway</span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="7">
|
| 280 |
+
<span class="line-number">8</span>
|
| 281 |
+
<span><span class="var1-color">t</span> = <span class="fact1-color">300</span> / 3 # Solving for t</span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="8">
|
| 284 |
+
<span class="line-number">9</span>
|
| 285 |
+
<span class="comment"># This means there are t=100 trucks on the road</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="9">
|
| 288 |
+
<span class="line-number">10</span>
|
| 289 |
+
<span><span class="var1-color">t</span> = 100 # Final answer</span>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="variables-display" id="variables-display">
|
| 294 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 295 |
+
<div id="variables-list">
|
| 296 |
+
<div class="variable-item">
|
| 297 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 298 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
</div>
|
| 303 |
+
</div>
|
| 304 |
+
|
| 305 |
+
<script>
|
| 306 |
+
class PythonDebugger {
|
| 307 |
+
constructor() {
|
| 308 |
+
this.currentStep = -1;
|
| 309 |
+
this.isPlaying = false;
|
| 310 |
+
this.playInterval = null;
|
| 311 |
+
this.totalSteps = 9;
|
| 312 |
+
this.variables = {};
|
| 313 |
+
|
| 314 |
+
this.initializeElements();
|
| 315 |
+
this.bindEvents();
|
| 316 |
+
this.updateUI();
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
initializeElements() {
|
| 320 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 321 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 322 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 323 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 324 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 325 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
bindEvents() {
|
| 329 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 330 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 331 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 332 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
togglePlay() {
|
| 336 |
+
if (this.isPlaying) {
|
| 337 |
+
this.pause();
|
| 338 |
+
} else {
|
| 339 |
+
this.play();
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
play() {
|
| 344 |
+
this.isPlaying = true;
|
| 345 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 346 |
+
|
| 347 |
+
if (this.currentStep >= this.totalSteps) {
|
| 348 |
+
this.currentStep = -1;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
this.playInterval = setInterval(() => {
|
| 352 |
+
if (this.currentStep < this.totalSteps) {
|
| 353 |
+
this.currentStep++;
|
| 354 |
+
this.executeStep(this.currentStep);
|
| 355 |
+
this.updateUI();
|
| 356 |
+
} else {
|
| 357 |
+
this.pause();
|
| 358 |
+
}
|
| 359 |
+
}, 1500);
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
pause() {
|
| 363 |
+
this.isPlaying = false;
|
| 364 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 365 |
+
if (this.playInterval) {
|
| 366 |
+
clearInterval(this.playInterval);
|
| 367 |
+
this.playInterval = null;
|
| 368 |
+
}
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
stop() {
|
| 372 |
+
this.pause();
|
| 373 |
+
this.currentStep = -1;
|
| 374 |
+
this.variables = {};
|
| 375 |
+
this.updateUI();
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
nextStep() {
|
| 379 |
+
if (this.currentStep < this.totalSteps) {
|
| 380 |
+
this.currentStep++;
|
| 381 |
+
this.executeStep(this.currentStep);
|
| 382 |
+
this.updateUI();
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
previousStep() {
|
| 387 |
+
if (this.currentStep > 0) {
|
| 388 |
+
this.currentStep--;
|
| 389 |
+
this.recalculateVariables();
|
| 390 |
+
this.updateUI();
|
| 391 |
+
} else if (this.currentStep === 0) {
|
| 392 |
+
this.currentStep = -1;
|
| 393 |
+
this.variables = {};
|
| 394 |
+
this.updateUI();
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
executeStep(step) {
|
| 399 |
+
switch(step) {
|
| 400 |
+
case 1:
|
| 401 |
+
this.variables.t = 0;
|
| 402 |
+
break;
|
| 403 |
+
case 3:
|
| 404 |
+
this.variables.cars = 2 * this.variables.t;
|
| 405 |
+
break;
|
| 406 |
+
case 5:
|
| 407 |
+
this.variables.total_vehicles = this.variables.cars + this.variables.t;
|
| 408 |
+
break;
|
| 409 |
+
case 7:
|
| 410 |
+
this.variables.t = 300 / 3;
|
| 411 |
+
break;
|
| 412 |
+
case 9:
|
| 413 |
+
this.variables.t = 100;
|
| 414 |
+
break;
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
recalculateVariables() {
|
| 419 |
+
this.variables = {};
|
| 420 |
+
for (let i = 0; i <= this.currentStep; i++) {
|
| 421 |
+
this.executeStep(i);
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
updateUI() {
|
| 426 |
+
// Update code highlighting
|
| 427 |
+
this.codeLines.forEach((line, index) => {
|
| 428 |
+
line.classList.remove('current');
|
| 429 |
+
});
|
| 430 |
+
|
| 431 |
+
if (this.currentStep >= 0 && this.currentStep <= this.totalSteps) {
|
| 432 |
+
this.codeLines[this.currentStep].classList.add('current');
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Update button states
|
| 436 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep <= -1);
|
| 437 |
+
this.nextBtn.classList.toggle('disabled', this.currentStep >= this.totalSteps);
|
| 438 |
+
|
| 439 |
+
// Update variables display
|
| 440 |
+
this.updateVariablesDisplay();
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
updateVariablesDisplay() {
|
| 444 |
+
if (Object.keys(this.variables).length === 0) {
|
| 445 |
+
this.variablesDisplay.innerHTML = `
|
| 446 |
+
<div class="variable-item">
|
| 447 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 448 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 449 |
+
</div>
|
| 450 |
+
`;
|
| 451 |
+
return;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
let html = '';
|
| 455 |
+
const variableOrder = ['t', 'cars', 'total_vehicles'];
|
| 456 |
+
|
| 457 |
+
variableOrder.forEach(varName => {
|
| 458 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 459 |
+
const value = this.variables[varName];
|
| 460 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 461 |
+
|
| 462 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 463 |
+
if(varName === lastVarName){
|
| 464 |
+
varName = varName + " (Final Answer)";
|
| 465 |
+
html += `<div class="variable-item ${colorClass}">
|
| 466 |
+
<span class="variable-name">${varName}</span>
|
| 467 |
+
<span class="variable-value">${value}</span>
|
| 468 |
+
</div>`;
|
| 469 |
+
} else {
|
| 470 |
+
html += `<div class="variable-item ${colorClass}">
|
| 471 |
+
<span class="variable-name">${varName}</span>
|
| 472 |
+
<span class="variable-value">${value}</span>
|
| 473 |
+
</div>`;
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
});
|
| 477 |
+
|
| 478 |
+
this.variablesDisplay.innerHTML = html;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
getVariableColorClass(varName) {
|
| 482 |
+
const colorMap = {
|
| 483 |
+
't': 'var1-color',
|
| 484 |
+
'cars': 'var2-color',
|
| 485 |
+
'total_vehicles': 'var3-color'
|
| 486 |
+
};
|
| 487 |
+
return colorMap[varName] || '';
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
// Initialize the debugger when the page loads
|
| 492 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 493 |
+
new PythonDebugger();
|
| 494 |
+
});
|
| 495 |
+
</script>
|
| 496 |
+
</body>
|
| 497 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_42.html
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
|
| 192 |
+
ul {
|
| 193 |
+
padding-left: 20px;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
li {
|
| 197 |
+
margin-bottom: 12px;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
.what-to-find {
|
| 201 |
+
margin-top: 20px;
|
| 202 |
+
padding: 15px;
|
| 203 |
+
background-color: #e8f4fd;
|
| 204 |
+
border-radius: 6px;
|
| 205 |
+
border-left: 4px solid #3498db;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.what-to-find h4 {
|
| 209 |
+
color: #2c3e50;
|
| 210 |
+
margin-bottom: 8px;
|
| 211 |
+
}
|
| 212 |
+
.wrong-step {
|
| 213 |
+
display: none;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
</style>
|
| 217 |
+
</head>
|
| 218 |
+
<body>
|
| 219 |
+
<div class="wrong-step">0</div>
|
| 220 |
+
<div class="container">
|
| 221 |
+
<div class="left-panel">
|
| 222 |
+
<div class="problem-statement">
|
| 223 |
+
<div class="section-title">Problem Statement</div>
|
| 224 |
+
<p>
|
| 225 |
+
At the same store, <span id="fact1" class="fact1-color">Peter bought 2 pairs of pants and 5 shirts for $62 total</span>, and <span id="fact2" class="fact2-color">Jessica bought 2 shirts for $20 total</span>. Each pair of pants cost the same price, and each shirt cost the same price. How much does 1 pair of pants cost?
|
| 226 |
+
</p>
|
| 227 |
+
</div>
|
| 228 |
+
<div class="problem-understanding">
|
| 229 |
+
<div class="section-title">Problem Summary</div>
|
| 230 |
+
<ul>
|
| 231 |
+
<li><span class="fact1-color">Peter's purchase: 2 pairs of pants and 5 shirts for $62</span></li>
|
| 232 |
+
<li><span class="fact2-color">Jessica's purchase: 2 shirts for $20</span></li>
|
| 233 |
+
</ul>
|
| 234 |
+
<div class="what-to-find">
|
| 235 |
+
<h4>What we need to find</h4>
|
| 236 |
+
<p>The cost of 1 pair of pants.</p>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
<div class="right-panel">
|
| 241 |
+
<div class="debugger-controls">
|
| 242 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 243 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 244 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 245 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 246 |
+
</div>
|
| 247 |
+
<div class="python-solution">
|
| 248 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 249 |
+
<div class="python-code" id="python-code">
|
| 250 |
+
<div class="code-line" data-step="0">
|
| 251 |
+
<span class="line-number">1</span>
|
| 252 |
+
<span class="comment"># Calculate the cost per shirt from Jessica's purchase</span>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="code-line" data-step="1">
|
| 255 |
+
<span class="line-number">2</span>
|
| 256 |
+
<span><span class="var1-color">cost_per_shirt</span> = <span class="fact2-color">20</span> / 2</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="code-line" data-step="2">
|
| 259 |
+
<span class="line-number">3</span>
|
| 260 |
+
<span class="comment"># Set up equation for Peter's purchase</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="code-line" data-step="3">
|
| 263 |
+
<span class="line-number">4</span>
|
| 264 |
+
<span>2 * <span class="var2-color">X</span> + 5 * <span class="var1-color">cost_per_shirt</span> = <span class="fact1-color">62</span></span>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="code-line" data-step="4">
|
| 267 |
+
<span class="line-number">5</span>
|
| 268 |
+
<span class="comment"># Subtract the cost of shirts from both sides</span>
|
| 269 |
+
</div>
|
| 270 |
+
<div class="code-line" data-step="5">
|
| 271 |
+
<span class="line-number">6</span>
|
| 272 |
+
<span>2 * <span class="var2-color">X</span> = <span class="fact1-color">62</span> - 5 * <span class="var1-color">cost_per_shirt</span></span>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="code-line" data-step="6">
|
| 275 |
+
<span class="line-number">7</span>
|
| 276 |
+
<span class="comment"># Solve for X by dividing both sides by 2</span>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="code-line" data-step="7">
|
| 279 |
+
<span class="line-number">8</span>
|
| 280 |
+
<span><span class="var2-color">X</span> = (62 - 5 * <span class="var1-color">cost_per_shirt</span>) / 2</span>
|
| 281 |
+
</div>
|
| 282 |
+
</div>
|
| 283 |
+
</div>
|
| 284 |
+
<div class="variables-display" id="variables-display">
|
| 285 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 286 |
+
<div id="variables-list">
|
| 287 |
+
<div class="variable-item">
|
| 288 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 289 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
|
| 296 |
+
<script>
|
| 297 |
+
class PythonDebugger {
|
| 298 |
+
constructor() {
|
| 299 |
+
this.currentStep = -1;
|
| 300 |
+
this.isPlaying = false;
|
| 301 |
+
this.playInterval = null;
|
| 302 |
+
this.totalSteps = 7;
|
| 303 |
+
this.variables = {};
|
| 304 |
+
|
| 305 |
+
this.initializeElements();
|
| 306 |
+
this.bindEvents();
|
| 307 |
+
this.updateUI();
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
initializeElements() {
|
| 311 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 312 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 313 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 314 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 315 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 316 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
bindEvents() {
|
| 320 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 321 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 322 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 323 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
togglePlay() {
|
| 327 |
+
if (this.isPlaying) {
|
| 328 |
+
this.pause();
|
| 329 |
+
} else {
|
| 330 |
+
this.play();
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
play() {
|
| 335 |
+
this.isPlaying = true;
|
| 336 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 337 |
+
|
| 338 |
+
if (this.currentStep >= this.totalSteps) {
|
| 339 |
+
this.currentStep = -1;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
this.playInterval = setInterval(() => {
|
| 343 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 344 |
+
if (nextStep !== null) {
|
| 345 |
+
this.currentStep = nextStep;
|
| 346 |
+
this.executeStep(this.currentStep);
|
| 347 |
+
this.updateUI();
|
| 348 |
+
} else {
|
| 349 |
+
this.pause();
|
| 350 |
+
}
|
| 351 |
+
}, 1500);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
pause() {
|
| 355 |
+
this.isPlaying = false;
|
| 356 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 357 |
+
if (this.playInterval) {
|
| 358 |
+
clearInterval(this.playInterval);
|
| 359 |
+
this.playInterval = null;
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
stop() {
|
| 364 |
+
this.pause();
|
| 365 |
+
this.currentStep = -1;
|
| 366 |
+
this.variables = {};
|
| 367 |
+
this.updateUI();
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
nextStep() {
|
| 371 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 372 |
+
if (nextStep !== null) {
|
| 373 |
+
this.currentStep = nextStep;
|
| 374 |
+
this.executeStep(this.currentStep);
|
| 375 |
+
this.updateUI();
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
previousStep() {
|
| 380 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 381 |
+
if (prevStep !== null) {
|
| 382 |
+
this.currentStep = prevStep;
|
| 383 |
+
this.recalculateVariables();
|
| 384 |
+
this.updateUI();
|
| 385 |
+
} else if (this.currentStep !== -1) {
|
| 386 |
+
this.currentStep = -1;
|
| 387 |
+
this.variables = {};
|
| 388 |
+
this.updateUI();
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
executeStep(step) {
|
| 393 |
+
switch(step) {
|
| 394 |
+
case 1:
|
| 395 |
+
this.variables.cost_per_shirt = 20 / 2;
|
| 396 |
+
break;
|
| 397 |
+
case 3:
|
| 398 |
+
// This is where the equation is set up, no calculation yet
|
| 399 |
+
this.variables.X = "unknown";
|
| 400 |
+
break;
|
| 401 |
+
case 5:
|
| 402 |
+
// This is the wrong step according to the unformatted information
|
| 403 |
+
// We'll implement it as given in the unformatted information
|
| 404 |
+
this.variables.equation = "2X = $12";
|
| 405 |
+
break;
|
| 406 |
+
case 7:
|
| 407 |
+
this.variables.X = 6;
|
| 408 |
+
break;
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
getExecutableSteps() {
|
| 413 |
+
// Returns only the steps that execute actual code (not comments)
|
| 414 |
+
return [1, 3, 5, 7];
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
getNextExecutableStep(currentStep) {
|
| 418 |
+
const executableSteps = this.getExecutableSteps();
|
| 419 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 420 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
getPreviousExecutableStep(currentStep) {
|
| 424 |
+
const executableSteps = this.getExecutableSteps();
|
| 425 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 426 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
recalculateVariables() {
|
| 430 |
+
this.variables = {};
|
| 431 |
+
const executableSteps = this.getExecutableSteps();
|
| 432 |
+
for (let step of executableSteps) {
|
| 433 |
+
if (step <= this.currentStep) {
|
| 434 |
+
this.executeStep(step);
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
updateUI() {
|
| 440 |
+
// Update code highlighting
|
| 441 |
+
this.codeLines.forEach((line, index) => {
|
| 442 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 443 |
+
});
|
| 444 |
+
|
| 445 |
+
// Update button states
|
| 446 |
+
const executableSteps = this.getExecutableSteps();
|
| 447 |
+
const isFirstStep = this.currentStep === -1;
|
| 448 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 449 |
+
|
| 450 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 451 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 452 |
+
|
| 453 |
+
// Update variables display
|
| 454 |
+
this.updateVariablesDisplay();
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
updateVariablesDisplay() {
|
| 458 |
+
if (Object.keys(this.variables).length === 0) {
|
| 459 |
+
this.variablesDisplay.innerHTML = `
|
| 460 |
+
<div class="variable-item">
|
| 461 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 462 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 463 |
+
</div>
|
| 464 |
+
`;
|
| 465 |
+
return;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
let html = '';
|
| 469 |
+
const variableOrder = ['cost_per_shirt', 'X', 'equation'];
|
| 470 |
+
|
| 471 |
+
variableOrder.forEach(varName => {
|
| 472 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 473 |
+
const value = this.variables[varName];
|
| 474 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 475 |
+
|
| 476 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 477 |
+
if(varName === lastVarName){
|
| 478 |
+
varName = varName + " (Final Answer)";
|
| 479 |
+
html += `<div class="variable-item ${colorClass}">
|
| 480 |
+
<span class="variable-name">${varName}</span>
|
| 481 |
+
<span class="variable-value">${value}</span>
|
| 482 |
+
</div>`;
|
| 483 |
+
} else {
|
| 484 |
+
html += `<div class="variable-item ${colorClass}">
|
| 485 |
+
<span class="variable-name">${varName}</span>
|
| 486 |
+
<span class="variable-value">${value}</span>
|
| 487 |
+
</div>`;
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
});
|
| 491 |
+
|
| 492 |
+
this.variablesDisplay.innerHTML = html;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
getVariableColorClass(varName) {
|
| 496 |
+
const colorMap = {
|
| 497 |
+
'cost_per_shirt': 'var1-color',
|
| 498 |
+
'X': 'var2-color',
|
| 499 |
+
'equation': ''
|
| 500 |
+
};
|
| 501 |
+
return colorMap[varName] || '';
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
// Initialize the debugger when the page loads
|
| 506 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 507 |
+
new PythonDebugger();
|
| 508 |
+
});
|
| 509 |
+
</script>
|
| 510 |
+
</body>
|
| 511 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_43.html
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.fact3-color { background-color: rgba(0, 123, 255, 0.5); }
|
| 190 |
+
.fact4-color { background-color: rgba(220, 53, 69, 0.5); }
|
| 191 |
+
.fact5-color { background-color: rgba(156, 39, 176, 0.5); }
|
| 192 |
+
.fact6-color { background-color: rgba(76, 175, 80, 0.5); }
|
| 193 |
+
.fact7-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 194 |
+
.var1-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 195 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 196 |
+
.var3-color { background-color: rgba(121, 85, 72, 0.5); }
|
| 197 |
+
.var4-color { background-color: rgba(0, 188, 212, 0.5); }
|
| 198 |
+
.var5-color { background-color: rgba(255, 152, 0, 0.5); }
|
| 199 |
+
|
| 200 |
+
ul {
|
| 201 |
+
padding-left: 20px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
li {
|
| 205 |
+
margin-bottom: 12px;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.what-to-find {
|
| 209 |
+
margin-top: 20px;
|
| 210 |
+
padding: 15px;
|
| 211 |
+
background-color: #e8f4fd;
|
| 212 |
+
border-radius: 6px;
|
| 213 |
+
border-left: 4px solid #3498db;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.what-to-find h4 {
|
| 217 |
+
color: #2c3e50;
|
| 218 |
+
margin-bottom: 8px;
|
| 219 |
+
}
|
| 220 |
+
.wrong-step {
|
| 221 |
+
display: none;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
</style>
|
| 225 |
+
</head>
|
| 226 |
+
<body>
|
| 227 |
+
<div class="wrong-step">0</div>
|
| 228 |
+
<div class="container">
|
| 229 |
+
<div class="left-panel">
|
| 230 |
+
<div class="problem-statement">
|
| 231 |
+
<div class="section-title">Problem Statement</div>
|
| 232 |
+
<p>
|
| 233 |
+
<span id="fact1" class="fact1-color">Sandra saved $10 for sweets</span>. <span id="fact2" class="fact2-color">Her mother gave her an additional $4</span>, and <span id="fact3" class="fact3-color">her father twice as much as her mother</span>. <span id="fact4" class="fact4-color">One candy costs $0.5</span>, and <span id="fact5" class="fact5-color">one jelly bean $0.2</span>. She wants to buy <span id="fact6" class="fact6-color">14 candies</span> and <span id="fact7" class="fact7-color">20 jelly beans</span>. How much money will she be left with after the purchase?
|
| 234 |
+
</p>
|
| 235 |
+
</div>
|
| 236 |
+
<div class="problem-understanding">
|
| 237 |
+
<div class="section-title">Problem Summary</div>
|
| 238 |
+
<ul>
|
| 239 |
+
<li><span class="fact1-color">Sandra's savings: $10</span></li>
|
| 240 |
+
<li><span class="fact2-color">Money from mother: $4</span></li>
|
| 241 |
+
<li><span class="fact3-color">Money from father: 2 times mother's amount</span></li>
|
| 242 |
+
<li><span class="fact4-color">Cost of one candy: $0.5</span></li>
|
| 243 |
+
<li><span class="fact5-color">Cost of one jelly bean: $0.2</span></li>
|
| 244 |
+
<li><span class="fact6-color">Number of candies to buy: 14</span></li>
|
| 245 |
+
<li><span class="fact7-color">Number of jelly beans to buy: 20</span></li>
|
| 246 |
+
</ul>
|
| 247 |
+
<div class="what-to-find">
|
| 248 |
+
<h4>What we need to find</h4>
|
| 249 |
+
<p>How much money Sandra will be left with after the purchase.</p>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="right-panel">
|
| 254 |
+
<div class="debugger-controls">
|
| 255 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 256 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 257 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 258 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 259 |
+
</div>
|
| 260 |
+
<div class="python-solution">
|
| 261 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 262 |
+
<div class="python-code" id="python-code">
|
| 263 |
+
<div class="code-line" data-step="0">
|
| 264 |
+
<span class="line-number">1</span>
|
| 265 |
+
<span class="comment"># Calculate how much money Sandra's father gave her</span>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="code-line" data-step="1">
|
| 268 |
+
<span class="line-number">2</span>
|
| 269 |
+
<span><span class="var1-color">father_money</span> = <span class="fact2-color">4</span> * <span class="fact3-color">2</span></span>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="code-line" data-step="2">
|
| 272 |
+
<span class="line-number">3</span>
|
| 273 |
+
<span class="comment"># Calculate total money Sandra has</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="code-line" data-step="3">
|
| 276 |
+
<span class="line-number">4</span>
|
| 277 |
+
<span><span class="var2-color">total_money</span> = <span class="var1-color">father_money</span> + <span class="fact2-color">4</span> + <span class="fact1-color">10</span></span>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="code-line" data-step="4">
|
| 280 |
+
<span class="line-number">5</span>
|
| 281 |
+
<span class="comment"># Calculate cost of candies</span>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="code-line" data-step="5">
|
| 284 |
+
<span class="line-number">6</span>
|
| 285 |
+
<span><span class="var3-color">candy_cost</span> = <span class="fact6-color">14</span> * <span class="fact4-color">0.50</span></span>
|
| 286 |
+
</div>
|
| 287 |
+
<div class="code-line" data-step="6">
|
| 288 |
+
<span class="line-number">7</span>
|
| 289 |
+
<span class="comment"># Calculate cost of jelly beans</span>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="code-line" data-step="7">
|
| 292 |
+
<span class="line-number">8</span>
|
| 293 |
+
<span><span class="var4-color">jellybean_cost</span> = <span class="fact7-color">20</span> * <span class="fact5-color">0.20</span></span>
|
| 294 |
+
</div>
|
| 295 |
+
<div class="code-line" data-step="8">
|
| 296 |
+
<span class="line-number">9</span>
|
| 297 |
+
<span class="comment"># Calculate money left after purchase</span>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="code-line" data-step="9">
|
| 300 |
+
<span class="line-number">10</span>
|
| 301 |
+
<span><span class="var5-color">money_left</span> = <span class="var2-color">total_money</span> - <span class="var4-color">jellybean_cost</span> - <span class="var3-color">candy_cost</span></span>
|
| 302 |
+
</div>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
<div class="variables-display" id="variables-display">
|
| 306 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 307 |
+
<div id="variables-list">
|
| 308 |
+
<div class="variable-item">
|
| 309 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 310 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
|
| 317 |
+
<script>
|
| 318 |
+
class PythonDebugger {
|
| 319 |
+
constructor() {
|
| 320 |
+
this.currentStep = -1;
|
| 321 |
+
this.isPlaying = false;
|
| 322 |
+
this.playInterval = null;
|
| 323 |
+
this.totalSteps = 9;
|
| 324 |
+
this.variables = {};
|
| 325 |
+
|
| 326 |
+
this.initializeElements();
|
| 327 |
+
this.bindEvents();
|
| 328 |
+
this.updateUI();
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
initializeElements() {
|
| 332 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 333 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 334 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 335 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 336 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 337 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
bindEvents() {
|
| 341 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 342 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 343 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 344 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
togglePlay() {
|
| 348 |
+
if (this.isPlaying) {
|
| 349 |
+
this.pause();
|
| 350 |
+
} else {
|
| 351 |
+
this.play();
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
play() {
|
| 356 |
+
this.isPlaying = true;
|
| 357 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 358 |
+
|
| 359 |
+
if (this.currentStep >= this.totalSteps) {
|
| 360 |
+
this.currentStep = -1;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
this.playInterval = setInterval(() => {
|
| 364 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 365 |
+
if (nextStep !== null) {
|
| 366 |
+
this.currentStep = nextStep;
|
| 367 |
+
this.executeStep(this.currentStep);
|
| 368 |
+
this.updateUI();
|
| 369 |
+
} else {
|
| 370 |
+
this.pause();
|
| 371 |
+
}
|
| 372 |
+
}, 1500);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
pause() {
|
| 376 |
+
this.isPlaying = false;
|
| 377 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 378 |
+
if (this.playInterval) {
|
| 379 |
+
clearInterval(this.playInterval);
|
| 380 |
+
this.playInterval = null;
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
stop() {
|
| 385 |
+
this.pause();
|
| 386 |
+
this.currentStep = -1;
|
| 387 |
+
this.variables = {};
|
| 388 |
+
this.updateUI();
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
nextStep() {
|
| 392 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 393 |
+
if (nextStep !== null) {
|
| 394 |
+
this.currentStep = nextStep;
|
| 395 |
+
this.executeStep(this.currentStep);
|
| 396 |
+
this.updateUI();
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
previousStep() {
|
| 401 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 402 |
+
if (prevStep !== null) {
|
| 403 |
+
this.currentStep = prevStep;
|
| 404 |
+
this.recalculateVariables();
|
| 405 |
+
this.updateUI();
|
| 406 |
+
} else if (this.currentStep !== -1) {
|
| 407 |
+
this.currentStep = -1;
|
| 408 |
+
this.variables = {};
|
| 409 |
+
this.updateUI();
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
executeStep(step) {
|
| 414 |
+
switch(step) {
|
| 415 |
+
case 1:
|
| 416 |
+
this.variables.father_money = 4 * 2;
|
| 417 |
+
break;
|
| 418 |
+
case 3:
|
| 419 |
+
this.variables.total_money = this.variables.father_money + 4 + 10;
|
| 420 |
+
break;
|
| 421 |
+
case 5:
|
| 422 |
+
this.variables.candy_cost = 14 * 0.50;
|
| 423 |
+
break;
|
| 424 |
+
case 7:
|
| 425 |
+
this.variables.jellybean_cost = 20 * 0.20;
|
| 426 |
+
break;
|
| 427 |
+
case 9:
|
| 428 |
+
// This is the wrong step as indicated in the unformatted information
|
| 429 |
+
this.variables.money_left = this.variables.total_money - this.variables.jellybean_cost - this.variables.candy_cost;
|
| 430 |
+
break;
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
getExecutableSteps() {
|
| 435 |
+
// Returns only the steps that execute actual code (not comments)
|
| 436 |
+
return [1, 3, 5, 7, 9];
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
getNextExecutableStep(currentStep) {
|
| 440 |
+
const executableSteps = this.getExecutableSteps();
|
| 441 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 442 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
getPreviousExecutableStep(currentStep) {
|
| 446 |
+
const executableSteps = this.getExecutableSteps();
|
| 447 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 448 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
recalculateVariables() {
|
| 452 |
+
this.variables = {};
|
| 453 |
+
const executableSteps = this.getExecutableSteps();
|
| 454 |
+
for (let step of executableSteps) {
|
| 455 |
+
if (step <= this.currentStep) {
|
| 456 |
+
this.executeStep(step);
|
| 457 |
+
}
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
updateUI() {
|
| 462 |
+
// Update code highlighting
|
| 463 |
+
this.codeLines.forEach((line, index) => {
|
| 464 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 465 |
+
});
|
| 466 |
+
|
| 467 |
+
// Update button states
|
| 468 |
+
const executableSteps = this.getExecutableSteps();
|
| 469 |
+
const isFirstStep = this.currentStep === -1;
|
| 470 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 471 |
+
|
| 472 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 473 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 474 |
+
|
| 475 |
+
// Update variables display
|
| 476 |
+
this.updateVariablesDisplay();
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
updateVariablesDisplay() {
|
| 480 |
+
if (Object.keys(this.variables).length === 0) {
|
| 481 |
+
this.variablesDisplay.innerHTML = `
|
| 482 |
+
<div class="variable-item">
|
| 483 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 484 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 485 |
+
</div>
|
| 486 |
+
`;
|
| 487 |
+
return;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
let html = '';
|
| 491 |
+
const variableOrder = ['father_money', 'total_money', 'candy_cost', 'jellybean_cost', 'money_left'];
|
| 492 |
+
|
| 493 |
+
variableOrder.forEach(varName => {
|
| 494 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 495 |
+
const value = this.variables[varName];
|
| 496 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 497 |
+
const displayValue = varName.includes('money') || varName.includes('cost') ? `$${value.toFixed(2)}` : value;
|
| 498 |
+
|
| 499 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 500 |
+
if(varName === lastVarName){
|
| 501 |
+
varName = varName + " (Final Answer)";
|
| 502 |
+
html += `<div class="variable-item ${colorClass}">
|
| 503 |
+
<span class="variable-name">${varName}</span>
|
| 504 |
+
<span class="variable-value">${value}</span>
|
| 505 |
+
</div>`;
|
| 506 |
+
} else {
|
| 507 |
+
html += `<div class="variable-item ${colorClass}">
|
| 508 |
+
<span class="variable-name">${varName}</span>
|
| 509 |
+
<span class="variable-value">${value}</span>
|
| 510 |
+
</div>`;
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
});
|
| 514 |
+
|
| 515 |
+
this.variablesDisplay.innerHTML = html;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
getVariableColorClass(varName) {
|
| 519 |
+
const colorMap = {
|
| 520 |
+
'father_money': 'var1-color',
|
| 521 |
+
'total_money': 'var2-color',
|
| 522 |
+
'candy_cost': 'var3-color',
|
| 523 |
+
'jellybean_cost': 'var4-color',
|
| 524 |
+
'money_left': 'var5-color'
|
| 525 |
+
};
|
| 526 |
+
return colorMap[varName] || '';
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
// Initialize the debugger when the page loads
|
| 531 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 532 |
+
new PythonDebugger();
|
| 533 |
+
});
|
| 534 |
+
</script>
|
| 535 |
+
</body>
|
| 536 |
+
</html>
|
evaluation/eval_interfaces/interactive_coding_explanations/interactive_code_right_CA_44.html
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
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+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Problem-Solving Interface</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background-color: #f5f5f5;
|
| 17 |
+
color: #333;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
display: flex;
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 800px;
|
| 25 |
+
border: 1px solid #ddd;
|
| 26 |
+
background-color: white;
|
| 27 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.left-panel {
|
| 31 |
+
width: 40%;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
border-right: 1px solid #ddd;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.right-panel {
|
| 38 |
+
width: 60%;
|
| 39 |
+
display: flex;
|
| 40 |
+
flex-direction: column;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.problem-statement, .problem-understanding {
|
| 44 |
+
padding: 20px;
|
| 45 |
+
overflow-y: auto;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.problem-statement {
|
| 49 |
+
height: 50%;
|
| 50 |
+
border-bottom: 1px solid #ddd;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.problem-understanding {
|
| 54 |
+
height: 50%;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.section-title {
|
| 58 |
+
font-size: 1.4rem;
|
| 59 |
+
font-weight: 600;
|
| 60 |
+
margin-bottom: 15px;
|
| 61 |
+
color: #2c3e50;
|
| 62 |
+
border-bottom: 2px solid #3498db;
|
| 63 |
+
padding-bottom: 5px;
|
| 64 |
+
display: inline-block;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.debugger-controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
padding: 10px;
|
| 70 |
+
background-color: #f8f9fa;
|
| 71 |
+
border-bottom: 1px solid #ddd;
|
| 72 |
+
gap: 5px;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.btn {
|
| 76 |
+
display: flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
border: none;
|
| 81 |
+
border-radius: 4px;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
font-weight: 500;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
transition: all 0.2s ease;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.btn:hover:not(.disabled) {
|
| 89 |
+
opacity: 0.9;
|
| 90 |
+
transform: translateY(-1px);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-play-pause {
|
| 94 |
+
background-color: #2ecc71;
|
| 95 |
+
color: white;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-stop {
|
| 99 |
+
background-color: #e74c3c;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.btn-prev, .btn-next {
|
| 104 |
+
background-color: #3498db;
|
| 105 |
+
color: white;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.disabled {
|
| 109 |
+
opacity: 0.5;
|
| 110 |
+
cursor: not-allowed;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.python-solution {
|
| 114 |
+
height: 400px;
|
| 115 |
+
border: 1px solid #ddd;
|
| 116 |
+
margin: 10px;
|
| 117 |
+
border-radius: 4px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
background-color: #ffffff;
|
| 120 |
+
color: #333333;
|
| 121 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.python-code {
|
| 125 |
+
padding: 15px;
|
| 126 |
+
height: calc(100% - 50px);
|
| 127 |
+
overflow-y: auto;
|
| 128 |
+
font-size: 14px;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.code-line {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
padding: 4px 0;
|
| 136 |
+
position: relative;
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.code-line.current {
|
| 141 |
+
background-color: #ffeb3b;
|
| 142 |
+
color: #000;
|
| 143 |
+
padding-left: 8px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.line-number {
|
| 147 |
+
color: #888;
|
| 148 |
+
font-size: 12px;
|
| 149 |
+
min-width: 20px;
|
| 150 |
+
text-align: right;
|
| 151 |
+
margin-right: 15px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.comment {
|
| 155 |
+
color: #347778;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.variables-display {
|
| 159 |
+
height: 300px;
|
| 160 |
+
border: 1px solid #ddd;
|
| 161 |
+
margin: 10px;
|
| 162 |
+
border-radius: 4px;
|
| 163 |
+
background-color: #f8f9fa;
|
| 164 |
+
overflow-y: auto;
|
| 165 |
+
padding: 15px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.variable-item {
|
| 169 |
+
display: flex;
|
| 170 |
+
justify-content: space-between;
|
| 171 |
+
align-items: center;
|
| 172 |
+
padding: 8px 12px;
|
| 173 |
+
margin: 5px 0;
|
| 174 |
+
border-radius: 6px;
|
| 175 |
+
border-left: 4px solid #3498db;
|
| 176 |
+
font-weight: 500;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.variable-name {
|
| 180 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.variable-value {
|
| 184 |
+
font-weight: 600;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.fact1-color { background-color: rgba(255, 193, 7, 0.5); }
|
| 188 |
+
.fact2-color { background-color: rgba(40, 167, 69, 0.5); }
|
| 189 |
+
.var1-color { background-color: rgba(255, 87, 34, 0.5); }
|
| 190 |
+
.var2-color { background-color: rgba(96, 125, 139, 0.5); }
|
| 191 |
+
.var3-color { background-color: rgba(233, 30, 99, 0.5); }
|
| 192 |
+
|
| 193 |
+
ul {
|
| 194 |
+
padding-left: 20px;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
li {
|
| 198 |
+
margin-bottom: 12px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.what-to-find {
|
| 202 |
+
margin-top: 20px;
|
| 203 |
+
padding: 15px;
|
| 204 |
+
background-color: #e8f4fd;
|
| 205 |
+
border-radius: 6px;
|
| 206 |
+
border-left: 4px solid #3498db;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.what-to-find h4 {
|
| 210 |
+
color: #2c3e50;
|
| 211 |
+
margin-bottom: 8px;
|
| 212 |
+
}
|
| 213 |
+
.wrong-step {
|
| 214 |
+
display: none;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
</style>
|
| 218 |
+
</head>
|
| 219 |
+
<body>
|
| 220 |
+
<div class="wrong-step">0</div>
|
| 221 |
+
<div class="container">
|
| 222 |
+
<div class="left-panel">
|
| 223 |
+
<div class="problem-statement">
|
| 224 |
+
<div class="section-title">Problem Statement</div>
|
| 225 |
+
<p>
|
| 226 |
+
Steve is building a bench for the playground and needs <span id="fact1" class="fact1-color">6 lengths of wood that measure 4 feet</span> and <span id="fact2" class="fact2-color">2 lengths of wood that measure 2 feet</span>. How many feet of wood does Steve need to buy?
|
| 227 |
+
</p>
|
| 228 |
+
</div>
|
| 229 |
+
<div class="problem-understanding">
|
| 230 |
+
<div class="section-title">Problem Summary</div>
|
| 231 |
+
<ul>
|
| 232 |
+
<li><span class="fact1-color">Number of 4-foot wood lengths: 6</span></li>
|
| 233 |
+
<li><span class="fact1-color">Length of each piece: 4 feet</span></li>
|
| 234 |
+
<li><span class="fact2-color">Number of 2-foot wood lengths: 2</span></li>
|
| 235 |
+
<li><span class="fact2-color">Length of each piece: 2 feet</span></li>
|
| 236 |
+
</ul>
|
| 237 |
+
<div class="what-to-find">
|
| 238 |
+
<h4>What we need to find</h4>
|
| 239 |
+
<p>How many total feet of wood Steve needs to buy.</p>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
</div>
|
| 243 |
+
<div class="right-panel">
|
| 244 |
+
<div class="debugger-controls">
|
| 245 |
+
<button id="playPauseBtn" class="btn btn-play-pause">▶ Play</button>
|
| 246 |
+
<button id="stopBtn" class="btn btn-stop">■ Stop</button>
|
| 247 |
+
<button id="prevBtn" class="btn btn-prev">⤴ Previous Step</button>
|
| 248 |
+
<button id="nextBtn" class="btn btn-next">⤵ Next Step</button>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="python-solution">
|
| 251 |
+
<div class="section-title" style="color: #333333; padding: 15px 15px 0; margin: 0;">Python Solution</div>
|
| 252 |
+
<div class="python-code" id="python-code">
|
| 253 |
+
<div class="code-line" data-step="0">
|
| 254 |
+
<span class="line-number">1</span>
|
| 255 |
+
<span class="comment"># Calculate the total length of 4-foot wood pieces</span>
|
| 256 |
+
</div>
|
| 257 |
+
<div class="code-line" data-step="1">
|
| 258 |
+
<span class="line-number">2</span>
|
| 259 |
+
<span><span class="var1-color">four_foot_wood</span> = <span class="fact1-color">6</span> * <span class="fact1-color">4</span></span>
|
| 260 |
+
</div>
|
| 261 |
+
<div class="code-line" data-step="2">
|
| 262 |
+
<span class="line-number">3</span>
|
| 263 |
+
<span class="comment"># Calculate the total length of 2-foot wood pieces</span>
|
| 264 |
+
</div>
|
| 265 |
+
<div class="code-line" data-step="3">
|
| 266 |
+
<span class="line-number">4</span>
|
| 267 |
+
<span><span class="var2-color">two_foot_wood</span> = <span class="fact2-color">2</span> * <span class="fact2-color">2</span></span>
|
| 268 |
+
</div>
|
| 269 |
+
<div class="code-line" data-step="4">
|
| 270 |
+
<span class="line-number">5</span>
|
| 271 |
+
<span class="comment"># Calculate the total length of wood needed</span>
|
| 272 |
+
</div>
|
| 273 |
+
<div class="code-line" data-step="5">
|
| 274 |
+
<span class="line-number">6</span>
|
| 275 |
+
<span><span class="var3-color">total_wood</span> = <span class="var1-color">four_foot_wood</span> + <span class="var2-color">two_foot_wood</span></span>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="variables-display" id="variables-display">
|
| 280 |
+
<div class="section-title" style="margin-bottom: 15px;">Variables</div>
|
| 281 |
+
<div id="variables-list">
|
| 282 |
+
<div class="variable-item">
|
| 283 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 284 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
|
| 291 |
+
<script>
|
| 292 |
+
class PythonDebugger {
|
| 293 |
+
constructor() {
|
| 294 |
+
this.currentStep = -1;
|
| 295 |
+
this.isPlaying = false;
|
| 296 |
+
this.playInterval = null;
|
| 297 |
+
this.totalSteps = 5;
|
| 298 |
+
this.variables = {};
|
| 299 |
+
|
| 300 |
+
this.initializeElements();
|
| 301 |
+
this.bindEvents();
|
| 302 |
+
this.updateUI();
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
initializeElements() {
|
| 306 |
+
this.playPauseBtn = document.getElementById('playPauseBtn');
|
| 307 |
+
this.stopBtn = document.getElementById('stopBtn');
|
| 308 |
+
this.prevBtn = document.getElementById('prevBtn');
|
| 309 |
+
this.nextBtn = document.getElementById('nextBtn');
|
| 310 |
+
this.codeLines = document.querySelectorAll('.code-line');
|
| 311 |
+
this.variablesDisplay = document.getElementById('variables-list');
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
bindEvents() {
|
| 315 |
+
this.playPauseBtn.addEventListener('click', () => this.togglePlay());
|
| 316 |
+
this.stopBtn.addEventListener('click', () => this.stop());
|
| 317 |
+
this.prevBtn.addEventListener('click', () => this.previousStep());
|
| 318 |
+
this.nextBtn.addEventListener('click', () => this.nextStep());
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
togglePlay() {
|
| 322 |
+
if (this.isPlaying) {
|
| 323 |
+
this.pause();
|
| 324 |
+
} else {
|
| 325 |
+
this.play();
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
play() {
|
| 330 |
+
this.isPlaying = true;
|
| 331 |
+
this.playPauseBtn.innerHTML = '❚❚ Pause';
|
| 332 |
+
|
| 333 |
+
if (this.currentStep >= this.totalSteps) {
|
| 334 |
+
this.currentStep = -1;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
this.playInterval = setInterval(() => {
|
| 338 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 339 |
+
if (nextStep !== null) {
|
| 340 |
+
this.currentStep = nextStep;
|
| 341 |
+
this.executeStep(this.currentStep);
|
| 342 |
+
this.updateUI();
|
| 343 |
+
} else {
|
| 344 |
+
this.pause();
|
| 345 |
+
}
|
| 346 |
+
}, 1500);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
pause() {
|
| 350 |
+
this.isPlaying = false;
|
| 351 |
+
this.playPauseBtn.innerHTML = '▶ Play';
|
| 352 |
+
if (this.playInterval) {
|
| 353 |
+
clearInterval(this.playInterval);
|
| 354 |
+
this.playInterval = null;
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
stop() {
|
| 359 |
+
this.pause();
|
| 360 |
+
this.currentStep = -1;
|
| 361 |
+
this.variables = {};
|
| 362 |
+
this.updateUI();
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
nextStep() {
|
| 366 |
+
const nextStep = this.getNextExecutableStep(this.currentStep);
|
| 367 |
+
if (nextStep !== null) {
|
| 368 |
+
this.currentStep = nextStep;
|
| 369 |
+
this.executeStep(this.currentStep);
|
| 370 |
+
this.updateUI();
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
previousStep() {
|
| 375 |
+
const prevStep = this.getPreviousExecutableStep(this.currentStep);
|
| 376 |
+
if (prevStep !== null) {
|
| 377 |
+
this.currentStep = prevStep;
|
| 378 |
+
this.recalculateVariables();
|
| 379 |
+
this.updateUI();
|
| 380 |
+
} else if (this.currentStep !== -1) {
|
| 381 |
+
this.currentStep = -1;
|
| 382 |
+
this.variables = {};
|
| 383 |
+
this.updateUI();
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
executeStep(step) {
|
| 388 |
+
switch(step) {
|
| 389 |
+
case 1:
|
| 390 |
+
this.variables.four_foot_wood = 6 * 4;
|
| 391 |
+
break;
|
| 392 |
+
case 3:
|
| 393 |
+
// This is the wrong step as indicated in the unformatted information
|
| 394 |
+
this.variables.two_foot_wood = 2 * 2;
|
| 395 |
+
break;
|
| 396 |
+
case 5:
|
| 397 |
+
this.variables.total_wood = this.variables.four_foot_wood + this.variables.two_foot_wood;
|
| 398 |
+
break;
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
getExecutableSteps() {
|
| 403 |
+
// Returns only the steps that execute actual code (not comments)
|
| 404 |
+
return [1, 3, 5];
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
getNextExecutableStep(currentStep) {
|
| 408 |
+
const executableSteps = this.getExecutableSteps();
|
| 409 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 410 |
+
return currentIndex < executableSteps.length - 1 ? executableSteps[currentIndex + 1] : null;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
getPreviousExecutableStep(currentStep) {
|
| 414 |
+
const executableSteps = this.getExecutableSteps();
|
| 415 |
+
const currentIndex = executableSteps.indexOf(currentStep);
|
| 416 |
+
return currentIndex > 0 ? executableSteps[currentIndex - 1] : null;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
recalculateVariables() {
|
| 420 |
+
this.variables = {};
|
| 421 |
+
const executableSteps = this.getExecutableSteps();
|
| 422 |
+
for (let step of executableSteps) {
|
| 423 |
+
if (step <= this.currentStep) {
|
| 424 |
+
this.executeStep(step);
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
updateUI() {
|
| 430 |
+
// Update code highlighting
|
| 431 |
+
this.codeLines.forEach((line, index) => {
|
| 432 |
+
line.classList.toggle('current', index === this.currentStep);
|
| 433 |
+
});
|
| 434 |
+
|
| 435 |
+
// Update button states
|
| 436 |
+
const executableSteps = this.getExecutableSteps();
|
| 437 |
+
const isFirstStep = this.currentStep === -1;
|
| 438 |
+
const isLastStep = this.currentStep === executableSteps[executableSteps.length - 1];
|
| 439 |
+
|
| 440 |
+
this.prevBtn.classList.toggle('disabled', this.currentStep === -1);
|
| 441 |
+
this.nextBtn.classList.toggle('disabled', isLastStep);
|
| 442 |
+
|
| 443 |
+
// Update variables display
|
| 444 |
+
this.updateVariablesDisplay();
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
updateVariablesDisplay() {
|
| 448 |
+
if (Object.keys(this.variables).length === 0) {
|
| 449 |
+
this.variablesDisplay.innerHTML = `
|
| 450 |
+
<div class="variable-item">
|
| 451 |
+
<span class="variable-name">No variables initialized yet</span>
|
| 452 |
+
<span class="variable-value">Run the code to see variables</span>
|
| 453 |
+
</div>
|
| 454 |
+
`;
|
| 455 |
+
return;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
let html = '';
|
| 459 |
+
const variableOrder = ['four_foot_wood', 'two_foot_wood', 'total_wood'];
|
| 460 |
+
|
| 461 |
+
variableOrder.forEach(varName => {
|
| 462 |
+
if (this.variables.hasOwnProperty(varName)) {
|
| 463 |
+
const value = this.variables[varName];
|
| 464 |
+
const colorClass = this.getVariableColorClass(varName);
|
| 465 |
+
const displayValue = `${value} feet`;
|
| 466 |
+
|
| 467 |
+
const lastVarName = variableOrder[variableOrder.length - 1];
|
| 468 |
+
if(varName === lastVarName){
|
| 469 |
+
varName = varName + " (Final Answer)";
|
| 470 |
+
html += `<div class="variable-item ${colorClass}">
|
| 471 |
+
<span class="variable-name">${varName}</span>
|
| 472 |
+
<span class="variable-value">${value}</span>
|
| 473 |
+
</div>`;
|
| 474 |
+
} else {
|
| 475 |
+
html += `<div class="variable-item ${colorClass}">
|
| 476 |
+
<span class="variable-name">${varName}</span>
|
| 477 |
+
<span class="variable-value">${value}</span>
|
| 478 |
+
</div>`;
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
});
|
| 482 |
+
|
| 483 |
+
this.variablesDisplay.innerHTML = html;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
getVariableColorClass(varName) {
|
| 487 |
+
const colorMap = {
|
| 488 |
+
'four_foot_wood': 'var1-color',
|
| 489 |
+
'two_foot_wood': 'var2-color',
|
| 490 |
+
'total_wood': 'var3-color'
|
| 491 |
+
};
|
| 492 |
+
return colorMap[varName] || '';
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
// Initialize the debugger when the page loads
|
| 497 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 498 |
+
new PythonDebugger();
|
| 499 |
+
});
|
| 500 |
+
</script>
|
| 501 |
+
</body>
|
| 502 |
+
</html>
|