Difference between revisions of "Eliminate Unsorted Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with "=Code to Implement= {{SMLToImplement|eliminate_unsorted|eliminate_unsorted|warmup_eliminate_unsorted}} ==eliminate_unsorted== Write a function fun eliminate_unsorted(xs :...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=Previous Warmup=
 +
follows [[Remove_First_Assignment|Remove First]]
 +
 
=Code to Implement=
 
=Code to Implement=
  
Line 19: Line 22:
 
  [1, 6, 8, 9]
 
  [1, 6, 8, 9]
  
===Example [131,231,425]===
+
===Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]===
For example:
+
Ties are to be retained in the result.  For example:
  
  sum_scan([131,231,425])
+
  eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0])
  
 
would produce:
 
would produce:
  
  [131, 362, 787]
+
  [1, 1, 2, 3, 3, 4, 5, 5]
 
 
:{| class="wikitable" style="text-align:right;"
 
|-
 
! style="text-align:right;" | xs
 
| 131 || 231 || 425
 
|-
 
! style="text-align:right;" | sum_scan(xs)
 
| 131 || 362 || 787
 
|}
 
  
 
=Test=
 
=Test=
 
{{SMLUnitTesting|run_eliminate_unsorted_testing|warmup_eliminate_unsorted}}
 
{{SMLUnitTesting|run_eliminate_unsorted_testing|warmup_eliminate_unsorted}}

Latest revision as of 14:34, 12 September 2022

Previous Warmup

follows Remove First

Code to Implement

file: src/main/sml/warmup_eliminate_unsorted/eliminate_unsorted.sml Smlnj-logo.png
functions: eliminate_unsorted

eliminate_unsorted

Write a function

fun eliminate_unsorted(xs : int list) : int list

which produces a list of the already sorted items, eliminated any unsorted items.

Example [1, 6, 1, 8, 0, 3, 3, 9, 8, 8, 7]

For example:

eliminate_unsorted([1, 6, 1, 8, 0, 3, 3, 9, 8, 8, 7])

would produce:

[1, 6, 8, 9]

Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]

Ties are to be retained in the result. For example:

eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0])

would produce:

[1, 1, 2, 3, 3, 4, 5, 5]

Test

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

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

SML Error Messages