Sort an integer array: Difference between revisions
→{{header|Ed}}: Expand on implementation details
(Add ed example) |
(→{{header|Ed}}: Expand on implementation details) |
||
Line 990:
Input numbers as comma/space/tab/newline separated integers.
Given that ed doesn't support numbers, this example first converts numbers to unary system and compares the lengths of the converted numbers for sorting. Sorting happens in 8 iterations, which is a totally arbitrary number, yet sufficient to sort 5 example values. Should be copy-pasted more (there are no loops in ed) for bigger samples.
<syntaxhighlight>
Line 996 ⟶ 998:
g/\b[[:space:]]*[,[:space:]][[:space:]]*\b/s//\
/g
# unary -> decimal (via Roman-ish)
g/(.*)0([0-9]{3})/s//\1\2/
g/(.*)1([0-9]{3})/s//\1m\2/
|