Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
26
Task/Ordered-words/EchoLisp/ordered-words.echolisp
Normal file
26
Task/Ordered-words/EchoLisp/ordered-words.echolisp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(define (ordered? str)
|
||||
(for/and ([i (in-range 1 (string-length str))])
|
||||
(string-ci<=? (string-ref str (1- i)) (string-ref str i))))
|
||||
|
||||
(define (ordre words)
|
||||
(define wl 0)
|
||||
(define s 's)
|
||||
(for/fold (len 0) ((w words))
|
||||
(set! wl (string-length w))
|
||||
#:continue (< wl len)
|
||||
#:when (ordered? w)
|
||||
#:continue (and (= len wl) (push s w))
|
||||
(push (stack s) w) ;; start a new list of length wl
|
||||
wl)
|
||||
(stack->list s))
|
||||
|
||||
;; output
|
||||
(load 'unixdict)
|
||||
(ordre (text-parse unixdict))
|
||||
→ (abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty)
|
||||
|
||||
;; with the dictionaries provided with EchoLisp
|
||||
;; french
|
||||
→ (accentué) ;; ordered, longest, and ... self-reference
|
||||
;; english
|
||||
→ (Adelops alloquy beefily begorry billowy egilops)
|
||||
42
Task/Ordered-words/FreeBASIC/ordered-words.freebasic
Normal file
42
Task/Ordered-words/FreeBASIC/ordered-words.freebasic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function isOrdered(s As Const String) As Boolean
|
||||
If Len(s) <= 1 Then Return True
|
||||
For i As Integer = 1 To Len(s) - 1
|
||||
If s[i] < s[i - 1] Then Return False
|
||||
Next
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Dim words() As String
|
||||
Dim word As String
|
||||
Dim maxLength As Integer = 0
|
||||
Dim count As Integer = 0
|
||||
Open "undict.txt" For Input As #1
|
||||
While Not Eof(1)
|
||||
Line Input #1, word
|
||||
If isOrdered(word) Then
|
||||
If Len(word) = maxLength Then
|
||||
Redim Preserve words(0 To count)
|
||||
words(count) = word
|
||||
count += 1
|
||||
ElseIf Len(word) > maxLength Then
|
||||
Erase words
|
||||
maxLength = Len(word)
|
||||
Redim words(0 To 0)
|
||||
words(0) = word
|
||||
count = 1
|
||||
End If
|
||||
End If
|
||||
Wend
|
||||
|
||||
Close #1
|
||||
|
||||
Print "The ordered words with the longest length ("; Str(maxLength); ") in undict.txt are :"
|
||||
Print
|
||||
For i As Integer = 0 To UBound(words)
|
||||
Print words(i)
|
||||
Next
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
18
Task/Ordered-words/Lasso/ordered-words.lasso
Normal file
18
Task/Ordered-words/Lasso/ordered-words.lasso
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
local(f = file('unixdict.txt'), words = array, ordered = array, maxleng = 0)
|
||||
#f->dowithclose => {
|
||||
#f->foreachLine => {
|
||||
#words->insert(#1)
|
||||
}
|
||||
}
|
||||
with w in #words
|
||||
do => {
|
||||
local(tosort = #w->asString->values)
|
||||
#tosort->sort
|
||||
if(#w->asString == #tosort->join('')) => {
|
||||
#ordered->insert(#w->asString)
|
||||
#w->asString->size > #maxleng ? #maxleng = #w->asString->size
|
||||
}
|
||||
}
|
||||
with w in #ordered
|
||||
where #w->size == #maxleng
|
||||
do => {^ #w + '\r' ^}
|
||||
27
Task/Ordered-words/Lingo/ordered-words.lingo
Normal file
27
Task/Ordered-words/Lingo/ordered-words.lingo
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
-- Contents of unixdict.txt passed as string
|
||||
on printLongestOrderedWords (words)
|
||||
res = []
|
||||
maxlen = 0
|
||||
_player.itemDelimiter = numtochar(10)
|
||||
cnt = words.item.count
|
||||
repeat with i = 1 to cnt
|
||||
w = words.item[i]
|
||||
len = w.length
|
||||
ordered = TRUE
|
||||
repeat with j = 2 to len
|
||||
if chartonum(w.char[j-1])>chartonum(w.char[j]) then
|
||||
ordered = FALSE
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
if ordered then
|
||||
if len > maxlen then
|
||||
res = [w]
|
||||
maxlen = len
|
||||
else if len = maxlen then
|
||||
res.add(w)
|
||||
end if
|
||||
end if
|
||||
end repeat
|
||||
put res
|
||||
end
|
||||
21
Task/Ordered-words/Nim/ordered-words.nim
Normal file
21
Task/Ordered-words/Nim/ordered-words.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import httpclient, strutils
|
||||
|
||||
proc isSorted(s): bool =
|
||||
var last = low(char)
|
||||
for c in s:
|
||||
if c < last:
|
||||
return false
|
||||
last = c
|
||||
return true
|
||||
|
||||
const url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
|
||||
var mx = 0
|
||||
var words: seq[string] = @[]
|
||||
|
||||
for word in getContent(url).split():
|
||||
if word.len >= mx and isSorted(word):
|
||||
if word.len > mx:
|
||||
words = @[]
|
||||
mx = word.len
|
||||
words.add(word)
|
||||
echo words.join(" ")
|
||||
9
Task/Ordered-words/Oforth/ordered-words.oforth
Normal file
9
Task/Ordered-words/Oforth/ordered-words.oforth
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
: longWords
|
||||
| w longest l s |
|
||||
0 ->longest
|
||||
File new("unixdict.txt") forEach: w [
|
||||
w size dup ->s longest < ifTrue: [ continue ]
|
||||
w sort w == ifFalse: [ continue ]
|
||||
s longest > ifTrue: [ s ->longest ListBuffer new ->l ]
|
||||
l add(w)
|
||||
] l ;
|
||||
34
Task/Ordered-words/Phix/ordered-words.phix
Normal file
34
Task/Ordered-words/Phix/ordered-words.phix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
type ordered(sequence s)
|
||||
for i=1 to length(s)-1 do
|
||||
-- assume all items in the sequence are atoms
|
||||
if s[i]>s[i+1] then
|
||||
return 0
|
||||
end if
|
||||
end for
|
||||
return 1
|
||||
end type
|
||||
|
||||
integer maxlen
|
||||
sequence words
|
||||
object word
|
||||
constant fn = open("demo\\unixdict.txt","r")
|
||||
maxlen = -1
|
||||
|
||||
while 1 do
|
||||
word = gets(fn)
|
||||
if atom(word) then
|
||||
exit
|
||||
end if
|
||||
word = trim(word)
|
||||
if length(word)>=maxlen and ordered(lower(word)) then
|
||||
if length(word)>maxlen then
|
||||
maxlen = length(word)
|
||||
words = {}
|
||||
end if
|
||||
words = append(words,word)
|
||||
end if
|
||||
end while
|
||||
|
||||
close(fn)
|
||||
|
||||
?words
|
||||
37
Task/Ordered-words/Ring/ordered-words.ring
Normal file
37
Task/Ordered-words/Ring/ordered-words.ring
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
fn = "C:\Ring\unixdict.txt"
|
||||
|
||||
fp = fopen(fn,"r")
|
||||
str = fread(fp, getFileSize(fp))
|
||||
str = substr(str, windowsnl(), nl)
|
||||
clist = str2list(str)
|
||||
fclose(fp)
|
||||
dlist = []
|
||||
|
||||
for m = 1 to len(clist)
|
||||
flag = 1
|
||||
for n = 1 to len(clist[m])-1
|
||||
if ascii(clist[m][n+1]) < ascii(clist[m][n])
|
||||
flag=0 exit ok
|
||||
next
|
||||
if flag = 1
|
||||
add(dlist, clist[m]) ok
|
||||
next
|
||||
|
||||
nr = 0
|
||||
for m = 1 to len(dlist)
|
||||
if len(dlist[m]) > nr
|
||||
nr = len(dlist[m]) ok
|
||||
next
|
||||
|
||||
for n = 1 to len(dlist)
|
||||
if len(dlist[n]) = nr
|
||||
see dlist[n] + nl ok
|
||||
next
|
||||
|
||||
func getFileSize fp
|
||||
c_filestart = 0
|
||||
c_fileend = 2
|
||||
fseek(fp,0,c_fileend)
|
||||
nfilesize = ftell(fp)
|
||||
fseek(fp,0,c_filestart)
|
||||
return nfilesize
|
||||
14
Task/Ordered-words/Sidef/ordered-words.sidef
Normal file
14
Task/Ordered-words/Sidef/ordered-words.sidef
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
var words = [[]]
|
||||
var file = %f'unixdict.txt'
|
||||
|
||||
file.open_r(\var fh, \var err) ->
|
||||
|| die "Can't open file #{file}: $#{err}"
|
||||
|
||||
fh.each { |line|
|
||||
line.trim!
|
||||
if (line == line.sort) {
|
||||
words[line.length] := [] << line
|
||||
}
|
||||
}
|
||||
|
||||
say words[-1].join(' ')
|
||||
28
Task/Ordered-words/Swift/ordered-words.swift
Normal file
28
Task/Ordered-words/Swift/ordered-words.swift
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import Foundation
|
||||
|
||||
guard
|
||||
let url = NSURL(string: "http://www.puzzlers.org/pub/wordlists/unixdict.txt"),
|
||||
let input = try? NSString(contentsOfURL: url,encoding: NSUTF8StringEncoding) as String
|
||||
else { exit(EXIT_FAILURE) }
|
||||
|
||||
let words = input.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
|
||||
let group: ([Int: [String]], String) -> [Int: [String]] = {
|
||||
var d = $0; let g = d[$1.characters.count] ?? []
|
||||
d[$1.characters.count] = g + [$1]
|
||||
return d
|
||||
}
|
||||
let ordered: ([String], String) -> [String] = {
|
||||
guard String($1.characters.sort()) == $1 else { return $0 }
|
||||
return $0 + [$1]
|
||||
}
|
||||
|
||||
let groups = words
|
||||
.reduce([String](), combine: ordered)
|
||||
.reduce([Int: [String]](), combine: group)
|
||||
|
||||
guard
|
||||
let maxLength = groups.keys.maxElement(),
|
||||
let maxLengthGroup = groups[maxLength]
|
||||
else { exit(EXIT_FAILURE) }
|
||||
|
||||
maxLengthGroup.forEach { print($0) }
|
||||
14
Task/Ordered-words/jq/ordered-words.jq
Normal file
14
Task/Ordered-words/jq/ordered-words.jq
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def is_sorted:
|
||||
if length <= 1 then true
|
||||
else .[0] <= .[1] and (.[1:] | is_sorted)
|
||||
end;
|
||||
|
||||
def longest_ordered_words:
|
||||
# avoid string manipulation:
|
||||
def is_ordered: explode | is_sorted;
|
||||
map(select(is_ordered))
|
||||
| (map(length)|max) as $max
|
||||
| map( select(length == $max) );
|
||||
|
||||
|
||||
split("\n") | longest_ordered_words
|
||||
Loading…
Add table
Add a link
Reference in a new issue