Sort a list of object identifiers: Difference between revisions

m
syntax highlighting fixup automation
(Added solution for Action!)
m (syntax highlighting fixup automation)
Line 47:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V data = [
‘1.3.6.1.4.1.11.2.17.19.3.4.0.10’,
‘1.3.6.1.4.1.11.2.17.5.2.0.79’,
Line 59:
 
L(s) sorted(data, key' x -> x.split(:delim).map(Int))
print(s)</langsyntaxhighlight>
 
{{out}}
Line 72:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">DEFINE PTR="CARD"
 
PROC PrintArray(PTR ARRAY a INT size)
Line 168:
PrintE("Array after sort:")
PrintArray(a,SIZE)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sort_a_list_of_object_identifiers.png Screenshot from Atari 8-bit computer]
Line 193:
{{works with|Ada|Ada|2012}}
 
<langsyntaxhighlight Adalang="ada">with Ada.Containers.Generic_Array_Sort;
with Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 243:
Ada.Text_IO.Put_Line(To_String(element));
end loop;
end Sort_List_Identifiers;</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 256:
===Vanilla===
Place the call to the sort handler in a <tt>considering numeric strings</tt> statement.
<langsyntaxhighlight lang="applescript">(* Shell sort
Algorithm: Donald Shell, 1959.
*)
Line 302:
sort(theList, 1, -1)
end considering
return theList</langsyntaxhighlight>
 
{{output}}
Line 309:
===ASObjC===
Use the <tt>localizedStandardCompare:</tt> string comparison method.
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
 
Line 319:
ascending:(true) selector:("localizedStandardCompare:")
tell theArray to sortUsingDescriptors:({theDescriptor})
return theArray as list</langsyntaxhighlight>
 
{{output}}
Line 328:
As a composition of pure functions:
 
<langsyntaxhighlight lang="applescript">------------- SORTED LIST OF OBJECT IDENTIFIERS ------------
 
-- sortedIdentifiers :: [String] -> [String]
Line 686:
end tell
end if
end zipWith</langsyntaxhighlight>
{{Out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 696:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">; based on http://www.rosettacode.org/wiki/Sorting_algorithms/Quicksort#AutoHotkey
OidQuickSort(a, Delim:=".", index:=1){
if (a.Count() <= 1)
Line 720:
Out.InsertAt(1, Less*) ; InsertAt all values of Less at index 1
return Out
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">a := ["1.3.6.1.4.1.11.2.17.19.3.4.0.10"
,"1.3.6.1.4.1.11.2.17.5.2.0.79"
,"1.3.6.1.4.1.11.2.17.19.3.4.0.4"
Line 731:
Out .= "`n" v
MsgBox % Out
return</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 742:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SORT_A_LIST_OF_OBJECT_IDENTIFIERS.AWK
#
Line 778:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 791:
=={{header|C}}==
A C99 (or later) compiler is required.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 900:
oid_destroy(oids[i]);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 913:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Collections.Generic;
Line 940:
Console.WriteLine(string.Join(Environment.NewLine, oids));
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 952:
 
=={{header|C++}}==
<langsyntaxhighlight Cpplang="cpp">#include <string>
#include <vector>
#include <algorithm>
Line 1,001:
std::cout << s << '\n' ;
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,015:
Clojure 'sort' function allows specifying an optional comparator function. In this case, our custom comparator utilizes the ability of the clojure.core 'compare' function to compare vectors in an appropriate fashion.
 
<syntaxhighlight lang="clojure">
<lang Clojure>
(defn oid-vec [oid-str]
(->> (clojure.string/split oid-str #"\.")
Line 1,040:
(sort oid-compare)
(map oid-str)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,060:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun oid->list (oid)
(loop for start = 0 then (1+ pos)
for pos = (position #\. oid :start start)
Line 1,086:
"1.3.6.1.4.1.11150.3.4.0")))
(dolist (oid (sort-oids oids))
(write-line oid))))</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,096:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Sort_by_OID do
def numbers(list) do
Enum.sort_by(list, fn oid ->
Line 1,113:
]
|> Sort_by_OID.numbers
|> Enum.each(fn oid -> IO.puts oid end)</langsyntaxhighlight>
 
{{out}}
Line 1,127:
=={{header|Factor}}==
Factor provides the <code>human<=></code> word which converts numbers in a string to integers before comparing them.
<langsyntaxhighlight lang="factor">USING: io qw sequences sorting sorting.human ;
 
qw{
Line 1,136:
1.3.6.1.4.1.11.2.17.19.3.4.0.1
1.3.6.1.4.1.11150.3.4.0
} [ human<=> ] sort [ print ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 1,156:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,227:
fmt.Println(o)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,240:
=={{header|Haskell}}==
====Data.List====
<langsyntaxhighlight Haskelllang="haskell">import Data.List ( sort , intercalate )
 
splitString :: Eq a => (a) -> [a] -> [[a]]
Line 1,264:
main :: IO ( )
main = do
mapM_ putStrLn $ orderOID oid</langsyntaxhighlight>
 
{{out}}
Line 1,278:
(To use '''split :: (Char -> Bool) -> Text -> [Text]''' in the standard libraries, we would have to temporarily convert the strings from [Char] to Text with pack and unpack)
 
<langsyntaxhighlight lang="haskell">import Data.Text (pack, split, unpack)
import Data.List (sort, intercalate)
 
Line 1,305:
, "1.3.6.1.4.1.11.2.17.19.3.4.0.1"
, "1.3.6.1.4.1.11150.3.4.0"
]</langsyntaxhighlight>
{{Out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,317:
we can alternatively write:
 
<langsyntaxhighlight lang="haskell">import Data.List.Split (splitOn)
import Data.List (sort, intercalate)
 
Line 1,326:
 
readInt :: String -> Int
readInt x = read x :: Int</langsyntaxhighlight>
 
=={{header|J}}==
Line 1,332:
Data:
 
<langsyntaxhighlight Jlang="j">oids=:<@-.&' ';._2]0 :0
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,339:
1.3.6.1.4.1.11.2.17.19.3.4.0.1
1.3.6.1.4.1.11150.3.4.0
)</langsyntaxhighlight>
 
In other words, for each line in that script, remove the spaces and put the rest in a box.
Line 1,345:
Sorting:
 
<langsyntaxhighlight Jlang="j"> >(/: __&".;._1&.('.'&,)&>) oids
1.3.6.1.4.1.11.2.17.5.2.0.79
1.3.6.1.4.1.11.2.17.19.3.4.0.1
Line 1,351:
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11150.3.4.0
1.3.6.1.4.1.11150.3.4.0.1 </langsyntaxhighlight>
 
In other words, for our sort key, we break the contents of each box by an initial '.' and treat the remainder as numbers.
Line 1,360:
{{works with|Java|8 or higher}}
 
<langsyntaxhighlight lang="java">
package com.rosettacode;
 
Line 1,393:
.forEach(System.out::println);
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,404:
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq">def data: [
"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
Line 1,413:
];
 
data | map( split(".") | map(tonumber) ) | sort | map(join("."))</langsyntaxhighlight>
 
{{out}}
Line 1,428:
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">oidlist = ["1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
"1.3.6.1.4.1.11.2.17.19.3.4.0.4",
Line 1,437:
sort!(oidlist; lt=lexless,
by=x -> parse.(Int, String.(split(x, "."))))
println.(oidlist)</langsyntaxhighlight>
 
{{out}}
Line 1,448:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
class Oid(val id: String): Comparable<Oid> {
Line 1,475:
)
println(oids.sorted().joinToString("\n"))
}</langsyntaxhighlight>
 
{{out}}
Line 1,489:
=={{header|Lua}}==
Using the in-built table.sort with a custom compare function.
<langsyntaxhighlight Lualang="lua">local OIDs = {
"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
Line 1,509:
table.sort(OIDs, compare)
for _, oid in pairs(OIDs) do print(oid) end</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,518:
1.3.6.1.4.1.11150.3.4.0.1</pre>
===Using Coroutine===
<langsyntaxhighlight lang="lua">
local function oidGen(s)
local wrap, yield = coroutine.wrap, coroutine.yield
Line 1,547:
table.sort(OIDs, oidCmp)
for _, oid in pairs(OIDs) do print(oid) end
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
In this example we have to change dot to #, to make each number as an integer one.
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Flush ' empty stack of values
Line 1,574:
}
Checkit
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,594:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
GT=lambda (a$, b$)->{
def i
Line 1,628:
}
}
</syntaxhighlight>
</lang>
 
Using a function which split pieces one time. We have to insert one more item, by append a "." to a$ and b$
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
GT=lambda (a$, b$)->{
def i=-1
Line 1,644:
=val(a$(i))>val(b$(i))
}
</syntaxhighlight>
</lang>
 
===Using QuickSort===
Line 1,657:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Group Quick {
Private:
Line 1,720:
Print join$(arr(i))
}
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">in = {"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79", "1.3.6.1.4.1.11.2.17.19.3.4.0.4",
"1.3.6.1.4.1.11150.3.4.0.1", "1.3.6.1.4.1.11.2.17.19.3.4.0.1",
Line 1,729:
in = StringSplit[#, "."] & /@ in;
in = Map[ToExpression, in, {2}];
Column[StringRiffle[ToString /@ #, "."] & /@ LexicographicSort[in]]</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,741:
=== OID as distinct string ===
Nim allows to define distinct types. As OID are peculiar strings, defining them as distinct strings seems a good idea. We have to define a specific comparison procedure and that’s all. Here is the code:
<langsyntaxhighlight Nimlang="nim">import algorithm, sequtils, strutils
 
type OID = distinct string
Line 1,775:
 
for oid in OIDS.sorted(oidCmp):
echo oid</langsyntaxhighlight>
 
Note that as the type is distinct, we have to borrow the procedure `$` to the string type in order to print OID values.
Line 1,793:
To avoid this, we can define OID as a composite object type containing a string value and a list of integers to use for the comparisons. The code is not really more complicated, only arguably less elegant as we have to create the OIDs using the procedure “initOID”.
 
<langsyntaxhighlight Nimlang="nim">import algorithm, sequtils, strutils
 
type OID = object
Line 1,824:
 
for oid in OIDS.sorted(oidCmp):
echo oid</langsyntaxhighlight>
 
{{out}}
Line 1,831:
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">my @OIDs = qw(
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,846:
@OIDs;
 
print "$_\n" for @sorted;</langsyntaxhighlight>
 
{{out}}
Line 1,860:
Alternately, you can sort them as "version strings", which is a Perl syntax allowing you to specify a character string in the source code with the characters' codes specified as a dot-delimited sequence of integers.
 
<langsyntaxhighlight lang="perl">my @sorted =
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, eval "v$_"] }
@OIDs;</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
This is a variation on a standard tagsort, but performed a bit more explicitly.
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">strings</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"1.3.6.1.4.1.11.2.17.19.3.4.0.10"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"1.3.6.1.4.1.11.2.17.5.2.0.79"</span><span style="color: #0000FF;">,</span>
Line 1,891:
<span style="color: #0000FF;">?</span><span style="color: #000000;">strings</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sortable</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,904:
===alternative===
This is very similar to the above, but without using any tags/indexes at all.
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">strings</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"1.3.6.1.4.1.11.2.17.19.3.4.0.10"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"1.3.6.1.4.1.11.2.17.5.2.0.79"</span><span style="color: #0000FF;">,</span>
Line 1,918:
<span style="color: #000080;font-style:italic;">-- sort on sortable, then use vslice to extract the originals:</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">vslice</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">strings</span><span style="color: #0000FF;">,</span><span style="color: #000000;">each</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,930:
 
=={{header|Phixmonti}}==
<langsyntaxhighlight Phixmontilang="phixmonti">include ..\Utilitys.pmt
 
( "1.3.6.1.4.1.11.2.17.19.3.4.0.10"
Line 1,963:
 
len for get print nl endfor
</syntaxhighlight>
</lang>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for I
(by
'((L) (mapcar format (split (chop L) ".")))
Line 1,977:
"1.3.6.1.4.1.11.2.17.19.3.4.0.1"
"1.3.6.1.4.1.11150.3.4.0" ) )
(prinl I) )</langsyntaxhighlight>
{{out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
Line 1,988:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">main:-
sort_oid_list(["1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
Line 2,013:
number_strings([Number|Numbers], [String|Strings]):-
number_string(Number, String),
number_strings(Numbers, Strings).</langsyntaxhighlight>
 
{{out}}
Line 2,028:
 
We need to split the input and map each part to int otherwise elements gets compared as a string
<syntaxhighlight lang="python">
<lang Python>
data = [
'1.3.6.1.4.1.11.2.17.19.3.4.0.10',
Line 2,040:
for s in sorted(data, key=lambda x: list(map(int, x.split('.')))):
print(s)
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
(require data/order)
 
Line 2,070:
"1.3.6.1.4.1.11.2.17.19.3.4.0.10"
"1.3.6.1.4.1.11150.3.4.0"
"1.3.6.1.4.1.11150.3.4.0.1")))</langsyntaxhighlight>
Tests run with no output, indicating success.
 
Line 2,078:
The <tt>sort</tt> routine accepts a sort key callback as the first argument. Here we generate a list of integers as the sort key for each OID, which gets sorted lexicographically with numeric comparison by default.
 
<syntaxhighlight lang="raku" perl6line>.say for sort *.comb(/\d+/)».Int, <
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11.2.17.5.2.0.79
Line 2,085:
1.3.6.1.4.1.11.2.17.19.3.4.0.1
1.3.6.1.4.1.11150.3.4.0
>;</langsyntaxhighlight>
 
{{out}}
Line 2,099:
Alternatively, using the <tt>sprintf</tt>-based approach used by the Perl solution, for comparison ''(input elided)'':
 
<syntaxhighlight lang="raku" perl6line>.say for sort *.split('.').fmt('%08d'), <...>;</langsyntaxhighlight>
 
Or if using a third-party module is acceptable:
 
<syntaxhighlight lang="raku" perl6line>use Sort::Naturally;
 
.say for sort &naturally, <...>;</langsyntaxhighlight>
 
=={{header|REXX}}==
This REXX version supports negative integers in the OID.
<langsyntaxhighlight lang="rexx">/*REXX program performs a sort of OID (Object IDentifiers ◄── used in Network data).*/
call gen /*generate an array (@.) from the OIDs.*/
call show 'before sort ───► ' /*display the @ array before sorting.*/
Line 2,147:
return /*── ─ ─ */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do a=1 for #; say right("OID number",20) right(a,length(#)) arg(1) @.a; end; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the (internal) default input:}}
<pre>
Line 2,167:
=={{header|Ring}}==
 
<syntaxhighlight lang="ring">
<lang Ring>
 
/*
Line 2,276:
###-----------------------------------------------------------
 
>;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,291:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">%w[
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11.2.17.5.2.0.79
Line 2,300:
]
.sort_by{|oid| oid.split(".").map(&:to_i)}
.each{|oid| puts oid}</langsyntaxhighlight>
 
{{out}}
Line 2,312:
</pre>
Or, using the Gem module (which knows about versions):
<langsyntaxhighlight lang="ruby">puts %w[
1.3.6.1.4.1.11.2.17.19.3.4.0.10
1.3.6.1.4.1.11.2.17.5.2.0.79
Line 2,319:
1.3.6.1.4.1.11.2.17.19.3.4.0.1
1.3.6.1.4.1.11150.3.4.0
].sort_by{|oid| Gem::Version.new(oid) }</langsyntaxhighlight>
with identical output.
 
=={{header|Rust}}==
<langsyntaxhighlight Rustlang="rust">fn split(s: &str) -> impl Iterator<Item = u64> + '_ {
s.split('.').map(|x| x.parse().unwrap())
}
Line 2,340:
println!("{:#?}", oids);
}</langsyntaxhighlight>
{{out}}
<pre>[
Line 2,352:
 
=={{header|Sather}}==
<langsyntaxhighlight lang="sather">class MAIN is
oid_lt (a, b: STR): BOOL is
as ::= a.cursor.split('.');
Line 2,381:
loop #OUT+sorted.elt! + "\n"; end;
end;
end;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,401:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func sort_OIDs(ids) {
ids.sort_by { |id|
id.split('.').map { Num(_) }
Line 2,416:
)
 
sort_OIDs(OIDs).each { .say }</langsyntaxhighlight>
{{out}}
<pre>
Line 2,429:
=={{header|Swift}}==
 
<langsyntaxhighlight lang="swift">import Foundation
 
public struct OID {
Line 2,478:
for id in ids.sorted() {
print(id)
}</langsyntaxhighlight>
 
{{out}}
Line 2,490:
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">
<lang Tcl>
# Example input data:
set oid_list [list \
Line 2,543:
puts [join $oid_list "."]
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,557:
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">' Sort a list of object identifiers - VBScript
function myCompare(x,y)
dim i,b
Line 2,597:
"1.3.6.1.4.1.11150.3.4.0")
bubbleSort a
wscript.echo join(a,vbCrlf) </langsyntaxhighlight>
{{out}}
<pre>
Line 2,611:
{{libheader|Wren-fmt}}
{{libheader|Wren-sort}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Fmt
import "/sort" for Sort
 
Line 2,626:
Sort.quick(oids)
oids = oids.map { |oid| oid.replace(" ", "") }.toList
System.print(oids.join("\n"))</langsyntaxhighlight>
 
{{out}}
Line 2,642:
 
Basically, blow apart each line into a list of numbers and sort that.
<langsyntaxhighlight lang="zkl">fcn sortOIDS(oids){ // oids is not modified, a new list is created
// pad each oid with a terminal (-1) so zip won't short cut
oids=oids.pump(List(),fcn(oid){ (oid + ".-1").split(".").apply("toInt") });
Line 2,653:
});
oids.pump(List,fcn(list){ list[0,-1].concat(".") }) // back to strings
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">oids:=List(
"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
Line 2,662:
"1.3.6.1.4.1.11150.3.4.0");
oids=sortOIDS(oids);
oids.pump(Console.println); // print one OID per line</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits