Difference between revisions of "Sum Scan Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
=Code to Implement=
 
=Code to Implement=
  
{{SMLToImplement|sum_scan|sum_scan|warmup_sum_scan}}
+
{{SMLToImplement|sum_scan_fun|sum_scan|warmup_sum_scan_fun}}
  
 
==sum_scan==
 
==sum_scan==
Line 11: Line 11:
 
  fun sum_scan(xs : int list) : int list
 
  fun sum_scan(xs : int list) : int list
  
which produces a list whose values are each the sum of values in <code>xs</code> up to and including the value at its location.
+
which produces a list whose values are the [https://en.wikipedia.org/wiki/Running_total running totals] of the values in <code>xs</code>.
  
 
===Example [1,2,3,4,5,6,7,8]===
 
===Example [1,2,3,4,5,6,7,8]===
Line 50: Line 50:
  
 
=Test=
 
=Test=
{{SMLUnitTest|sum_scan|warmup_sum_scan}}
+
{{SMLUnitTesting|run_sum_scan_fun_testing|warmup_sum_scan_fun}}

Latest revision as of 21:06, 7 September 2022

Background

Prefix sum on Wikipedia

Code to Implement

file: src/main/sml/warmup_sum_scan_fun/sum_scan_fun.sml Smlnj-logo.png
functions: sum_scan

sum_scan

Write a function

fun sum_scan(xs : int list) : int list

which produces a list whose values are the running totals of the values in xs.

Example [1,2,3,4,5,6,7,8]

For example:

sum_scan([1,2,3,4,5,6,7,8])

would produce:

[1,3,6,10,15,21,28,36]
xs 1 2 3 4 5 6 7 8
sum_scan(xs) 1 3 6 10 15 21 28 36

Example [131,231,425]

For example:

sum_scan([131,231,425])

would produce:

[131, 362, 787]
xs 131 231 425
sum_scan(xs) 131 362 787

Test

source folder: src/test/sml/warmup_sum_scan_fun
how to run with CM.make verbosity off: sml -Ccm.verbose=false run_sum_scan_fun_testing.sml
how to run with CM.make verbosity on: sml run_sum_scan_fun_testing.sml

note: ensure that you have removed all printing to receive credit for any assignment.

SML Error Messages