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,30 @@
(lib 'sequences)
(define input-stream null)
(define output-stream "")
;;---------------------------
;; character I/O simulation
;; --------------------------
(define (read-char) (next input-stream)) ;; #f if EOF
(define (write-char c) (when c (set! output-stream (string-append output-stream c))))
(define (init-streams sentence)
(set! input-stream (procrastinator sentence))
(set! output-stream ""))
;;---------------------------------
;; task , using read-char/write-char
;;----------------------------------
(define (flop) ; reverses, and returns first non-alpha after word, or EOF
(define c (read-char))
(if (string-alphabetic? c) (begin0 (flop) (write-char c)) c))
(define (flip)
(define c (read-char))
(if (string-alphabetic? c) (begin (write-char c) (flip)) c))
(define (task sentence)
(init-streams sentence)
(while (and (write-char (flip)) (write-char (flop))))
output-stream )

View file

@ -0,0 +1,5 @@
(task "what,is,the;meaning,of:life.")
→ "what,si,the;gninaem,of:efil."
; check diacritical
(task "Longtemps,je me suis couché,héhé,hôhô,de bonne heure.")
→ "Longtemps,ej me sius couché,éhéh,hôhô,ed bonne erueh."

View file

@ -0,0 +1,54 @@
define odd_word_processor(str::string) => {
local(
isodd = false,
pos = 1,
invpos = 1,
lastpos = 1
)
while(#str->get(#pos) != '.' && #pos <= #str->size) => {
if(not #str->isAlpha(#pos)) => {
not #isodd ? #isodd = true | #isodd = false
}
if(#isodd) => {
#lastpos = 1
#invpos = 1
while(#str->isAlpha(#pos+#lastpos) && #pos+#lastpos <= #str->size) => {
#lastpos++
}
'odd lastpos: '+#lastpos+'\r'
local(maxpos = #pos+#lastpos-1)
while(#invpos < (#lastpos+1)/2) => {
local(i,o,ipos,opos)
#ipos = #pos+#invpos
#opos = #pos+(#lastpos-#invpos)
#i = #str->get(#ipos)
#o = #str->get(#opos)
//'switching '+#i+' and '+#o+'\r'
//'insert '+#o+' at '+(#ipos)+'\r'
#str = string_insert(#str,-position=(#ipos),-text=#o)
//'remove redundant pos '+(#ipos+1)+'\r'
#str->remove(#ipos+1,1)
//'insert '+#i+' at '+(#opos)+'\r'
#str = string_insert(#str,-position=(#opos),-text=#i)
//'remove redundant pos '+(#opos+1)+'\r'
#str->remove(#opos+1,1)
#invpos++
}
#pos += #lastpos - 1
}
//#str->get(#pos) + #isodd + '\r'
#pos += 1
}
return #str
}
'orig:\rwhat,is,the;meaning,of:life.\r'
'new:\r'
odd_word_processor('what,is,the;meaning,of:life.')
'\rShould have:\rwhat,si,the;gninaem,of:efil.'

View file

@ -0,0 +1,28 @@
import os, unicode, future
proc nothing(): bool{.closure.} = false
proc odd(prev = nothing): bool =
let a = stdin.readChar()
if not isAlpha(Rune(ord(a))):
discard prev()
stdout.write(a)
return a != '.'
# delay action until later, in the shape of a closure
proc clos(): bool =
stdout.write(a)
prev()
return odd(clos)
proc even(): bool =
while true:
let c = stdin.readChar()
stdout.write(c)
if not isAlpha(Rune(ord(c))):
return c != '.'
var e = false
while (if e: odd() else: even()):
e = not e

View file

@ -0,0 +1,24 @@
func rev {
(var c = STDIN.getc) \\ return()
if (c ~~ /^[a-z]\z/i) {
var r = rev()
print c
return r
}
return c
}
var (n=0, l=false)
while (defined(var c = STDIN.getc)) {
var w = (c ~~ /^[a-z]\z/i)
++n if (w && !l)
l = w
if (n & 1) {
print c
} else {
var r = rev()
print(c, r)
n = 0
l = false
}
}