LESSON 33 OF 52 · CHAPTER 04
Vector Norm
norm length and immutable normalize for a 3-4 vector
09-vector-norm.srp
// Finite-safe Euclidean norm and immutable normalization.
bind values = [3.0, 4.0];
print(norm(values));
print(normalize(values));
stdout
5.0
[0.6, 0.8]
Write what you expect this program to print. Check prediction for a line-level hint without revealing the answer, or reveal the verified output when ready. This checks displayed text only; it does not run Scarp or save your input.
UNDERSTAND THE CODE
Explanation & practice
What this example teaches
norm length and immutable normalize for a 3-4 vector
Expected behavior
5.0, then [0.6, 0.8]
Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.
वेक्टर का मानक (नॉर्म)
norm([3.0, 4.0]) यूक्लिडीय लंबाई 5.0 देता है। normalize वेक्टर की प्रत्येक संख्या को लंबाई से भाग देकर नया इकाई-वेक्टर बनाता है। पुरानी बाइंडिंग नहीं बदलती।
आउटपुट: पहले 5.0, फिर [0.6, 0.8]।
अभ्यास: 3 और 4 के वर्गों का योग लेकर नॉर्म निकालें।
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
LEARNING PROGRESS
Keep your place
Mark this lesson complete when you are ready.
Only saved in this browser. No account or tracking.
TRY IT LOCALLY
Verify, then execute
Use the pinned compiler from the course root. Keep any imported _support files next to the source.
scarp verify examples/04-collections/09-vector-norm.srp
scarp exec examples/04-collections/09-vector-norm.srpThe website does not run code. Read the CLI guide ↗
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.