How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the Red programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the Red programming language

Table of Contents

Problem Statement

Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 02 August 2022 at 09:50 +02

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the Red programming language

Source code in the red programming language

Red []

data: read http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
lb: make block! 500
;;data: read %data.html ;; for testing save html and use flat file 
arr: split data newline

k: "Category:"
;; exclude list:
exrule: [thru ["programming" 
                | "users" 
                | "Implementations"
                | "Solutions by "
                | "Members"
                | "WikipediaSourced"
                | "Typing/Strong"
                | "Impl needed"
                ]
            to end
          ]
          
foreach line arr [
  unless find line k [continue]
  parse line [ thru k thru ">" copy lang to "<" to end ] ;; extract/parse language
  if 20 < length? lang [continue]
  if parse lang [exrule] [continue] ;; exclude invalid
  cnt: 0
  ;; parse number of entries
  parse line [thru "" thru "(" copy cnt  to " member" (cnt: to-integer cnt ) to end]
  if cnt > 25 [  append  lb reduce [to-string lang cnt]   ] ;; only process lang with > 25 entries
]

lb:  sort/skip/compare lb 2 2   ;; sort series by entries

print reduce [ "Rank Entries Language" ]    ;; header 

last: 0
rank: 0

lb: tail lb   ;; process the series backwards

until [
  lb: skip lb -2
  cnt: second lb
  if cnt <> last [
    rank: rank + 1 
  ]
  print rejoin [ pad/left rank 4 "." pad/left cnt 5 " - " first lb  ]
  last: cnt
  head? lb  ;; until head reached
]


  

You may also check:How to resolve the algorithm Queue/Usage step by step in the Nim programming language
You may also check:How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the Perl programming language
You may also check:How to resolve the algorithm Null object step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Text processing/1 step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Ludic numbers step by step in the Raku programming language