This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Sorting numbers

Old posts that have not been replied to for several years.
Locked
User avatar
duofruo
Halfop
Posts: 94
Joined: Thu Oct 23, 2003 3:17 pm
Location: Ploiesti@.ro
Contact:

Sorting numbers

Post by duofruo »

I have a file whith a list of numers like this for example

Code: Select all

1
49
2
6
18
49
3
8
7
1
46
1
I need a script that will show the most used numbers. In my example 1 and 49. Thx
Embrace The Inevitable
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

if there is no lsearch feature for this i might suggest this way:

-check every lindex of your string, list, whatever
-if it cointains a number -> check for an array called myarray($number), if yes -> incr it by 1, if no -> create it and set it to 1

at the end you will have an array, and all his fields represent a number and how often they are used. then you just need a loop to sort (e.g. bubblesort) them and you're done

this is just one possible way, i'm sure there are easier ways (like with lsort -> stringlist and so on)
User avatar
duofruo
Halfop
Posts: 94
Joined: Thu Oct 23, 2003 3:17 pm
Location: Ploiesti@.ro
Contact:

Post by duofruo »

i am verry new in this domain. so i am 0 . if someone can write is ok, if no ... thx anyway
Embrace The Inevitable
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

<snip>
XplaiN but think of me as stupid
Locked