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
17
Task/Rot-13/ERRE/rot-13.erre
Normal file
17
Task/Rot-13/ERRE/rot-13.erre
Normal 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
|
||||
29
Task/Rot-13/FreeBASIC/rot-13.freebasic
Normal file
29
Task/Rot-13/FreeBASIC/rot-13.freebasic
Normal 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
|
||||
25
Task/Rot-13/FunL/rot-13.funl
Normal file
25
Task/Rot-13/FunL/rot-13.funl
Normal 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) )
|
||||
26
Task/Rot-13/Lasso/rot-13-1.lasso
Normal file
26
Task/Rot-13/Lasso/rot-13-1.lasso
Normal 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
|
||||
}
|
||||
18
Task/Rot-13/Lasso/rot-13-2.lasso
Normal file
18
Task/Rot-13/Lasso/rot-13-2.lasso
Normal 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')
|
||||
8
Task/Rot-13/LiveCode/rot-13.livecode
Normal file
8
Task/Rot-13/LiveCode/rot-13.livecode
Normal 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
|
||||
12
Task/Rot-13/Nim/rot-13.nim
Normal file
12
Task/Rot-13/Nim/rot-13.nim
Normal 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"
|
||||
5
Task/Rot-13/Oforth/rot-13.oforth
Normal file
5
Task/Rot-13/Oforth/rot-13.oforth
Normal 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 ;
|
||||
11
Task/Rot-13/Phix/rot-13.phix
Normal file
11
Task/Rot-13/Phix/rot-13.phix
Normal 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.")
|
||||
14
Task/Rot-13/Ring/rot-13.ring
Normal file
14
Task/Rot-13/Ring/rot-13.ring
Normal 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
|
||||
7
Task/Rot-13/Sidef/rot-13.sidef
Normal file
7
Task/Rot-13/Sidef/rot-13.sidef
Normal 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) }
|
||||
16
Task/Rot-13/Swift/rot-13.swift
Normal file
16
Task/Rot-13/Swift/rot-13.swift
Normal 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"))
|
||||
14
Task/Rot-13/Wart/rot-13-1.wart
Normal file
14
Task/Rot-13/Wart/rot-13-1.wart
Normal 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
|
||||
2
Task/Rot-13/Wart/rot-13-2.wart
Normal file
2
Task/Rot-13/Wart/rot-13-2.wart
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(rot13 "Moron")
|
||||
=> "Zbeba"
|
||||
19
Task/Rot-13/jq/rot-13-1.jq
Normal file
19
Task/Rot-13/jq/rot-13-1.jq
Normal 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
|
||||
13
Task/Rot-13/jq/rot-13-2.jq
Normal file
13
Task/Rot-13/jq/rot-13-2.jq
Normal 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'
|
||||
Loading…
Add table
Add a link
Reference in a new issue