nth.sf 340 B

123456789101112131415
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/N'th
  4. #
  5. func nth(n) {
  6. static irregulars = Hash.new(<1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ 11 ᵗʰ 12 ᵗʰ 13 ᵗʰ>...);
  7. n.to_s + (irregulars{n % 100} \\ irregulars{n % 10} \\ 'ᵗʰ');
  8. }
  9. [range(0, 25), range(250, 265), range(1000, 1025)].each { |r|
  10. say r.map {|n| nth(n) }.join(" ");
  11. }