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
30
Task/Odd-word-problem/EchoLisp/odd-word-problem-1.echolisp
Normal file
30
Task/Odd-word-problem/EchoLisp/odd-word-problem-1.echolisp
Normal 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 )
|
||||
|
|
@ -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."
|
||||
54
Task/Odd-word-problem/Lasso/odd-word-problem.lasso
Normal file
54
Task/Odd-word-problem/Lasso/odd-word-problem.lasso
Normal 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.'
|
||||
28
Task/Odd-word-problem/Nim/odd-word-problem.nim
Normal file
28
Task/Odd-word-problem/Nim/odd-word-problem.nim
Normal 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
|
||||
24
Task/Odd-word-problem/Sidef/odd-word-problem.sidef
Normal file
24
Task/Odd-word-problem/Sidef/odd-word-problem.sidef
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue