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
20
Task/Comma-quibbling/EchoLisp/comma-quibbling.echolisp
Normal file
20
Task/Comma-quibbling/EchoLisp/comma-quibbling.echolisp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(lib 'match)
|
||||
|
||||
(define (quibble words)
|
||||
(match words
|
||||
[ null "{}"]
|
||||
[ (a) (format "{ %a }" a)]
|
||||
[ (a b) (format "{ %a and %a }" a b)]
|
||||
[( a ... b c) (format "{ %a %a and %a }" (for/string ([w a]) (string-append w ", ")) b c)]
|
||||
[else 'bad-input]))
|
||||
|
||||
|
||||
;; output
|
||||
|
||||
(for ([t '(() ("ABC") ("ABC" "DEF") ("ABC" "DEF" "G" "H"))])
|
||||
(writeln t '----> (quibble t)))
|
||||
|
||||
null ----> "{}"
|
||||
("ABC") ----> "{ ABC }"
|
||||
("ABC" "DEF") ----> "{ ABC and DEF }"
|
||||
("ABC" "DEF" "G" "H") ----> "{ ABC, DEF, G and H }"
|
||||
58
Task/Comma-quibbling/FreeBASIC/comma-quibbling.freebasic
Normal file
58
Task/Comma-quibbling/FreeBASIC/comma-quibbling.freebasic
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub Split(s As String, sep As String, result() As String)
|
||||
Dim As Integer i, j, count = 0
|
||||
Dim temp As String
|
||||
Dim As Integer position(Len(s) + 1)
|
||||
position(0) = 0
|
||||
For i = 0 To Len(s) - 1
|
||||
For j = 0 To Len(sep) - 1
|
||||
If s[i] = sep[j] Then
|
||||
count += 1
|
||||
position(count) = i + 1
|
||||
End If
|
||||
Next j
|
||||
Next i
|
||||
position(count + 1) = Len(s) + 1
|
||||
Redim result(count)
|
||||
For i = 1 To count + 1
|
||||
result(i - 1) = Mid(s, position(i - 1) + 1, position(i) - position(i - 1) - 1)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Function CommaQuibble(s As String) As String
|
||||
Dim i As Integer
|
||||
Dim As String result
|
||||
Dim As String words()
|
||||
s = Trim(s, Any "[]""")
|
||||
' Now remove internal quotes
|
||||
Split s, """", words()
|
||||
s = ""
|
||||
For i = 0 To UBound(words)
|
||||
s &= words(i)
|
||||
Next
|
||||
' Now split 's' using the comma as separator
|
||||
Erase words
|
||||
Split s, ",", words()
|
||||
' And re-assemble the string in the desired format
|
||||
result = "{"
|
||||
For i = 0 To UBound(words)
|
||||
If i = 0 Then
|
||||
result &= words(i)
|
||||
ElseIf i = UBound(words) Then
|
||||
result &= " and " & words(i)
|
||||
Else
|
||||
result &= ", " + words(i)
|
||||
EndIf
|
||||
Next
|
||||
Return result & "}"
|
||||
End Function
|
||||
|
||||
' As 3 of the strings contain embedded quotes these need to be doubled in FB
|
||||
Print CommaQuibble("[]")
|
||||
Print CommaQuibble("[""ABC""]")
|
||||
Print CommaQuibble("[""ABC"",""DEF""]")
|
||||
Print CommaQuibble("[""ABC"",""DEF"",""G"",""H""]")
|
||||
Print
|
||||
Print "Press any key to quit the program"
|
||||
Sleep
|
||||
23
Task/Comma-quibbling/Lasso/comma-quibbling.lasso
Normal file
23
Task/Comma-quibbling/Lasso/comma-quibbling.lasso
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
local(collection =
|
||||
array(
|
||||
array,
|
||||
array("ABC"),
|
||||
array("ABC", "DEF"),
|
||||
array("ABC", "DEF", "G", "H")
|
||||
)
|
||||
)
|
||||
|
||||
with words in #collection do {
|
||||
if(#words -> size > 1) => {
|
||||
local(last = #words -> last)
|
||||
#words -> removelast
|
||||
stdoutnl('{' + #words -> join(', ') + ' and ' + #last'}')
|
||||
else(#words -> size == 1)
|
||||
stdoutnl('{' + #words -> first + '}')
|
||||
else
|
||||
stdoutnl('{}')
|
||||
}
|
||||
|
||||
}
|
||||
10
Task/Comma-quibbling/Nim/comma-quibbling.nim
Normal file
10
Task/Comma-quibbling/Nim/comma-quibbling.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
proc commaQuibble(s): string =
|
||||
result = ""
|
||||
for i, c in s:
|
||||
if i > 0: result.add (if i < s.high: ", " else: " and ")
|
||||
result.add c
|
||||
result = "{" & result & "}"
|
||||
|
||||
var s = @[@[], @["ABC"], @["ABC", "DEF"], @["ABC", "DEF", "G", "H"]]
|
||||
for i in s:
|
||||
echo commaQuibble(i)
|
||||
9
Task/Comma-quibbling/Oforth/comma-quibbling.oforth
Normal file
9
Task/Comma-quibbling/Oforth/comma-quibbling.oforth
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
: quibbing(l) -- string
|
||||
| i s |
|
||||
StringBuffer new "{" <<
|
||||
l size dup 1- ->s loop: i [
|
||||
l at(i) <<
|
||||
i s < ifTrue: [ ", " << continue ]
|
||||
i s == ifTrue: [ " and " << ]
|
||||
]
|
||||
"}" << dup freeze ;
|
||||
7
Task/Comma-quibbling/Sidef/comma-quibbling.sidef
Normal file
7
Task/Comma-quibbling/Sidef/comma-quibbling.sidef
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
func comma_quibbling(words) {
|
||||
'{' + ([words.ft(0, -2).join(', ')]-[''] + [words.last] -> join(' and ')) + '}';
|
||||
}
|
||||
|
||||
[<>, <ABC>, <ABC DEF>, <ABC DEF G H>].each { |w|
|
||||
say comma_quibbling(w);
|
||||
}
|
||||
23
Task/Comma-quibbling/Swift/comma-quibbling.swift
Normal file
23
Task/Comma-quibbling/Swift/comma-quibbling.swift
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
let inputs = [[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]]
|
||||
|
||||
func quibbling(var words:[String]) {
|
||||
if words.count == 0 {
|
||||
println("{}")
|
||||
} else if words.count == 1 {
|
||||
println("{\(words[0])}")
|
||||
} else if words.count == 2 {
|
||||
println("{\(words[0]) and \(words[1])}")
|
||||
} else {
|
||||
var output = "{"
|
||||
while words.count != 2 {
|
||||
output += words.removeAtIndex(0) + ", "
|
||||
}
|
||||
output += "\(words.removeAtIndex(0)) and \(words.removeAtIndex(0))}"
|
||||
|
||||
println(output)
|
||||
}
|
||||
}
|
||||
|
||||
for word in inputs {
|
||||
quibbling(word)
|
||||
}
|
||||
29
Task/Comma-quibbling/XLISP/comma-quibbling.xlisp
Normal file
29
Task/Comma-quibbling/XLISP/comma-quibbling.xlisp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
(defun quibble (inputs &optional oxford-comma)
|
||||
(define final
|
||||
(if (and (caddr inputs) oxford-comma)
|
||||
", and "
|
||||
" and " ) )
|
||||
(defun comma-quibble (words)
|
||||
(cond
|
||||
((null words) "")
|
||||
((null (cdr words)) (car words))
|
||||
(t (begin
|
||||
(string-append (car words)
|
||||
(if (caddr words)
|
||||
(string-append ", " (comma-quibble (cdr words)))
|
||||
(string-append final (cadr words))) ) ) ) ) )
|
||||
(string-append "{" (comma-quibble inputs) "}") )
|
||||
|
||||
; test cases:
|
||||
(print (quibble '())) ; empty list
|
||||
(print (quibble '("ABC")))
|
||||
(print (quibble '("ABC" "DEF")))
|
||||
(print (quibble '("ABC" "DEF" "G" "H")))
|
||||
|
||||
(newline)
|
||||
|
||||
; test cases using the Oxford comma:
|
||||
(print (quibble '() t))
|
||||
(print (quibble '("ABC") t))
|
||||
(print (quibble '("ABC" "DEF") t))
|
||||
(print (quibble '("ABC" "DEF" "G" "H") t))
|
||||
6
Task/Comma-quibbling/jq/comma-quibbling-1.jq
Normal file
6
Task/Comma-quibbling/jq/comma-quibbling-1.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def quibble:
|
||||
if length == 0 then ""
|
||||
elif length == 1 then .[0]
|
||||
else (.[0:length-1] | join(", ")) + " and " + .[length-1]
|
||||
end
|
||||
| "{" + . + "}";
|
||||
1
Task/Comma-quibbling/jq/comma-quibbling-2.jq
Normal file
1
Task/Comma-quibbling/jq/comma-quibbling-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
( [], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]) | quibble
|
||||
5
Task/Comma-quibbling/jq/comma-quibbling-3.jq
Normal file
5
Task/Comma-quibbling/jq/comma-quibbling-3.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
jq -n -r -f Comma_quibbling.jq
|
||||
{}
|
||||
{ABC}
|
||||
{ABC and DEF}
|
||||
{ABC, DEF, G and H}
|
||||
Loading…
Add table
Add a link
Reference in a new issue