BASIC User Group > Code Challenges

Array Sort

(1/3) > >>

John:
We haven't had a code challenge in a while so I thought I would suggest an Array Sort challenge in your language of choice.

I gave this a try in native ScriptBasic but I would love to extend the T module with it done in C. The speed of SPLITA gives me hope array access at the C level would be much faster.

ScriptBasic Initial Submission

AIR:

--- Code: Go ---package main import (    "fmt"    "sort"    "strings") func main() {    s := strings.Split("pear,cranberry,orange,apple,carrot,banana,grape", ",")    sort.Strings(s)    fmt.Println(strings.Join(s, "\n"))}
[riveraa@mini ~/Projects/go/sort] $ time ./sort
apple
banana
carrot
cranberry
grape
orange
pear

real    0m0.006s
user    0m0.002s
sys    0m0.002s

John:
Nice to see GO has native array sort. I was hoping for something in C I could use in an extension module.

Based on your fast PC compared to my PoS PC, SB seems faster than GO. Try the bible line sort in GO.

AIR:
This was done on my Mac Mini:

      Model Name: Mac mini
      Model Identifier: Macmini6,2
      Processor Name: Intel Core i7
      Processor Speed: 2.3 GHz
      Number of Processors: 1
      Total Number of Cores: 4

John:
That's twice as fast as my PC running at 1.3 ghz 4 cores.

Navigation

[0] Message Index

[#] Next page

Go to full version