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

23
Task/Nth/ERRE/nth.erre Normal file
View file

@ -0,0 +1,23 @@
PROGRAM NTH_SOLVE
!
! for rosettacode.org
!
PROCEDURE NTH(S%,E%)
LOCAL I%,SUFF$
FOR I%=S% TO E% DO
SUFF$="th"
IF I% MOD 10=1 AND I% MOD 100<>11 THEN SUFF$="st" END IF
IF I% MOD 10=2 AND I% MOD 100<>12 THEN SUFF$="nd" END IF
IF I% MOD 10=3 AND I% MOD 100<>13 THEN SUFF$="rd" END IF
PRINT(STR$(I%)+SUFF$+" ";)
END FOR
PRINT
END PROCEDURE
BEGIN
NTH(0,25)
NTH(250,265)
NTH(1000,1025)
END PROGRAM

View file

@ -0,0 +1,39 @@
' FB 1.05.0 Win64
' Apostrophes NOT used as incorrect English
Function ordinal(n As UInteger) As String
Dim ns As String = Str(n)
Select Case Right(ns, 1)
Case "0", "4" To "9"
Return ns + "th"
Case "1"
If Right(ns, 2) = "11" Then Return ns + "th"
Return ns + "st"
Case "2"
If Right(ns, 2) = "12" Then Return ns + "th"
Return ns + "nd"
Case "3"
If Right(ns, 2) = "13" Then Return ns + "th"
Return ns + "rd"
End Select
End Function
Dim i As Integer
For i = 0 To 25
Print ordinal(i); " ";
Next
Print : Print
For i = 250 To 265
Print ordinal(i); " ";
Next
Print : Print
For i = 1000 To 1025
Print ordinal(i); " ";
Next
Print : Print
Print "Press any key to quit"
Sleep

9
Task/Nth/Nim/nth.nim Normal file
View file

@ -0,0 +1,9 @@
const suffix = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"]
proc nth(n): string =
$n & "'" & (if n mod 100 <= 10 or n mod 100 > 20: suffix[n mod 10] else: "th")
for j in countup(0, 1000, 250):
for i in j..j+24:
stdout.write nth(i), " "
echo ""

View file

@ -0,0 +1,7 @@
: nth(n)
| r |
n "th" over 10 mod ->r
r 1 == ifTrue: [ n 100 mod 11 == ifFalse: [ drop "st" ] ]
r 2 == ifTrue: [ n 100 mod 12 == ifFalse: [ drop "nd" ] ]
r 3 == ifTrue: [ n 100 mod 13 == ifFalse: [ drop "rd" ] ]
+ ;

15
Task/Nth/Ring/nth.ring Normal file
View file

@ -0,0 +1,15 @@
for nr = 0 to 25
see Nth(nr) + Nth(nr + 250) + Nth(nr + 1000) + nl
next
func getSuffix n
lastTwo = n % 100
lastOne = n % 10
if lastTwo > 3 and lastTwo < 21 "th" ok
if lastOne = 1 return "st" ok
if lastOne = 2 return "nd" ok
if lastOne = 3 return "rd" ok
return "th"
func Nth n
return "" + n + "'" + getSuffix(n) + " "

21
Task/Nth/Set-lang/nth.set Normal file
View file

@ -0,0 +1,21 @@
set o 49
set t 50
set h 51
set n !
set ! n
set ! 39
[n=o] set ? 13
[n=t] set ? 16
[n=h] set ? 19
set ! T
set ! H
set ? 21
set ! S
set ! T
set ? 21
set ! N
set ! D
set ? 12
set ! R
set ! D
> EOF

8
Task/Nth/Sidef/nth.sidef Normal file
View file

@ -0,0 +1,8 @@
func nth(n) {
static irregulars = Hash.new(<1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ 11 ᵗʰ 12 ᵗʰ 13 ᵗʰ>...);
n.to_s + (irregulars{n % 100} \\ irregulars{n % 10} \\ 'ᵗʰ');
}
[range(0, 25), range(250, 265), range(1000, 1025)].each { |r|
say r.map {|n| nth(n) }.join(" ");
}

29
Task/Nth/Swift/nth.swift Normal file
View file

@ -0,0 +1,29 @@
func addSuffix(n:Int) -> String {
if n % 100 / 10 == 1 {
return "th"
}
switch n % 10 {
case 1:
return "st"
case 2:
return "nd"
case 3:
return "rd"
default:
return "th"
}
}
for i in 0...25 {
print("\(i)\(addSuffix(i)) ")
}
println()
for i in 250...265 {
print("\(i)\(addSuffix(i)) ")
}
println()
for i in 1000...1025 {
print("\(i)\(addSuffix(i)) ")
}
println()

20
Task/Nth/XLISP/nth.xlisp Normal file
View file

@ -0,0 +1,20 @@
(DEFUN NTH (N)
(COND
((AND (> (MOD N 100) 3) (< (MOD N 100) 21)) `(,N TH))
((= (MOD N 10) 1) `(,N ST))
((= (MOD N 10) 2) `(,N ND))
((= (MOD N 10) 3) `(,N RD))
(T `(,N TH))))
(DEFUN RANGE (X Y)
(IF (<= X Y)
(CONS X (RANGE (+ X 1) Y))))
(DEFUN TEST-NTH ()
(DISPLAY (MAPCAR NTH (RANGE 1 25)))
(NEWLINE)
(DISPLAY (MAPCAR NTH (RANGE 250 265)))
(NEWLINE)
(DISPLAY (MAPCAR NTH (RANGE 1000 1025))))
(TEST-NTH)

17
Task/Nth/jq/nth.jq Normal file
View file

@ -0,0 +1,17 @@
# ordinalize an integer input, positive or negative
def ordinalize:
(if . < 0 then -(.) else . end) as $num
| ($num % 100) as $small
| (if 11 <= $small and $small <= 13 then "th"
else
( $num % 10)
| (if . == 1 then "st"
elif . == 2 then "nd"
elif . == 3 then "rd"
else "th"
end)
end) as $ordinal
| "\(.)\($ordinal)" ;
([range(-5; -1)], [range(0;26)], [range(250;266)], [range(1000;1026)])
| map(ordinalize)