Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,21 @@
@echo off
::Main thing...
call :Nth 0 25
call :Nth 250 265
call :Nth 1000 1025
pause
exit /b
::The subroutine
:Nth <lbound> <ubound>
setlocal enabledelayedexpansion
for /l %%n in (%~1,1,%~2) do (
set curr_num=%%n
set "out=%%nth"
if !curr_num:~-1!==1 (set "out=%%nst")
if !curr_num:~-1!==2 (set "out=%%nnd")
if !curr_num:~-1!==3 (set "out=%%nrd")
set "range_output=!range_output! !out!"
)
echo."!range_output:~1!"
goto :EOF

12
Task/Nth/Befunge/nth.bf Normal file
View file

@ -0,0 +1,12 @@
0>55*:>1-\:0\`!v
#v$#$<^:\+*8"}"_
>35*:>1-\:0\`!v
#v$#$<^:\+*2"}"_
5< v$_v#!::-<0*5
@v <,*>#81#4^# _
>>:0\>:55+%68*v:
tsnr |:/+ 55\+<,
htdd >$>:#,_$:vg
v"d"\*!`3:%+55<9
>%55+/1-!!*:8g,^

41
Task/Nth/C++/nth.cpp Normal file
View file

@ -0,0 +1,41 @@
#include <string>
#include <iostream>
using namespace std;
string Suffix(int num)
{
switch (num % 10)
{
case 1 : if(num % 100 != 11) return "st";
break;
case 2 : if(num % 100 != 12) return "nd";
break;
case 3 : if(num % 100 != 13) return "rd";
}
return "th";
}
int main()
{
cout << "Set [0,25]:" << endl;
for (int i = 0; i < 26; i++)
cout << i << Suffix(i) << " ";
cout << endl;
cout << "Set [250,265]:" << endl;
for (int i = 250; i < 266; i++)
cout << i << Suffix(i) << " ";
cout << endl;
cout << "Set [1000,1025]:" << endl;
for (int i = 1000; i < 1026; i++)
cout << i << Suffix(i) << " ";
cout << endl;
return 0;
}

View file

@ -7,6 +7,12 @@
(svref suffixes last-digit))))
(format nil "~a~a" number suffix)))
(defun add-suffix (n)
"A more concise, albeit less readable version"
(format nil "~d'~:[~[th~;st~;nd~;rd~:;th~]~;th~]" n (< (mod (- n 10) 100) 10) (mod n 10)))
(loop for (low high) in '((0 25) (250 265) (1000 1025))
do (progn
(format t "~a to ~a: " low high)

View file

@ -0,0 +1,20 @@
defmodule RC do
def ordinalize(n) do
num = abs(n)
ordinal = if rem(num, 100) in 4..20 do
"th"
else
case rem(num, 10) do
1 -> "st"
2 -> "nd"
3 -> "rd"
_ -> "th"
end
end
"#{n}#{ordinal}"
end
end
Enum.each([0..25, 250..265, 1000..1025], fn range ->
Enum.map(range, fn n -> RC.ordinalize(n) end) |> Enum.join(" ") |> IO.puts
end)

View file

@ -1,3 +1,2 @@
suf=: (;:'th st nd rd th'){::~4<.10 10(* 1&~:)~/@#:]
nth=: [:;:inv (":,suf)each
suf=: (;:'th st nd rd th') {::~ 4 <. 10 10 (* 1&~:)~/@#: ]
nth=: [: ;:inv (": , suf)each

View file

@ -0,0 +1,24 @@
console.log(function () {
var lstSuffix = 'th st nd rd th th th th th th'.split(' '),
fnOrdinalForm = function (n) {
return n.toString() + (
11 <= n % 100 && 13 >= n % 100 ?
"th" : lstSuffix[n % 10]
);
},
range = function (m, n) {
return Array.apply(
null, Array(n - m + 1)
).map(function (x, i) {
return m + i;
});
};
return [[0, 25], [250, 265], [1000, 1025]].map(function (tpl) {
return range.apply(null, tpl).map(fnOrdinalForm).join(' ');
}).join('\n\n');
}());

View file

@ -0,0 +1,5 @@
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th

View file

@ -0,0 +1,12 @@
function sprintfordinal{T<:Integer}(n::T)
const sfixes = ["st", "nd", "rd"]
0 <= n || throw(ArgumentError("number to be formatted must be ≥ 0, got $n"))
u = n%10
t = div(n, 10)%10
if 3 < u || u == 0 || t == 1
sf = "th"
else
sf = sfixes[u]
end
@sprintf "%d%s" n sf
end

View file

@ -0,0 +1,24 @@
println("Tests of ordinal formatting of integers.")
for (i, n) in enumerate(0:25)
if (i-1)%10 == 0
print("\n ")
end
print(@sprintf("%7s", sprintfordinal(n)))
end
println()
for (i, n) in enumerate(250:265)
if (i-1)%10 == 0
print("\n ")
end
print(@sprintf("%7s", sprintfordinal(n)))
end
println()
for (i, n) in enumerate(1000:1025)
if (i-1)%10 == 0
print("\n ")
end
print(@sprintf("%7s", sprintfordinal(n)))
end
println()

16
Task/Nth/Lua/nth.lua Normal file
View file

@ -0,0 +1,16 @@
function getSuffix (n)
local lastTwo, lastOne = n % 100, n % 10
if lastTwo > 3 and lastTwo < 21 then return "th" end
if lastOne == 1 then return "st" end
if lastOne == 2 then return "nd" end
if lastOne == 3 then return "rd" end
return "th"
end
function Nth (n)
return n .. "'" .. getSuffix(n)
end
for n = 0, 25 do
print(Nth(n), Nth(n + 250), Nth(n + 1000))
end

View file

@ -0,0 +1,14 @@
function nth($inp){
$suffix = "th"
switch($inp % 10){
1{$suffix="st"}
2{$suffix="nd"}
3{$suffix="rd"}
}
return "$inp$suffix "
}
0..25 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
1000..1025 | %{Write-host -nonewline (nth "$_")};""

15
Task/Nth/Python/nth-2.py Normal file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env python3
def ord(n):
try:
s = ['st', 'nd', 'rd'][(n-1)%10]
if (n-10)%100//10:
return str(n)+s
except IndexError:
pass
return str(n)+'th'
if __name__ == '__main__':
print(*(ord(n) for n in range(26)))
print(*(ord(n) for n in range(250,266)))
print(*(ord(n) for n in range(1000,1026)))

View file

@ -1,4 +1,4 @@
fn nth(num: int) -> String {
fn nth(num: i32) -> String {
format!("{}{}", num, match (num % 10, num % 100) {
(1, 11) => "th",
(1, _) => "st",
@ -12,13 +12,13 @@ fn nth(num: int) -> String {
fn main() {
let ranges = vec![
(0i, 26i),
(250i, 266i),
(1000i, 1026i)
(0, 26),
(250, 266),
(1000, 1026)
];
for &(s, e) in ranges.iter() {
println!("[{}, {}) :", s, e);
for i in range(s, e) {
for i in s..e {
print!("{}, ", nth(i));
}
println!("");