Difference between revisions of "Sum Distances To Origin With Functions Assignment"
Jump to navigation
Jump to search
| Line 19: | Line 19: | ||
fun sum_distances_to_origin(xys : (real * real) list) | fun sum_distances_to_origin(xys : (real * real) list) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | For example, if the list is <code>[(3,4), (5,12)]</code> then calling <code>sum_distances_to_origin</code> with that list would evaluate to <code>18</code> (since 5 + 13 is 18). | ||
=Test= | =Test= | ||
{{SMLUnitTesting|run_sum_distances_to_origin_fun_testing|sum_distances_to_origin_fun}} | {{SMLUnitTesting|run_sum_distances_to_origin_fun_testing|sum_distances_to_origin_fun}} | ||
Revision as of 22:16, 26 August 2024
Background
The distance of a point (x,y) from the origin:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle distance = \sqrt {x^2 + y^2}}
Basis Library
Code To Implement
sum_distances_to_origin
| file: | src/main/sml/sum_distances_to_origin_fun/sum_distances_to_origin.sml | |
| functions: | sum_distances_to_origin |
A list of tuples xys is passed to sum_distances_to_origin. Evaluate to the sum of the distances from each point (x,y) in the list to the origin.
fun sum_distances_to_origin(xys : (real * real) list)
For example, if the list is [(3,4), (5,12)] then calling sum_distances_to_origin with that list would evaluate to 18 (since 5 + 13 is 18).
Test
| source folder: | src/test/sml/sum_distances_to_origin_fun |
| how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_sum_distances_to_origin_fun_testing.sml |
| how to run with CM.make verbosity on: | sml run_sum_distances_to_origin_fun_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.