Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,25 @@
PROGRAM LETTER
DIM CNT[255]
BEGIN
OPEN("I",1,"f:\errev30\erre.hlp")
REPEAT
GET(#1,A$)
L%=LEN(A$)
IF L%>0 THEN
FOR I%=1 TO L% DO
A%=ASC(MID$(A$,I%))
CNT[A%]+=1
END FOR
END IF
UNTIL EOF(1)
CLOSE(1)
FOR C%=$41 TO $5A DO
PRINT(CHR$(C%);CHR$(C%+32);": ";CNT[C%]+CNT[C%+32])
END FOR
END PROGRAM

View file

@ -0,0 +1,11 @@
;; bump count when letter added
(define (hash-counter hash key )
;; (set! key (string-downcase key)) - if ignore case wanted
(putprop hash (1+ (or (getprop hash key) 0 )) key))
;; apply to exploded string
;; and sort result
(define (hash-compare a b) ( < (first a) (first b)))
(define (count-letters hash string)
(map (curry hash-counter hash) (string->list string))
(list-sort hash-compare (symbol-plist hash)))

View file

@ -0,0 +1,24 @@
(define (file-stats file string)
(set-plist! 'file-stats null) ; reset counters
(writeln (count-letters 'file-stats string))
(writeln "Total letters:" (string-length string))
(writeln "Total lines:" (getprop 'file-stats "#\\newline")))
; frequency for 'help.html' file
(file->string file-stats) ; browser 'open' dialog
➛ help.html -> string
➛ (( 28918) (! 138) (# 1035) (#\newline 4539) (#\tab 409) ($ 7) (% 24) (& 136) (' 1643) ((3577) () 3583) (* 233)
(+ 303) (, 599) (- 3164) (. 1454) (/ 5388) (0 1567) (1 1769) (2 1258) (3 857) (4 1872) (5 453) (6 581) (7 344)
(8 337) (9 411) (: 1235) (; 647) (< 9951) (= 1834) (> 10255) (? 392) (@ 11) (A 166) (B 92) (C 144) (D 72) (E 224)
(F 52) (G 35) (H 42) (I 193) (J 31) (K 36) (L 196) (M 82) (N 94) (O 132) (P 192) (Q 27) (R 56) (S 220) (T 226) (U 37)
(V 51) (W 28) (X 6) (Y 38) (Z 2) ([ 237) (\ 12) (] 215) (^ 28) (_ 107) (` 7) (a 8420) (b 4437) (c 3879) (d 4201)
(e 11905) (f 2989) (g 2068) (h 3856) (i 11313) (j 334) (k 653) (l 5748) (m 3048) (n 7020) (o 7207) (p 3585) (q 249)
(r 8312) (s 8284) (t 8704) (u 3833) (v 1135) (w 861) (x 1172) (y 1451) (z 268) ({ 123) (| 62) (} 123) (~ 7) (§ 1) (© 1)
(« 1) (» 1) (É 2) (à 18) (â 3) (ç 3) (è 6) (é 53) (î 1) (ö 9) (û 1) (œ 1) (ε 2) (λ 12) (μ 1) (ο 2) (ς 1)
(τ 1) (а 1) (д 1) (е 1) (з 1) (л 1) (м 1) (н 1) (я 3) (ἄ 1) (— 2) (“ 2) (” 2) (… 184) (→ 465) (∅ 57) (∈ 4) (∏ 1)
(∑ 2) (∘ 6) (√ 4)(∞ 12) (∫ 2) (⌚ 2) (⌛ 1) (⏳ 4) (☕ 1) (♠ 7) (♡ 2) (♢ 2) (♣ 6) (♤ 2) (♥ 8) (♦ 8)
(♧ 2) (⚁ 1) (⚃ 2) (⚪ 1) (⛔ 1) (✋ 1) (❄ 1) (❅ 1) (❆ 1) (❇ 1) (❈ 1) (❉ 1) (❊ 1) (❋ 1) (❌ 3) (❍ 1)
(❎ 1) (❗ 1) (➛ 900) (➰ 1) (⭕ 2) ... )
➛ Total letters: 212631
➛ Total lines: 4539

View file

@ -0,0 +1,28 @@
' FB 1.05.0 Win64
Dim a(65 to 90) As Integer ' array to hold frequency of each letter, all elements zero initially
Dim fileName As String = "input.txt"
Dim s As String
Dim i As Integer
Open fileName For Input As #1
While Not Eof(1)
Line Input #1, s
s = UCase(s)
For i = 0 To Len(s) - 1
a(s[i]) += 1
Next
Wend
Close #1
Print "The frequency of each letter in the file "; fileName; " is as follows:"
Print
For i = 65 To 90
If a(i) > 0 Then
Print Chr(i); " : "; a(i)
End If
Next
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,24 @@
PROCEDURE Main()
LOCAL s := hb_MemoRead( Left( __FILE__ , At( ".", __FILE__ )) +"prg")
LOCAL c, n, i
LOCAL a := {}
FOR EACH c IN s
IF Asc( c ) > 31
AAdd( a, c )
ENDIF
NEXT
a := ASort( a )
i := 1
WHILE i <= Len( a )
c := a[i] ; n := 1
i++
IF i < Len(a) .AND. c == a[i]
WHILE c == a[i]
n++ ; i++
END
ENDIF
?? "'" + c + "'" + "=" + hb_NtoS( n ) + " "
END
RETURN

View file

@ -0,0 +1,24 @@
local(
str = 'Hello world!',
freq = map
)
// as a loop. arguably quicker than query expression
loop(#str->size) => {
#freq->keys !>> #str->get(loop_count) ?
#freq->insert(#str->get(loop_count) = #str->values->find(#str->get(loop_count))->size)
}
// or
local(
str = 'Hello world!',
freq = map
)
// as query expression, less code
with i in #str->values where #freq->keys !>> #i do => {
#freq->insert(#i = #str->values->find(#i)->size)
}
// output #freq
with elem in #freq->keys do => {^
'"'+#elem+'": '+#freq->find(#elem)+'\r'
^}

View file

@ -0,0 +1,8 @@
import tables, os
var t = initCountTable[char]()
var f = open(paramStr(1))
for l in f.lines:
for c in l:
t.inc(c)
echo t

View file

@ -0,0 +1,17 @@
sequence lc = repeat(0,#7E)
integer fn = open(command_line()[$],"rb"), ch
while 1 do
ch = getc(fn)
if ch=-1 then exit end if
if ch>=' ' and ch<#7F then
lc[ch] += 1
end if
end while
close(fn)
for i=' ' to #7E do
if lc[i]!=0 then
printf(1,"'%c': %d%s",{i,lc[i],iff(mod(i,32)=31?'\n':'\t')})
end if
end for
{} = wait_key()

View file

@ -0,0 +1,14 @@
textData = read("C:\Ring\ReadMe.txt")
ln =len(textData)
charCount = list(255)
totCount = 0
for i =1 to ln
char = ascii(substr(textData,i,1))
charCount[char] = charCount[char] + 1
if char > 31 totCount = totCount + 1 ok
next
for i = 32 to 255
if charCount[i] > 0 see char(i) + " = " + charCount[i] + " " + (charCount[i]/totCount)*100 + " %" + nl ok
next

View file

@ -0,0 +1,9 @@
func letter_frequency(File file) {
file.read.chars.grep{.match(/[[:alpha:]]/)} \
.group_by {|letter| letter.downcase} \
.map_val {|_, val| val.len} \
.sort_by {|_, val| -val}
}
var top = letter_frequency(File(__FILE__))
top.each{|pair| say "#{pair[0]}: #{pair[1]}"}

View file

@ -0,0 +1,9 @@
# Input: an array of strings.
# Output: an object with the strings as keys,
# the values of which are the corresponding frequencies.
def counter:
reduce .[] as $item ( {}; .[$item] += 1 ) ;
# For neatness we sort the keys:
explode | map( [.] | implode ) | counter | . as $counter
| keys | sort[] | [., $counter[.] ]

View file

@ -0,0 +1 @@
jq -s -R -c -f Letter_frequency.jq somefile.txt