The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/list.nut@3:7268a3ceaffc, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 11:39:42 2014 +0000
- Revision:
- 3:7268a3ceaffc
- Parent:
- 0:97a4f8cc534c
Accepts \r as line terminator as well.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | /*translation of the list test from The Great Computer Language Shootout |
jhnwkmn | 0:97a4f8cc534c | 2 | */ |
jhnwkmn | 0:97a4f8cc534c | 3 | |
jhnwkmn | 0:97a4f8cc534c | 4 | function compare_arr(a1,a2) |
jhnwkmn | 0:97a4f8cc534c | 5 | { |
jhnwkmn | 0:97a4f8cc534c | 6 | foreach(i,val in a1) |
jhnwkmn | 0:97a4f8cc534c | 7 | if(val!=a2[i])return null; |
jhnwkmn | 0:97a4f8cc534c | 8 | return 1; |
jhnwkmn | 0:97a4f8cc534c | 9 | } |
jhnwkmn | 0:97a4f8cc534c | 10 | |
jhnwkmn | 0:97a4f8cc534c | 11 | function test() |
jhnwkmn | 0:97a4f8cc534c | 12 | { |
jhnwkmn | 0:97a4f8cc534c | 13 | local size=10000 |
jhnwkmn | 0:97a4f8cc534c | 14 | local l1=[]; l1.resize(size); |
jhnwkmn | 0:97a4f8cc534c | 15 | for(local i=0;i<size;i+=1) l1[i]=i; |
jhnwkmn | 0:97a4f8cc534c | 16 | local l2=clone l1; |
jhnwkmn | 0:97a4f8cc534c | 17 | local l3=[] |
jhnwkmn | 0:97a4f8cc534c | 18 | |
jhnwkmn | 0:97a4f8cc534c | 19 | l2.reverse(); |
jhnwkmn | 0:97a4f8cc534c | 20 | while(l2.len()>0) |
jhnwkmn | 0:97a4f8cc534c | 21 | l3.append(l2.pop()); |
jhnwkmn | 0:97a4f8cc534c | 22 | while(l3.len()>0) |
jhnwkmn | 0:97a4f8cc534c | 23 | l2.append(l3.pop()); |
jhnwkmn | 0:97a4f8cc534c | 24 | l1.reverse(); |
jhnwkmn | 0:97a4f8cc534c | 25 | |
jhnwkmn | 0:97a4f8cc534c | 26 | if(compare_arr(l1,l2)) |
jhnwkmn | 0:97a4f8cc534c | 27 | return l1.len(); |
jhnwkmn | 0:97a4f8cc534c | 28 | return null; |
jhnwkmn | 0:97a4f8cc534c | 29 | } |
jhnwkmn | 0:97a4f8cc534c | 30 | |
jhnwkmn | 0:97a4f8cc534c | 31 | local n = vargv.len()!=0?vargv[0].tointeger():1 |
jhnwkmn | 0:97a4f8cc534c | 32 | for(local i=0;i<n;i+=1) |
jhnwkmn | 0:97a4f8cc534c | 33 | if(!test()) |
jhnwkmn | 0:97a4f8cc534c | 34 | { |
jhnwkmn | 0:97a4f8cc534c | 35 | print("failed"); |
jhnwkmn | 0:97a4f8cc534c | 36 | return; |
jhnwkmn | 0:97a4f8cc534c | 37 | } |
jhnwkmn | 0:97a4f8cc534c | 38 | |
jhnwkmn | 0:97a4f8cc534c | 39 | print("oki doki"); |
jhnwkmn | 0:97a4f8cc534c | 40 |