Order two numerical lists: Difference between revisions

Undo revision 127060 by Spoon! (talk)
(it seems that the task describes <=, not <)
(Undo revision 127060 by Spoon! (talk))
Line 28:
b.push_back(0);
 
std::cout << std::boolalpha << (a <= b) << std::endl; // prints "false"
return 0;
}</lang>
Line 42:
If your numbers happen to be in the range 0 to 255, this works:
<lang go>func less(a, b []byte) bool {
return string(a) <= string(b)
}</lang>
Otherwise, the following code is equivalent and can be easily changed to support lists of other numeric types.
Line 60:
=={{header|Haskell}}==
The built-in comparison operators already do this:
<lang haskell>Prelude> [1,2,1,3,2] <= [1,2,0,4,4,0,0,0]
False</lang>
 
Line 120:
 
The built-in comparison operators already do this:
<lang ocaml># [1;2;1;3;2] <= [1;2;0;4;4;0;0;0];;
- : bool = false</lang>
 
Line 183:
=={{header|Python}}==
The built-in comparison operators already do this:
<lang python>>>> [1,2,1,3,2] <= [1,2,0,4,4,0,0,0]
False</lang>
 
=={{header|Ruby}}==
The built-in <code><=></code> operator already does this:
<lang ruby>>> ([1,2,1,3,2] <=> [1,2,0,4,4,0,0,0]) <= 0
=> false</lang>
 
=={{header|Standard ML}}==
<lang sml>- List.collate Int.compare ([1,2,1,3,2], [1,2,0,4,4,0,0,0]) <>= GREATERLESS;
val it = false : bool</lang>
 
Anonymous user