|
| [ASK] Sort n Modus | |
| | Pengirim | Message |
---|
Kuro Ethernite The Creator
Posts : 1631 Thanked : 24 Engine : RMVX Ace Skill : Masterful Type : Jack of All Trades
Trophies
Awards:
| Subyek: [ASK] Sort n Modus 2011-11-30, 00:34 | |
| Model pertanyaan yg sama with my last trit before.... Aq hanya ingin tau BEST CASE dari suatu algoritma untuk men SORTIR, dan mencari MODUS.... Semenjak mencari Modus q kira langkah terbaikny yakni mengurutkan semua nilainy trlebih dahulu, so skalian ajah.... (summon fredy ~ ) THANKS AGAIN ~ | |
| | | Demon033 Novice
Posts : 258 Thanked : 2 Engine : Other Skill : Beginner Type : Writer
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 00:49 | |
| bagusan juga pke insertion sorting (OOT ga ya?? ) | |
| | | fredy Senior
Posts : 612 Thanked : 4 Engine : RMVX
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 00:51 | |
| Copas from CB how to sort array http://www.techotopia.com/index.php/Advanced_Ruby_Arrays#Sorting_Arrays | |
| | | Kuro Ethernite The Creator
Posts : 1631 Thanked : 24 Engine : RMVX Ace Skill : Masterful Type : Jack of All Trades
Trophies
Awards:
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 00:57 | |
| ya elah..... d topik ny kan aq ga menyatakan bahwa ini soal ruby... nany algoritma.... But my bad.... scara reflek q ngepos ny d sektor RGSS2 | |
| | | fredy Senior
Posts : 612 Thanked : 4 Engine : RMVX
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 01:16 | |
| Mungkin seperti ini algoritmanya Hope it help Though I'm not sure - Code:
-
#Coba misal ada array num = [3,8,10,15,7] ord[] ord[0] = num [0] #get the first minimum for i = 0..num.size if ord[0] < num[i] ord[0] = num[i] end end # determine max max = ord[0] for i = 0..num.size if num[i] > max max = num[i] end end #all except ord[0] become max temporaryly for i = 1..ord.size ord[i] = max end
#to the next for i = 1..num.size for j = 0..num.size #is current id value lower than or equal to max and not higher than previous id if ord[i] > num[j] and ord[i] <= ord[i-1] ord[i] = num[j] end end end | |
| | | Kuro Ethernite The Creator
Posts : 1631 Thanked : 24 Engine : RMVX Ace Skill : Masterful Type : Jack of All Trades
Trophies
Awards:
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 01:58 | |
| Kurang ngerti... Bisa rada d jelasin dikit ?? - Code:
-
# contoh.... ngaco = [5, 7, 9, 1, 3, 2] # any largest number parah = 999 for i in 0..ngaco.size for j in i..ngaco.size if ngaco[j] < parah parah = ngaco[j] ngaco[j] = ngaco[i] ngaco[i] = parah end end end Itu punya q.... Baru aja kepikir pas copas-edit punya mu tuk coba eksekusi ~ Konsepny, dari awal ampe akhir d tlusuri untuk d cari nilai minimal ny pas ketemu, langsung d tukar dengan array pertama, n sterus ny.... itu konsep ny.... Tapi pas coba d eksekusi masih ngaco juga masih ga k sortir..... well... at least that was my opinion.... | |
| | | hart Senior
Posts : 805 Thanked : 38 Engine : Other Skill : Very Beginner Type : Developer
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 07:52 | |
| yang cepat itu Quick Sort, Merge Sort, atau Heap Sort CMIIW, tapi saya lebih suka Quick Sort karena lebih mudah implementasinya (silahkan cari aja di google ) kalau mau gampang pake .Net aja deh, perintah sortnya luar biasa amat sangat cepat. @om kuro: yang punya anda itu Bubble Sort, algoritma sorting yang paling lambat dan paling mudah. BTW punya om sedikit salah, harusnya: - Code:
-
ngaco = [5, 7, 9, 1, 3, 2] for i in 0..ngaco.size for j in i + 1..ngaco.size if ngaco[j] < ngaco[i] parah = ngaco[j] ngaco[j] = ngaco[i] ngaco[i] = parah end end end
CMIIW | |
| | | Kuro Ethernite The Creator
Posts : 1631 Thanked : 24 Engine : RMVX Ace Skill : Masterful Type : Jack of All Trades
Trophies
Awards:
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 12:20 | |
| @hart g-goodness, it works.... IT WORKS !!!! u just hepl me out, hart !!!! Q kurang tau soal quick sort or bubble sort or whtaever.... Yg aq minta hanya yg paling simpel ny ~ Okay.... Let's get back to the point Now about mncari sebuah nilai yg paling sering muncul, or should I said Modus..... ini bayangan q untuk modus, and lemme know if there's something better.... - Code:
-
for i in 1..ngaco.size if i == (i-1) walah += 1 else if aduh > walah aduh = walah x = @ngaco[i] end walah = 0 end end Itu bayangan q untuk nyari modus.... Jelas keliatan ga efektif banget kalo aja ada jumlah modus yg sama.... | |
| | | hart Senior
Posts : 805 Thanked : 38 Engine : Other Skill : Very Beginner Type : Developer
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 14:14 | |
| @om kuro: wah sama2 tak kuduga bisa membantu - Quote :
- Q kurang tau soal quick sort or bubble sort or whtaever.... Yg aq minta hanya yg paling simpel ny ~
tapi kalau angkanya agak banyak (sekitar 1000 aja, belum banyak amat), bubble sort akan jadi sangat lambat.. (sampai2 anda pikir programnya hang). tapi kalau angkanya dikit sih memang gpp CMIIW BTW itu modusnya udah dicoba belum om? kalau saya lihat sih kayaknya hasilnya gak sesuai? IMO bukannya harusnya - Code:
-
for i in 1..ngaco.size if @ngaco[i] == @ngaco[i - 1] walah += 1 else if walah > aduh aduh = walah index_modus = i - 1 end walah = 0 end end bilangan_modus = ngaco[index_modus] jumlah_kemunculan = aduh
terus kalau mau bisa untuk modus lebih dari satu, di bayangan saya kayaknya tinggal bikin index_modus jadi array deh.. | |
| | | Kuro Ethernite The Creator
Posts : 1631 Thanked : 24 Engine : RMVX Ace Skill : Masterful Type : Jack of All Trades
Trophies
Awards:
| Subyek: Re: [ASK] Sort n Modus 2011-11-30, 14:29 | |
| owh crap .... kburu2, jdi lupa nambahin "ngaco" ny yep, that's whta I mean.... ntar..... q bakal mikirin bbrapa hal dlu.... (somekind dapet inspirasi ) Thanks por teh hepl ~ | |
| | | Sponsored content
| Subyek: Re: [ASK] Sort n Modus | |
| |
| | | | [ASK] Sort n Modus | |
|
| Permissions in this forum: | Anda tidak dapat menjawab topik
| |
| |
| Latest topics | » [Web Novel] Gloria Infidelis by LightNightKnight 2016-11-17, 21:27
» [Announcement] Forum baru untuk RMID by TheoAllen 2016-08-25, 16:39
» Where I'm Wrong ? by ReydVires 2016-07-24, 16:10
» flakeheartnet's Resources part III by flakeheartnet 2016-07-08, 14:30
» Keira's Art Warehouse by KeiraBlaze 2016-06-28, 19:27
» Theo Core Time System + Bingung by Lockin 2016-06-27, 16:24
» Error Script, Maybe ? by Lockin 2016-06-27, 16:20
» Nusaimoe @ RMID Lounge by Jihad Bagas 2016-06-21, 05:02
» Call Random Battle by Lockin 2016-06-15, 17:04
» Flakeheartnet Resources Part II [come back gift] by flakeheartnet 2016-06-07, 15:51
|
Statistics
|
Members: [ 4947 ]
Topics: [ 8258 ]
Posts: [ 112606 ]
Newest member: [ https://rmid.forumotion.net/u4968 ]
|
|
|
|