Rosetta Code/Rank languages by popularity: Difference between revisions

m
→‎{{header|Wren}}: Minor tidy and rerun
(→‎{{header|C sharp|C#}}: Handle more that 500 languages and more than 999 tasks)
m (→‎{{header|Wren}}: Minor tidy and rerun)
(One intermediate revision by one other user not shown)
Line 6,361:
0 Examples - WML
0 Examples - VAX Assembly</pre>
 
=={{header|Visual Basic .NET}}==
Uses Web scrapping to get the information from the Languages category page - as this now shows the number of pages in each category with the non-task pages separated, there is no need to access other pages.<br>
It may be necessary to set the Security Protocol to Tls12 at the start of the Main method in order to run this - see the "Problem running the C# entry" section on the [[Talk:Rosetta Code/Count examples]] page.
<syntaxhighlight lang="vbnet">
Imports System.Collections
Imports System.Collections.Generic
Imports System.Net
Imports System.Text.RegularExpressions
 
Module RankLanguagesByPopularity
 
Private Class LanguageStat
Public name As String
Public count As Integer
Public Sub New(name As String, count As Integer)
Me.name = name
Me.count = count
End Sub
End Class
 
Private Function CompareLanguages(x As LanguageStat, y As languageStat) As Integer
Dim result As Integer = 0
If x IsNot Nothing Or y IsNot Nothing Then
If x Is Nothing Then
result = -1
ElseIf y Is Nothing
result = 1
Else
result = - x.count.CompareTo(y.count) ' Sort descending count
If result = 0 Then
result = x.name.CompareTo(y.name) ' Sort ascending name
End If
End If
End If
Return result
End Function
 
Public Sub Main(ByVal args As String())
 
Dim languages As New List(Of LanguageStat)
Dim basePage As String = "https://rosettacode.org/wiki/Category:Programming_Languages"
Dim nextPage As String = basePage
 
Dim nextPageEx = New RegEx("<a href=""/wiki/Category:Programming_Languages([?]subcatfrom=[^""]*)""")
Dim languageStatEx = _
New Regex(">([^<]+?)</a>[^<]*<span title=""Contains *[0-9,.]* *[a-z]*, *([0-9,.]*) *page")
 
Do While nextPage <> ""
Dim wc As New WebClient()
Dim page As String = wc.DownloadString(nextPage)
 
nextPage = ""
For Each link In nextPageEx.Matches(page)
nextPage = basePage & link.Groups(1).Value
Next link
 
For Each language In languageStatEx.Matches(page)
Dim lCount As Integer = 0
Dim lName As String = language.Groups(1).Value
Dim countText As String = language.Groups(2).Value.Replace(",", "").Replace(".", "")
If Not Integer.TryParse(countText, lCount)
Console.Out.WriteLine(lName & "Invalid page count: <<" & countText & ">>")
Else
languages.Add(New LanguageStat(lName, lCount))
End If
Next language
Loop
 
languages.Sort(AddressOf CompareLanguages)
 
Dim prevCount As Integer = -1
Dim prevPosition As Integer = -1
Dim position As Integer = 0
For Each stat As LanguageStat In languages
position += 1
If stat.count <> prevCount Then
prevPosition = position
prevCount = stat.Count
End If
Console.Out.WriteLine(prevPosition.ToString.PadLeft(4) & ": " &
stat.count.ToString.PadLeft(4) & " " & stat.name)
Next stat
 
End Sub
 
End Module
</syntaxhighlight>
{{out}}
Sample output as at 11th September 2023
<pre>
1: 1652 Phix
1: 1652 Wren
3: 1614 Julia
4: 1595 Raku
5: 1576 Nim
6: 1546 Go
7: 1531 Perl
8: 1470 Python
9: 1375 J
10: 1285 C
. . .
</pre>
 
=={{header|Wren}}==
Line 6,367 ⟶ 6,470:
{{libheader|Wren-fmt}}
An embedded program so we can use libcurl.
<syntaxhighlight lang="ecmascriptwren">/* rc_rank_languages_by_popularityRosetta_Code_Rank_languages_by_popularity.wren */
 
import "./pattern" for Pattern
Line 6,428 ⟶ 6,531:
var langs = findLangs.call()
langs.sort { |a, b| a[1] > b[1] }
System.print("Languages with most examples as at 113 SeptemberFebruary, 20222024:")
var rank = 0
var lastScore = 0
Line 6,447 ⟶ 6,550:
<br>
We now embed this script in the following C program, build and run.
<syntaxhighlight lang="c">/* gcc rc_rank_languages_by_popularityRosetta_Code_Rank_languages_by_popularity.c -o rc_rank_languages_by_popularityRosetta_Code_Rank_languages_by_popularity -lcurl -lwren -lm */
 
#include <stdio.h>
Line 6,621 ⟶ 6,724:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "rc_rank_languages_by_popularityRosetta_Code_Rank_languages_by_popularity.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 6,642 ⟶ 6,745:
Showing just the top thirty.
<pre>
Languages with most examples as at 113 SeptemberFebruary, 20222024:
1 Wren 1,570665
2 1 = Phix 1,569665
3 Julia 1,538638
4 Raku 1,518608
5 Go Nim 1,496576
6 PerlGo 1,467547
7 PythonPerl 1,405540
8 Nim Python 1,402497
9 J 1,276413
10 C Java 1,211318
11 MathematicaC 1,178293
12 REXXC++ 1,149258
13 HaskellRuby 1,139235
14 Java Mathematica 1,137200
15 Kotlin FreeBASIC 1,133185
16 C++ Haskell 1,123166
17 RubyREXX 1,103152
18 RacketKotlin 1,089143
19 FreeBASICRacket 1,070099
20 ZklJq 1,011081
21 Sidef 1,003051
22 Factor11l 985 1,016
23 DZkl 9791,011
24 TclFactor 9751,001
25 11lD 962 990
26 AdaALGOL 68 919986
27 CTcl sharp 917 983
28 Scala 897948
29 RustDelphi 880945
30 LuaAda 878940
30 = Rust 940
</pre>
 
9,476

edits