June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,11 +1,6 @@
|
|||
fun commaQuibble(s):
|
||||
result = ""
|
||||
for (i, c) in enumerate(s):
|
||||
if i > 0:
|
||||
result += ", " if i < s[!0] else "and "
|
||||
result += c
|
||||
result = "{ $result }"
|
||||
fun quibble(s):
|
||||
let result = ' and '.join(s).replace(/ and /, ', ', len(s) - 1)
|
||||
"{ $result }"
|
||||
|
||||
var s = [ [] ["ABC"] ["ABC", "DEF"] ["ABC", "DEF", "G", "H"] ]
|
||||
|
||||
for i in s: print commaQuibble i
|
||||
let s = [ [] ["ABC"] ["ABC", "DEF"] ["ABC", "DEF", "G", "H"] ]
|
||||
for i in s: print(quibble i)
|
||||
|
|
|
|||
20
Task/Comma-quibbling/Factor/comma-quibbling.factor
Normal file
20
Task/Comma-quibbling/Factor/comma-quibbling.factor
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
USING: arrays combinators io kernel qw sequences ;
|
||||
IN: rosetta-code.comma-quibble
|
||||
|
||||
: wrap ( str -- {str} ) "{" prepend "}" append ;
|
||||
: quibble-pair ( seq -- str ) " and " join wrap ;
|
||||
: quibble-list ( seq -- str )
|
||||
[ but-last ] [ last ] bi [ ", " join ] dip 2array
|
||||
quibble-pair ;
|
||||
: comma-quibble ( seq -- ) dup length
|
||||
{
|
||||
{ 0 [ drop "{}" ] }
|
||||
{ 1 [ first wrap ] }
|
||||
{ 2 [ quibble-pair ] }
|
||||
[ drop quibble-list ]
|
||||
} case print ;
|
||||
|
||||
{ } comma-quibble
|
||||
qw{ ABC } comma-quibble
|
||||
qw{ ABC DEF } comma-quibble
|
||||
qw{ ABC DEF G H } comma-quibble
|
||||
|
|
@ -1,4 +1,10 @@
|
|||
quibble(words) =
|
||||
"{"* (isempty(words) ? "" :
|
||||
length(words)==1? words[1] :
|
||||
join(words[1:end-1],", ")*" and "*words[end]) *"}"
|
||||
function quibble(arr::Array)
|
||||
if isempty(arr) rst = "" else rst = "$(arr[end])" end
|
||||
if length(arr) > 1 rst = join(arr[1:end-1], ", ") * " and " * rst end
|
||||
return "{" * rst * "}"
|
||||
end
|
||||
|
||||
@show quibble([])
|
||||
@show quibble(["ABC"])
|
||||
@show quibble(["ABC", "DEF"])
|
||||
@show quibble(["ABC", "DEF", "G", "H"])
|
||||
|
|
|
|||
17
Task/Comma-quibbling/OCaml/comma-quibbling-1.ocaml
Normal file
17
Task/Comma-quibbling/OCaml/comma-quibbling-1.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
open Printf
|
||||
|
||||
let quibble list =
|
||||
let rec aux = function
|
||||
| a :: b :: c :: d :: rest -> a ^ ", " ^ aux (b :: c :: d :: rest)
|
||||
| [a; b; c] -> sprintf "%s, %s and %s}" a b c
|
||||
| [a; b] -> sprintf "%s and %s}" a b
|
||||
| [a] -> sprintf "%s}" a
|
||||
| [] -> "}" in
|
||||
"{" ^ aux list
|
||||
|
||||
let test () =
|
||||
[[];
|
||||
["ABC"];
|
||||
["ABC"; "DEF"];
|
||||
["ABC"; "DEF"; "G"; "H"]]
|
||||
|> List.iter (fun list -> print_endline (quibble list))
|
||||
15
Task/Comma-quibbling/OCaml/comma-quibbling-2.ocaml
Normal file
15
Task/Comma-quibbling/OCaml/comma-quibbling-2.ocaml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
open Core
|
||||
|
||||
let quibble = function
|
||||
| [| |] -> "{}"
|
||||
| [| a |] -> sprintf "{%s}" a
|
||||
| array ->
|
||||
let last, rest = Array.last array, Array.slice array 0 (-1) in
|
||||
sprintf "{%s and %s}" (String.concat_array ~sep:", " rest) last
|
||||
|
||||
let test () =
|
||||
[[||];
|
||||
[|"ABC"|];
|
||||
[|"ABC"; "DEF"|];
|
||||
[|"ABC"; "DEF"; "G"; "H"|]]
|
||||
|> List.iter ~f:(fun list -> print_endline (quibble list))
|
||||
44
Task/Comma-quibbling/Ring/comma-quibbling.ring
Normal file
44
Task/Comma-quibbling/Ring/comma-quibbling.ring
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Project : Comma Quibbling
|
||||
# Date : 2017/11/12
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
text = list(4)
|
||||
text[1] = "{}"
|
||||
text[2] = "ABC"
|
||||
text[3] = "ABC,DEF"
|
||||
text[4] = "ABC,DEF,G,H"
|
||||
comma(text)
|
||||
|
||||
func comma(text)
|
||||
listtext = []
|
||||
for n = 1 to 4
|
||||
listtext = str2list(substr(text[n], ",", nl))
|
||||
if n = 2
|
||||
see "{" + list2str(listtext) + "}" + nl
|
||||
loop
|
||||
ok
|
||||
if len(listtext) = 1
|
||||
see "{}" + nl
|
||||
loop
|
||||
ok
|
||||
str = "{"
|
||||
for m = 1 to len(listtext)-1
|
||||
if len(listtext) = 2
|
||||
str = str + listtext[m] + " "
|
||||
else
|
||||
str = str + listtext[m] + ", "
|
||||
ok
|
||||
next
|
||||
if len(listtext) = 2
|
||||
str = left(str, len(str)-1)
|
||||
else
|
||||
str = left(str, len(str)-2)
|
||||
ok
|
||||
if len(listtext) = 2
|
||||
str = str + " " + listtext[len(listtext)] + "}"
|
||||
else
|
||||
str = str + " and " + listtext[len(listtext)] + "}"
|
||||
ok
|
||||
see str + nl
|
||||
next
|
||||
16
Task/Comma-quibbling/VBA/comma-quibbling.vba
Normal file
16
Task/Comma-quibbling/VBA/comma-quibbling.vba
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Debug.Print Quibbling("")
|
||||
Debug.Print Quibbling("ABC")
|
||||
Debug.Print Quibbling("ABC, DEF")
|
||||
Debug.Print Quibbling("ABC, DEF, G, H")
|
||||
Debug.Print Quibbling("ABC, DEF, G, H, IJKLM, NO, PQRSTUV")
|
||||
End Sub
|
||||
|
||||
Private Function Quibbling(MyString As String) As String
|
||||
Dim s As String, n As Integer
|
||||
s = "{" & MyString & "}": n = InStrRev(s, ",")
|
||||
If n > 0 Then s = Left(s, n - 1) & " and " & Right(s, Len(s) - (n + 1))
|
||||
Quibbling = s
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue