These are some sample programs. Though these accomplish the results but can be enhanced a lot which actually could be a good exercise for one who wants to learn more.
Taking a sample list for a few cases,
mya:[[0,1,10],[1,60,20],[0,2,5],[1,2,15]]
1. To find last element of each sublist:
map('lambda([x],last(x)),mya); => [10,20,5,15]
-------------------------------------------------map('lambda([x],last(x)),mya); => [10,20,5,15]
2. To find sublists with largest one element(say second) in each sublist:
largey([l]):=block([li],if l[1][2]>l[1][1] and
l[1][2]>l[1][3] then li:l else li:nil,return (li))$
Usage :: delete(nil,map(smallz,mya))[1]; =>[[1,60,20]]
-------------------------------------------------
3. Sorting: sortz(a,b):=b[3]>a[3];
Usage :: sort(mya,'sortz)[1]; => [0,2,5]
-------------------------------------------------
4. To find max in each sublist : maxx(x):=block([],first(sort(x,'ordergreatp)));
Usage :: map('lambda([x],maxx(x)),mya); => [10,60,5,15]
Usage :: map('lambda([x],maxx(x)),mya); => [10,60,5,15]
-------------------------------------------------
5. To find min in each sublist : minn(x):=block([],first(sort(x)));
Usage :: map('lambda([x],minn(x)),mya); => [0,1,0,1]
------------------------------------------------
6. To create a list from 1 to n : range(x):=block([],makelist(i,i,x));
6. To create a list from 1 to n : range(x):=block([],makelist(i,i,x));
Usage :: range(5) => [1,2,3,4,5]
------------------------------------------------
7. To create a functionality like Tally in mathematica, or run-length coding in simple terms,
tally(l):=block([u,s],u:unique(l),s:map(lambda([x],
count(x,l)),u),s);
count(x,l)),u),s);
count(a,l):=block([counter],counter:0,for ele in l do if(is(ele=a)) then counter:counter+1 ,counter);
Usage :: li:[1,2,3,2,1,3,5,3,2,1];
tally(li) => [3,3,3,1]
-----------------------------------------------
-----------------------------------------------
8. To find the primes present in prime factorization, primefactors(n):=block([],map(lambda([z],map(lambda([ t],first(t)),z)),[ifactors(n)]));
Usage :: primefactors(100) => [2,5]
-----------------------------------------------
9. To create functionality similar to Mathematica's
Partition[list, n]
custompartitions(x,n):=block([temp:[],f],for i:1 thru
length(x) step n do if(length(x)>= i+n-1) then
(print(temp:cons(part(x,makelist(s,s,i,i+n-
)),temp))) else nil ,return (reverse(temp)));
length(x) step n do if(length(x)>= i+n-1) then
(print(temp:cons(part(x,makelist(s,s,i,i+n-
)),temp))) else nil ,return (reverse(temp)));
Usage :: custompartitions(range(10),4); => [[1,2,3,4],[5,6,7,8]]
----------------------------------------------
10.To create functionality similar to Mathematica's
listpartition(l,n,k):=block([temp:[]], map(lambda([x],
(if(length(l)>=x+n-1)then
temp:cons(part(l,makelist(i,i,x,x+n-1)),temp)
else (temp:cons(part(l,makelist(s,s,x,length(l))),
temp)))),makelist(i,i,1,length(l),k)),reverse(temp));
(if(length(l)>=x+n-1)then
temp:cons(part(l,makelist(i,i,x,x+n-1)),temp)
else (temp:cons(part(l,makelist(s,s,x,length(l))),
temp)))),makelist(i,i,1,length(l),k)),reverse(temp));
Usage ::
listpartition([a,b,c,d,e,f,g,h,i],4,6); => [[a,b,c,d],[g,h,i]]
listpartition([a,b,c,d,e,f,g,h,i],4,3); => [[a,b,c,d],[d,e,f,g],[g,h,i]]
listpartition([a,b,c,d,e,f,g,h,i],4,6); => [[a,b,c,d],[g,h,i]]
listpartition([a,b,c,d,e,f,g,h,i],4,3); => [[a,b,c,d],[d,e,f,g],[g,h,i]]
------------------------------------------------
11. To create functionality similar to Mathematica's
constant_array ([L]) := block ([x : first (L), d :
rest (L)], apply (make_array, cons ('any, d)),
fillarray (%%, [x]));
rest (L)], apply (make_array, cons ('any, d)),
fillarray (%%, [x]));
Usage :: constant_array(2,2,8)
------------------------------------------------
12.To create functionality similar to Mathematica's
Partition[{a, b, c, d, e, f, g}, 3, 3, 1, x] => {{a,b,c},{d,e,f},{g,x,x}}
/*This will create a padded list and will work for -ive values too as partition index*/
create_listpad([l]):= block([temp:
[],f:third(l),n:first(l),k:second(l),u:rest(rest(rest(l))),w],declare(n,integer,k,integer),assume(n>0,k>0), w:constant_array(f,k),w:endcons(listarray(w),u),flatten(w));
[],f:third(l),n:first(l),k:second(l),u:rest(rest(rest(l))),w],declare(n,integer,k,integer),assume(n>0,k>0), w:constant_array(f,k),w:endcons(listarray(w),u),flatten(w));
Usage ::
create_listpad(3,2,-1,a,b,c,d,e); => [a,b,c,d,e,-1]
create_listpad(3,2,-1,a,b,c,d,e); => [a,b,c,d,e,-1]
create_listpad(-3,2,-1,a,b,c,d,e); => [a,b,c,d,e,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
listpartitionpad(l,n,k,d):= block([temp:[],gap,newl,ntemp:[]], newl:apply(create_listpad,flatten([n,k,d,l])), map(lambda([x],if(length(newl)>=x+n-1 and is(unique[x]#[d]))then temp:cons(part(newl,makelist(i,i,x,x+n-1)),temp) else temp:cons(part(newl,makelist(s,s,x,length(newl))),temp)),makelist(i,i,1,length(newl),k)),ntemp:sublist(temp,lambda([x],is(length(x)=n))),reverse(ntemp));
Usage ::
listpartitionpad([a,b,c,d,e,f,g],3,3,x); => [[a,b,c],[d,e,f],[g,x,x]]
listpartitionpad([a,b,c,d,e,f,g],3,3,x); => [[a,b,c],[d,e,f],[g,x,x]]
------------------------------------------------
13. To create number conversion, for example from integer to binary conversion,
integer_to_binary(n):=block([temp:[],bin:[]],(while(n>-1) do if(n>0) then (n:first(divide(n,2),temp:cons(n,temp))) else (temp:cons(n,temp),n:-1)),map(lambda([x],if is(evenp(x)) then bin:cons(0,bin) else bin:cons(1,bin)),rest(temp)),reverse(bin));
Usage :: integer_to_binary(10); => [1,0,1,0]
---------------------------------------------------
14. To convert list of integers to an integer ,
binarylist_to_intnum(n):=block([l:[],c:1],for i:1 thru length(n) do (l:cons(n[i]*c,l),c:c*10),apply("+",l));
Usage ::
binarylist_to_intnum(integer_to_binary(10)); => 101
binarylist_to_intnum(integer_to_binary(10)); => 101
--------------------------------------------------
15. To carry out rotations
Right rotation: right_rotation(nn):=block([n:most(nn),k:last(nn)],for i:1 thru k do (l:last(n),m:most(n),n:flatten(cons(l,[m]))),n);
Usage ::right_rotation([1,2,3,4,5,2]); => [4,5,1,2,3]
Left rotation: left_rotation(nn):=block([n:most(nn),k:last(nn)],for i:1 thru k do (f:first(n),l:rest(n),n:flatten(cons(l,[f]))),n);
Usage ::left_rotation([a,b,c,d,e,8]); => [d,e,a,b,c]
--------------------------------------------------
16. To convert array to list
array_2_list(arr):=block([r:first(last(arrayinfo(arr))),h:last(last(arrayinfo(arr)))],listpartition(listarray(arr),h+1,h+1));
Usage ::
m2:matrix([a,b,c,w,a,s,w,q],[d,e,r,1,2,3,4,5]);
Usage ::
m2:matrix([a,b,c,w,a,s,w,q],[d,e,r,1,2,3,4,5]);
array_2_list(matrix_2_array(m2));
-------------------------------------------------
17. To convert matrix to array
matrix_2_array(mm):=block([si:matrix_size(mm),li:args(mm)],lr:first(si),h:last(si),array(arr,fixnum,lr-1,h-1),fillarray(arr,flatten(li)),arr);
Usage :: matrix_2_array(mm); => arr
-------------------------------------------------
18. To convert list to matrix,
list_2_matrix(l):=block([],apply(matrix,l));
Usage :: matrix([1,2,3],[3,4,5])
--------------------------------------------------
19. To convert list to matrix with custom error,
list_2_matrix(l):=block([],if(not member(false,map(lambda([x],if(length(first(x))#length(last(x))) then false else true),listpartition(l,2,1)))) then t:apply(matrix,l) else t:Error ,t);
Usage :: list_2_matrix([[1,2,3],[3,4,5]]);
--------------------------------------------------
20. To get complement of two lists,
listcomplement(k,l):=block([],map(lambda([x],k:delete(x,k)),l),k);
Usage ::
listcomplement([1,2,3,4,5],[2,3,1,8]); => [4,5]
listcomplement([1,2,3,4,5],[2,3,1,8]); => [4,5]
To get complement in case of multiple lists in succession after first list,
listcomplementt(k,l):=block([temp:l,s:k],for i in temp do s:listcomplement(s,i),s);
listcomplementt2(k,l):=block([temp:l,s:apply(union,maplist(setify,l))],s:listcomplement(k,s),s); //using approach of union of sets, this shows that sets can some times replace lists
Usage ::
listcomplementt([4,3,2,8,9,7,0],[[1,2],[7,8]]); => [4,3,9,0]
listcomplementt([4,3,2,8,9,7,0],[[1,2],[7,8]]); => [4,3,9,0]
----------------------------------------------------
21. To get union of lists, list_union(k):=block([],listify(apply(union,maplist(setify,k))));
Usage :: list_union([[1,2,3],[3,4,5],[a,b,c,2]]); => [1,2,3,4,5,a,b,c]
---------------------------------------------------
22. To get intersection of lists,
list_intersection(k):=block([],listify(apply(intersection,maplist(setify,k))));
Usage ::
list_intersection([[1,2,3],[3,2,4,5]]); => [2,3]
list_intersection([[1,2,3],[3,2,4,5]]); => [2,3]
---------------------------------------------------
23. To get list difference similar to set difference,
list_difference(k,l):=block([],map(lambda([x],k:setdifference(setify(k),x)),maplist(setify,l)),listify(k));
Usage :: list_difference([1,2,3],[[1,2]]); => [3]
---------------------------------------------------
24. To get foldl similar to Haskel,
foldl(f,ac,li):=block([con:[],acc:ac],/*print("List=",li,ac),*/
if (is(li#[])) then (acc:apply(f,cons(acc,[first(li)])),acc:foldl(f,acc,rest(li))),acc)$
Usage :: foldl(lambda([x,y],[x,y]),S,[aa,bb,cc,dd,ee]); => [[[[[S,aa],bb],cc],dd],ee]
foldl(lambda([x,y],x^y),S,[aa,bb,cc,dd,ee]); => ((((S^aa)^bb)^cc)^dd)^ee
---------------------------------------------------
25. Subsequence similar to Haskell,
subsequence(x):=block([temp:[],count:0],(for i:1 thru length(x) do temp:cons(part(x,makelist(s,s,1,count:count+1)),temp)),reverse(temp))$
Usage ::
subsequence([1,2,3,4]); => [[1],[1,2],[1,2,3],[1,2,3,4]]
subsequence([1,2,3,4]); => [[1],[1,2],[1,2,3],[1,2,3,4]]
----------------------------------------------------
26. To get function Tuples similar to Mathematica,
tupples((l)):=block([eq:'outermap(f)],map(lambda([x],eq:endcons(x,eq)),l),eq);
Usage :: tupples(tot,[[a,b,c],[2,3]]); => outermap(tot,[a,b,c],[2,3]) on ev(%,nouns) =>[[tot(a,2),tot(a,3)],[tot(b,2),tot(b,3)],[tot(c,2),tot (c,3)]]
----------------------------------------------------
27. Iterate similar to haskell,
iterate(f,x,n):=block([temp],for i:1 thru n do x:apply(f,[x]),x)$
Usage :: iterate(sin,a,4) => sin(sin(sin(sin(a))))
float(iterate(sin,34,4)); => 0.46495283321512
----------------------------------------------------
28. Riffle similar to mathematica,
riffle(x):=block([mat:transpose(apply(matrix,x)),out:[]],for i:1 thru first(matrix_size(mat)) do (push(args(mat[i]),out)),reverse(out))$
Usage :: riffle([[a,b,c],[d,e,f],[g,h,i]]); => [[a,d,g],[b,e,h],[c,f,i]]
----------------------------------------------------
29. Similar to splitat in Haskell,
splitat(x,n):=block([temp:[]],
[part(x,makelist(i,i,1,n)), part(x,makelist(i,i,n+1,length(x)))]);
Usage :: splitat([1,2,3,4,5],3); => [[1,2,3],[4,5]]
----------------------------------------------------
30. Similar to drop in haskell,
dropat(x,n):=block([temp:[]],
part(x,makelist(i,i,n+1,length(x))));
Usage :: dropat([1,[2,3,4],5,6,7],3); => [6,7]
----------------------------------------------------
31. Similar to take in Haskell,
take(x,n):=block([temp:[]],part(x,makelist(i,i,1,n)));
Usage :: take([1,2,3,4,5,6,7],4); => [1,2,3,4]
----------------------------------------------------
32. Similar to tuples in Mathematica,
tuples(x,n):=apply(cartesian_product,create_list(setif
y(i),i,replicate(x,n)));
Usage :: tuples([1,2,3],2); => {[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]}
----------------------------------------------------
33. Similar to replicate in Haskell,
replicate(x,n):=block([temp:[]],for i:1 thru n do temp:cons(x,temp),temp);
Usage :: replicate([1,2,3],4) => [[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
----------------------------------------------------
34. Similar to takewhile in Haskell except that it will start from anywhere it finds satisfies the criteria and will also return the position along with the element, (suggested by slitvinov here).
load(basic);
takewhile(lst, pr):= block([c: []],
reverse(catch(for idx thru length(lst) do block([el: part(lst, idx)],
if not pr(el) and not emptyp(c) then throw(c)
else if pr(el) then push([el, idx], c)),
c)));
Usage :: [[4,5],[5,6],[7,7],[4,8]]
----------------------------------------------------
35. Complement similar to Mathematica,
complement(x,y):=block([],for i in y do
x:delete(i,x),x)$
Usage :: complement([1,2,3,4,5,1,3,5,8],[a,v,2,3,1]); => [4,5,5,8]
---------------------------------------------------
36. Interpreting membership at any depth in nested sublists,
member1(lis,l):=block([li:lis,p:false],load(basic),if member(l,li) then p:true else (while(not li=[])
do (li:apply(append,li),if(member(l,li)) then p:true,li:sublist(li,listp))),p)$
Usage ::
li : [[a, b, c],[2,3,4,[3,4,5,[00,99,88,[77,66,55,"+"]]]],[ff,gg,tt], [[t, y, u,[jj,kk,ll]]]] $
member1(li,[77,66,55,"+"]); => true
member1(li,[77,66,55,"+",7]); => false
----------------------------------------------------
37. Collecting information from different levels of nesting,
atlevel(lis,n):=block([li:lis,elem:[]],load(basic),for i:1 thru n do (li:apply(append,li),
push(sublist(li,lambda([x],(symbolp(x) or
integerp(x) or operatorp(x)))),elem), li:sublist(li,listp)),[reverse(elem),li])$
Usage :: atlevel(li,2) => [[[a,b,c,2,3,4,ff,gg,tt],[3,4,5,t,y,u]],[[0,99,88,[77,66,55,"+"]],[jj,kk,ll]]]
---------------------------------------------------
38. Building expression tree from postfix data, expression_tree(exp):=block([t1,t2,k,l:[], t:create_list(smake(1,x),x,charlist(exp))],print(t),
for i:1 thru length(t) do (if alphanumericp(t[i]) then print(push(t[i],l))
else (print(t[i]),if length(l)>=2 then (t1:pop(l),t2:pop(l), if(stringp(t1) and stringp(t2)) then (k:apply(t[i],
[parse_string(t2),parse_string(t1)]),print(push(k,l))) else (if stringp(t2) then t2:eval_string(t2),k:apply(t[i], [t2,t1]),print(push(k,l)))))),l[1])$
Usage :: expression_tree("wab-cde+/*^"); => [w^(((a-b)*c)/(e+d))]
-----------------------------------------------------
39. Gather similar to Mathematica(collecting similar solutions into one sublist),
listinbins(x):=block([r:[],s,y:unique(x)], for i in y do (if i#[] then (s:gather(i,x), x:delete(first(first(s)),x),push(s[1],r)) else push(last(x),r)),reverse(r))$
listseperate(x,op):=block([r:[],s,y:unique(x)], r:sublist(x,op),listinbins(r))$
gather(x,y):=block([t:[],tt:[],k,l:length(y),n],
k:sublist_indices(y,lambda([t],t=x)),for i in k do push(y[i],t),n:listcomplement(y,k),[t,n])$
Usage::
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],x^2+3*x=10));
=> [2,2]
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],(x^2)>1));
=> [[2,2],[3],[8],[9],[10],[12]]
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],symbolp(x)));
=> [[a,a],[b],[c],[e,e],[q],[s,s]]
----------------------------------------------------
40. Break a polynomial into a list of its part at topmost level,
breakPoly(ex):=block([res:[],temp:pickapart(ex,1)], for i:1 thru length(ex)
do(push(ev(part(temp,i)),res)),res)$
Usage :: expr: (a+b)/2 + sin (x^2^ee)/3 - log (1 + sqrt(x+1));
breakPoly(expr) => [(x+w)/2,-log(sqrt(x+1)+1),sin(x^2^ee)/3]
---------------------------------------------------
41. Integer digits of an integer,
integerdigits([x]):=block([y,t,temp],x:abs(flatten(x)),if(x=[0]) then (temp:[0]) else (if is(first(x)>0)
then y:[integerdigits(divide(first(x),10)),rest(x)] else y:[divide(first(x),10),rest(x)],temp:flatten(y)),
return(temp))$
Usage ::
integerdigits(0) => [0]
integerdigits(110); => [0,0,1,1,0].
one can do, rest(rest(integerdigits(110))=> [1,1,0]
29. Similar to splitat in Haskell,
splitat(x,n):=block([temp:[]],
[part(x,makelist(i,i,1,n)), part(x,makelist(i,i,n+1,length(x)))]);
Usage :: splitat([1,2,3,4,5],3); => [[1,2,3],[4,5]]
----------------------------------------------------
30. Similar to drop in haskell,
dropat(x,n):=block([temp:[]],
part(x,makelist(i,i,n+1,length(x))));
Usage :: dropat([1,[2,3,4],5,6,7],3); => [6,7]
----------------------------------------------------
31. Similar to take in Haskell,
take(x,n):=block([temp:[]],part(x,makelist(i,i,1,n)));
Usage :: take([1,2,3,4,5,6,7],4); => [1,2,3,4]
----------------------------------------------------
32. Similar to tuples in Mathematica,
tuples(x,n):=apply(cartesian_product,create_list(setif
y(i),i,replicate(x,n)));
Usage :: tuples([1,2,3],2); => {[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]}
----------------------------------------------------
33. Similar to replicate in Haskell,
replicate(x,n):=block([temp:[]],for i:1 thru n do temp:cons(x,temp),temp);
Usage :: replicate([1,2,3],4) => [[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
----------------------------------------------------
34. Similar to takewhile in Haskell except that it will start from anywhere it finds satisfies the criteria and will also return the position along with the element, (suggested by slitvinov here).
load(basic);
takewhile(lst, pr):= block([c: []],
reverse(catch(for idx thru length(lst) do block([el: part(lst, idx)],
if not pr(el) and not emptyp(c) then throw(c)
else if pr(el) then push([el, idx], c)),
c)));
Usage :: [[4,5],[5,6],[7,7],[4,8]]
----------------------------------------------------
35. Complement similar to Mathematica,
complement(x,y):=block([],for i in y do
x:delete(i,x),x)$
Usage :: complement([1,2,3,4,5,1,3,5,8],[a,v,2,3,1]); => [4,5,5,8]
---------------------------------------------------
36. Interpreting membership at any depth in nested sublists,
member1(lis,l):=block([li:lis,p:false],load(basic),if member(l,li) then p:true else (while(not li=[])
do (li:apply(append,li),if(member(l,li)) then p:true,li:sublist(li,listp))),p)$
Usage ::
li : [[a, b, c],[2,3,4,[3,4,5,[00,99,88,[77,66,55,"+"]]]],[ff,gg,tt], [[t, y, u,[jj,kk,ll]]]] $
member1(li,[77,66,55,"+"]); => true
member1(li,[77,66,55,"+",7]); => false
----------------------------------------------------
37. Collecting information from different levels of nesting,
atlevel(lis,n):=block([li:lis,elem:[]],load(basic),for i:1 thru n do (li:apply(append,li),
push(sublist(li,lambda([x],(symbolp(x) or
integerp(x) or operatorp(x)))),elem), li:sublist(li,listp)),[reverse(elem),li])$
Usage :: atlevel(li,2) => [[[a,b,c,2,3,4,ff,gg,tt],[3,4,5,t,y,u]],[[0,99,88,[77,66,55,"+"]],[jj,kk,ll]]]
---------------------------------------------------
38. Building expression tree from postfix data, expression_tree(exp):=block([t1,t2,k,l:[], t:create_list(smake(1,x),x,charlist(exp))],print(t),
for i:1 thru length(t) do (if alphanumericp(t[i]) then print(push(t[i],l))
else (print(t[i]),if length(l)>=2 then (t1:pop(l),t2:pop(l), if(stringp(t1) and stringp(t2)) then (k:apply(t[i],
[parse_string(t2),parse_string(t1)]),print(push(k,l))) else (if stringp(t2) then t2:eval_string(t2),k:apply(t[i], [t2,t1]),print(push(k,l)))))),l[1])$
Usage :: expression_tree("wab-cde+/*^"); => [w^(((a-b)*c)/(e+d))]
-----------------------------------------------------
39. Gather similar to Mathematica(collecting similar solutions into one sublist),
listinbins(x):=block([r:[],s,y:unique(x)], for i in y do (if i#[] then (s:gather(i,x), x:delete(first(first(s)),x),push(s[1],r)) else push(last(x),r)),reverse(r))$
listseperate(x,op):=block([r:[],s,y:unique(x)], r:sublist(x,op),listinbins(r))$
gather(x,y):=block([t:[],tt:[],k,l:length(y),n],
k:sublist_indices(y,lambda([t],t=x)),for i in k do push(y[i],t),n:listcomplement(y,k),[t,n])$
Usage::
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],x^2+3*x=10));
=> [2,2]
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],(x^2)>1));
=> [[2,2],[3],[8],[9],[10],[12]]
listseperate([a,b,c,10,3,-1,1,e,1,8,e,s,a,2,q,2,9,12,s],lambda([x],symbolp(x)));
=> [[a,a],[b],[c],[e,e],[q],[s,s]]
----------------------------------------------------
40. Break a polynomial into a list of its part at topmost level,
breakPoly(ex):=block([res:[],temp:pickapart(ex,1)], for i:1 thru length(ex)
do(push(ev(part(temp,i)),res)),res)$
Usage :: expr: (a+b)/2 + sin (x^2^ee)/3 - log (1 + sqrt(x+1));
breakPoly(expr) => [(x+w)/2,-log(sqrt(x+1)+1),sin(x^2^ee)/3]
---------------------------------------------------
41. Integer digits of an integer,
integerdigits([x]):=block([y,t,temp],x:abs(flatten(x)),if(x=[0]) then (temp:[0]) else (if is(first(x)>0)
then y:[integerdigits(divide(first(x),10)),rest(x)] else y:[divide(first(x),10),rest(x)],temp:flatten(y)),
return(temp))$
Usage ::
integerdigits(0) => [0]
integerdigits(110); => [0,0,1,1,0].
one can do, rest(rest(integerdigits(110))=> [1,1,0]
--------------------------------------------------
No comments:
Post a Comment