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,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 }"

View 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

View 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('{}')
}
}

View 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)

View 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 ;

View 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);
}

View 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)
}

View 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))

View 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
| "{" + . + "}";

View file

@ -0,0 +1 @@
( [], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]) | quibble

View file

@ -0,0 +1,5 @@
jq -n -r -f Comma_quibbling.jq
{}
{ABC}
{ABC and DEF}
{ABC, DEF, G and H}