Skip to main content

Stalin Sort

Once in a while, I found a funny and interesting thing related to coding. I love coding (and to code). So, when somebody forwarded this - Stalin Sort, I laughed so hard but at the same time was intrigue. (Here is the link: https://github.com/gustavo-depaula/stalin-sort)

The main gist of this "Stalin Sort" is that if you found an element that does not met with the sort criteria, you send it "to Gulag". Ha ha ha. That is so funny. You just delete or drop the element. Just like what Stalin would do.

Later, I checked the github codes. Lots of codes there. The first thing I do is to find Perl implementation. I love perl. There, I found exactly what I wanted to see, a beautiful implementation. No, not the one-liner but the more verbose one. I love to explain things. When I see code that "no need to explain", you know you find a good code. It's just like jokes. If you have to explain it, it's not a good joke.

Few days ago, I just had to roll my own Python implementation. It was midnight. I was worried that it could take me quite a while to code it, but it just took me a few minutes. So here it is. (It is also available in here: https://pastebin.com/Vk3NwcYG)

# stalin sort but using "list". just to show how it works
# 2020 @rahard
 
def stalinsort(original = []):
    max = 0
    newarray = []
    for x in original:
        if (x>max):
            max = x
            newarray.append(x)
    return(newarray)
 
# main program
x = [1, 2, 3, 5, 5, 9, 7, 2]
y = stalinsort(x)
print("Original", x)
print("Stalin sorted", y)
 
I know it is not the perfect one, but it is the easiest to explain. At least for me. I am going to tell a story about this in my class. See you in my class.

Comments

Popular posts from this blog

Himbauan Kepada Hacker & Cracker Indonesia & Malaysia

Kepada Hacker & Cracker Indonesia & Malaysia, Saya mengharapkan anda tidak melakukan penyerangan atau/dan pengrusakan situs-situs Indonesia dan Malaysia. Saya mengerti bahwa akhir-akhir ini beberapa masalah di dunia nyata membuat kita kesal dan marah. Namun kekesalan tersebut sebaiknya tidak dilimpahkan ke dunia maya (cyberspace). Semestinya sebelum melakukan aksi yang berdampak negatif, kita bisa melakukan langkah-langkah positif seperti melakukan dialog (melalui email, mailing list, bulletin board, blog, dan media elektronik lainnya). Kita harus ingat bahwa kita hidup bertetangga dan bersaudara. Yang namanya hidup bertetangga pasti mengalami perbedaan pendapat. Mari kita belajar bertetangga dengan baik. Saya berharap agar kita yang hidup di dunia maya mencontohkan bagaimana kita menyelesaikan permasalahan dengan kepala dingin dan hati yang lapang, sehingga para pemimpin kita di dunia nyata dapat mencontoh penyelesaian damai. Mudah-mudahan mereka dapat lebih arif dan bijaksana

More bad news with Malaysia - Indonesia

I've got more emails and news about bad news between Indonesia and Malaysia. To be exact, there was a news about RELA (not sure what that is) that goes out after Indonesians in Malaysia. There were incidents where they hit Indonesians, rob, and do horrible things. I cannot even write this is my blog. I am so sad and frustrated. What's going on with Malaysia (and Malaysians)? What did we - Indonesian(s) - do to deserve this? I thought there should be less boundary between Indonesia and Malaysia. But ... What's going on there, bro & sis? You know, more Indonesians now feel that they are offended by Malaysians. I can tell you that this bad feeling is increasing. This is a bad publicity towards Malaysia. People are now creating various calling names, such as "Malingsia" (it's a short of "maling" [thief] "siah" [you, Sundanese]), and worse.

Say NO to APJII!

Prolog At the end of 1997, I went back to Indonesia from my studies and work in Canada. The .ID domain management in Indonesia at that time was in a confusing state. Nobody wanted to manage it. Universitas Indonesia (UI) - the original maintainer - was in a fight with APJII (the Association of Indonesian ISP). In the end, IANA gave me a mandate to manage the .ID domain. Since then, I manage the .ID domain with open management. There are problems, but mostly minors. Until recently, when APJII (again) is trying to take over the .ID domain management from my team. Here's a short info to give you a head start. Short summary APJII (the association of ISP in Indonesia) is trying to takeover the .ID domain management in Indonesia. They have tried and will try everything to take over. Long description I've been managing the .ID domain since the end of 1997. At that time, nobody wanted to run the domain management. First of all, a brief description of how we run things. To run the .ID d