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,17 @@
PROGRAM ROT13
BEGIN
INPUT("Enter a string ",TEXT$)
FOR C%=1 TO LEN(TEXT$) DO
A%=ASC(MID$(TEXT$,C%,1))
CASE A% OF
65..90->
MID$(TEXT$,C%,1)=CHR$(65+(A%-65+13) MOD 26)
END ->
97..122->
MID$(TEXT$,C%,1)=CHR$(97+(A%-97+13) MOD 26)
END ->
END CASE
END FOR
PRINT("Converted: ";TEXT$)
END PROGRAM

View file

@ -0,0 +1,29 @@
' FB 1.05.0 Win64
' uses in place encoding/decoding
Sub rot13(ByRef s As String)
If s = "" Then Exit Sub
Dim code As Integer
For i As Integer = 0 To Len(s) - 1
Select Case As Const s[i]
Case 65 To 90 '' A to Z
code = s[i] + 13
If code > 90 Then code -= 26
s[i] = code
Case 97 To 122 '' a to z
code = s[i] + 13
If code > 122 Then code -= 26
s[i] = code
End Select
Next
End Sub
Dim s As String = "nowhere ABJURER"
Print "Before encoding : "; s
rot13(s)
Print "After encoding : "; s
rot13(s)
Print "After decoding : "; s
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,25 @@
import io.{lines, stdin}
def rot13( s ) =
buf = StringBuilder()
for c <- s
if isalpha( c )
n = ((ord(c) and 0x1F) - 1 + 13)%26 + 1
buf.append( chr(n or (if isupper(c) then 64 else 96)) )
else
buf.append( c )
buf.toString()
def rot13lines( ls ) =
for l <- ls
println( rot13(l) )
if _name_ == '-main-'
if args.isEmpty()
rot13lines( stdin() )
else
for f <- args
rot13lines( lines(f) )

View file

@ -0,0 +1,26 @@
// Extend the string type
define string->rot13 => {
local(
rot13 = bytes,
i, a, b
)
with char in .eachCharacter
let int = #char->integer
do {
// We only modify these ranges, set range if we should modify
#int >= 65 and #int < 91 ? local(a=65,b=91) |
#int >= 97 and #int < 123 ? local(a=97,b=123) | local(a=0,b=0)
if(#a && #b) => {
#i = (#int+13) % #b // loop back if past ceiling (#b)
#i += #a * (1 - #i / #a) // offset if below floor (#a)
#rot13->import8bits(#i) // import the new character
else
#rot13->append(#char) // just append the character
}
}
return #rot13->asstring
}

View file

@ -0,0 +1,18 @@
define rot13(p::string) => {
local(
rot13 = bytes,
a = bytes('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'),
b = bytes('NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'),
i
)
with char in #p->eachCharacter
let c = bytes(#char) do {
#i = #a->find(#b)
#i ? #rot13->import8bits(#b->get(#i)) | #rot13->append(#c)
}
return #rot13->asString
}
rot13('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')

View file

@ -0,0 +1,8 @@
function rot13 S
repeat with i = 1 to length(S)
get chartonum(char i of S)
if it < 65 or it > 122 or (it > 90 and it < 97) then next repeat
put char it - 64 of "NOPQRSTUVWXYZABCDEFGHIJKLM nopqrstuvwxyzabcdefghijklm" into char i of S
end repeat
return S
end rot13

View file

@ -0,0 +1,12 @@
import strutils
proc rot13(c): char =
case toLower(c)
of 'a'..'m': chr(ord(c) + 13)
of 'n'..'z': chr(ord(c) - 13)
else: c
for line in stdin.lines:
for c in line:
stdout.write rot13(c)
stdout.write "\n"

View file

@ -0,0 +1,5 @@
: encryptRot13(c)
c dup isLetter ifFalse: [ return ]
isUpper ifTrue: [ 'A' ] else: [ 'a' ] c 13 + over - 26 mod + ;
: rot13 map(#encryptRot13) charsAsString ;

View file

@ -0,0 +1,11 @@
function rot13(string s)
integer ch
for i=1 to length(s) do
ch = upper(s[i])
if ch>='A' and ch<='Z' then
s[i] += iff(ch<='M',+13,-13)
end if
end for
return s
end function
?rot13("abjurer NOWHERE.")

View file

@ -0,0 +1,14 @@
see "enter a string : " give s
ans = ""
for a = 1 to len(s)
letter = substr(s, a, 1)
if letter >= "a" and letter <= "z"
char = char(ascii(letter) + 13)
if char > "z" char = chr(asc(char) - 26) ok
else
if letter >= "a" and letter <= "z" char = char(ascii(letter) + 13) ok
if char > "z" char = char(ascii(char) - 26) else char = letter ok
ok
ans = ans + char
nex
see ans + nl

View file

@ -0,0 +1,7 @@
# Returns a copy of 's' with rot13 encoding.
func rot13(s) {
s.tr('A-Za-z', 'N-ZA-Mn-za-m');
}
# Perform rot13 on standard input.
STDIN.each { |line| print rot13(line) }

View file

@ -0,0 +1,16 @@
func rot13char(c: UnicodeScalar) -> UnicodeScalar {
switch c {
case "A"..."M", "a"..."m":
return UnicodeScalar(UInt32(c) + 13)
case "N"..."Z", "n"..."z":
return UnicodeScalar(UInt32(c) - 13)
default:
return c
}
}
func rot13(str: String) -> String {
return String(map(str.unicodeScalars){ c in Character(rot13char(c)) })
}
println(rot13("The quick brown fox jumps over the lazy dog"))

View file

@ -0,0 +1,14 @@
def (rot13 s)
(as string
(map rot13
(as list s)))
Alphabet <- "abcdefghijklmnopqrstuvwxyz"
def (rot13 c) :case (and string?.c len.c=1)
if ("a" <= c <= "z")
let idx (pos c Alphabet)
Alphabet (idx+13 % 26)
("A" <= c <= "Z")
(downcase.c -> rot13 -> upcase)
:else
c

View file

@ -0,0 +1,2 @@
(rot13 "Moron")
=> "Zbeba"

View file

@ -0,0 +1,19 @@
#!/usr/bin/env jq -M -R -r -f
# or perhaps:
#!/usr/local/bin/jq -M -R -r -f
# If your operating system does not allow more than one option
# to be specified on the command line,
# then consider using a version of jq that allows
# command-line options to be squished together (-MRrf),
# or see the following subsection.
def rot13:
explode
| map( if 65 <= . and . <= 90 then ((. - 52) % 26) + 65
elif 97 <= . and . <= 122 then (. - 84) % 26 + 97
else .
end)
| implode;
rot13

View file

@ -0,0 +1,13 @@
#!/bin/bash
jq -M -R -r '
def rot13:
explode
| map( if 65 <= . and . <= 90 then ((. - 52) % 26) + 65
elif 97 <= . and . <= 122 then (. - 84) % 26 + 97
else .
end)
| implode;
rot13'