头,肩膀,膝盖和脚趾,膝盖和脚趾


31

介绍:

我想我们都知道,并且它可能已翻译成多种语言:“儿童的头部,肩膀,膝盖和脚趾”儿童歌曲:

头部,肩膀,膝盖和脚趾,膝盖和脚趾
头部,肩膀,膝盖和脚趾,膝盖和脚趾
以及眼睛和耳朵以及嘴和鼻子
头部,肩膀,膝盖和脚趾,膝盖和脚趾
维基百科


挑战:

输入:一个正整数。

输出:根据输入作为第n个索引输出以下单词之一:

head
shoulders
knees
toes
eyes
ears
mouth
nose

在这里,主体部分附加了索引:

Head (0), shoulders (1), knees (2) and toes (3), knees (4) and toes  (5)
Head (6), shoulders (7), knees (8) and toes (9), knees (10) and toes (11) 
And eyes (12) and ears (13) and mouth (14) and nose (15)
Head (16), shoulders (17), knees (18) and toes (19), knees (20) and toes (21)

Head (22), shoulders (23), knees (24) and toes (25), knees (26) and toes  (27)
Head (28), shoulders (29), knees (30) and toes (31), knees (32) and toes (33) 
And eyes (34) and ears (35) and mouth (36) and nose (37)
Head (38), shoulders (39), knees (40) and toes (41), knees (42) and toes (43)

etc.

挑战规则:

  • 您当然可以使用1索引输入而不是0索引输入。但是,请指定您在答案中使用的哪一个。
  • 输出是不区分大小写的,因此,如果要以大写形式输出,就可以了。
  • 您应该支持至少1,000个输入。

一般规则:

  • 这是,因此最短答案以字节为单位。
    不要让代码高尔夫球语言阻止您发布使用非代码高尔夫球语言的答案。尝试针对“任何”编程语言提出尽可能短的答案。
  • 标准规则适用于您的答案,因此允许您使用STDIN / STDOUT,具有适当参数的函数/方法,完整程序。你的来电。
  • 默认漏洞是禁止的。
  • 如果可能,请为您的代码添加一个带有测试的链接。
  • 另外,如有必要,请添加说明。

测试用例(0索引):

Input:  Output:
0       head
1       shoulders
7       shoulders
13      ears
20      knees
35      ears
37      nose
98      knees
543     nose
1000    knees

3
添加了kolmogorov复杂性标签,因为大多数答案可能会将输入用作常量数组的循环索引,常量数组的生成将主导字节数。
马丁·恩德

@MartinEnder谢谢。我不正确地只将kolmogorov-complexity答案用于始终具有相同固定输出的答案,但是现在我看到的是代码中固定输出字符串,并找到用于匹配的模式(或像@Enigma的05AB1E answer一样对其进行编码)。感谢您添加它;我不太确定与该挑战​​相关的标签是什么,这是我在“沙箱”中(不幸的是未得到回答)的问题之一。
凯文·克鲁伊森


1
@KevinCruijssen至少您的问题遇到了+1:)(乐观的评论),您可以使用来在沙箱中搜索inquestion:2140 shoulders
暴民埃里克(Erik the Outgolfer)

3
有人整天都把这首歌留在他们的头上吗?...
Kevin Cruijssen

Answers:


12

05AB1E36 35 34字节

“‡ä¾ØsÏ©s¸±s“#2䤫Г—íÖÇ©¢ÄÓ#s)˜è

在线尝试!或作为测试套件

说明

“‡ä¾ØsÏ©s¸±s“                        # dictionary string 'head shoulders knees toes'
             #                       # split on spaces
              2ä                     # split in 2 parts
                ¤                    # get the last part ['knees', 'toes']
                 «                   # concatenate and flatten
                                     # STACK: [['head', 'shoulders'], ['knees', 'toes'], 'knees', 'toes']
                  Ð                  # triplicate
                   “—íÖÇ©¢ÄÓ        # dictionary string 'eyes ears mouth nose'
                             #s      # split on spaces and swap top 2 elements of stack
                               )˜    # wrap stack in a list and flatten
                                 è   # index into list with input

简而言之,我们构建列表 ['head', 'shoulders', 'knees', 'toes', 'knees', 'toes', 'head', 'shoulders', 'knees', 'toes', 'knees', 'toes', 'eyes', 'ears', 'mouth', 'nose', 'head', 'shoulders', 'knees', 'toes', 'knees', 'toes']并使用输入(0索引)对其进行索引。


4
@KevinCruijssen:即将有一个解释:)对于高尔夫语言imo这是非常强制的。
Emigna '16

‡ä¾ØsÏ©s¸±s考虑到每个单词都是2个字符,这看起来很奇怪。还有吗
暴民埃里克(Erik the Outgolfer)

2
@EriktheGolfer:是的,s那里的3 是要复数的shoulder, knee, toe,在字典中是单数。我们不需要with,eyes, ears因为它们已经在字典中被复数了,因此字符串具有预期的偶数长度。
Emigna '16

哦,他们把我弄糊涂了。谢谢。
暴民埃里克

31

JavaScript(ES6),91 88 87字节

n=>'knees,toes,head,shoulders,eyes,ears,mouth,nose'.split`,`[(245890>>(n%22&~1))&6|n%2]

怎么运行的

我们有4对不同的单词总是在一起出现:“ head”后面总是“ shoulders”,“ knees”后面总是“ toes”,依此类推。

因此,我们可以使用以下索引:

00: [ 'knees', 'toes' ]
01: [ 'head', 'shoulders' ]
10: [ 'eyes', 'ears' ]
11: [ 'mouth', 'nose' ]

并将整个序列(以相反的顺序)压缩为以下二进制掩码:

00 00 01 11 10 00 00 01 00 00 01

我们使用[ 'knees', 'toes' ]第一个对来获得尽可能多的前导零。

我们对该序列进行额外的填充,0以便将提取的值预乘以2,从而得出:

0b00000111100000010000010 = 245890

因此,正确单词的最终公式为:

(245890 >> (n % 22 & ~1)) & 6 | n % 2

测试用例


10

Python 2中,158个 148 137 128 114 109 104字节

查找表似乎更好。还缩短了大弦并重新排序了项目。-5个字节,感谢Rod使用字符串作为列表。

c=int('602323'*2+'4517602323'[input()%22])
print"smkteehnhonoyaeooueeerasutesssdelhs"[c::8]+"ders"*(c<1)

初始解决方案:

n=input()%22
n-=10*(n>15)
if n>=12:n-=8
else:n%=6;n-=2*(n>3)
print"hskteemnehnoyaooaoeeerusduessste ls   h  d       e       r       s"[n::8].strip()

1
很原始的答案!+1。但是,嗯,使用完整字符串的大多数答案都比这短。不过,我还是喜欢您花钱买的在琴弦上看到某种花纹的!开头语。
凯文·克鲁伊森

我认为您可以通过以下方式使这个肩膀变弦:hskteemnehnoyaooaoeeerusduessste ls h d如果您知道单词应该是“肩膀”,则可以附加“ ers” :)
Kade

1
您可以使用c c=int('602323'*2+'4517602323'[input()%22])放下h
Rod

1
[i%22]在第一个,[input()%22]第二个上
Rod

1
@Rod抱歉,如果您对代码的查看时间足够长,则会变得盲目。
Karl Napf

6

Perl,74个字节

73字节代码+ 1 for -p

$_=(@a=(head,shoulders,(knees,toes)x2),@a,eyes,ears,mouth,nose,@a)[$_%22]

使用基于0的索引。不输出分隔符,但是可以-l在标志中进行修改。

在线尝试


您可以保存1个字节,x2)x2而不是x2),@a
Adam

4

Python 2,97 90字节

可能需要做一些数学运算,所以我不必列出单词列表,但这暂时有效!

lambda n,k='head shoulders '+'knees toes '*2:(k*2+'eyes ears mouth nose '+k).split()[n%22]

感谢Flp.Tkc节省了7个字节:)


1
我有一个类似的解决方案,但习惯于split()将其缩短:k='head shoulders '+'knees toes '*2 print(k*2+'eyes ears mouth nose'+k).split()[input()%22]
FlipTack

抱歉,“鼻子”后面应该有一个空格:)
FlipTack

@ Flp.Tkc是的,我刚刚意识到:)正在更新中!
卡德

4

Java 7中,155个 137 131 123 111 110字节

String c(int i){return"knees,toes,head,shoulders,eyes,ears,mouth,nose".split(",")[(245890>>(i%22&~1))&6|i%2];}

-12个字节感谢@Neil
通过无耻地创建@Arnauld的惊人答案的端口-1字节。

Java是0索引的,所以这就是我所使用的。

取消测试代码:

在这里尝试。

class M{
  static String c(int i){
    return "knees,toes,head,shoulders,eyes,ears,mouth,nose".split(",")
      [(245890>>(i%22&~1))&6|i%2];
  }

  public static void main(String[] a){
    System.out.println(c(0));
    System.out.println(c(1));
    System.out.println(c(7));
    System.out.println(c(13));
    System.out.println(c(20));
    System.out.println(c(35));
    System.out.println(c(37));
    System.out.println(c(98));
    System.out.println(c(543));
    System.out.println(c(1000));
  }
}

输出:

head
shoulders
shoulders
ears
knees
nose
ears
knees
nose
knees

1
String c(int i){return "head,shoulders,knees,toes,knees,toes,eyes,ears,mouth,nose".split(",")[(i+16)%22%16%10];}只有112个字节。
尼尔

如果您尝试从注释中复制,则会得到Stack Exchange的一些额外的不可见字节。
尼尔

@Neil好的,我是个白痴。.不知道昨天晚上我怎么计数120粗糙。.可能为时已晚..>>空间),所以谢谢!
凯文·克鲁伊森

3

C,153字节 141字节

*b[]={"head","shoulders","knees","toes","eyes","ears","mouth","nose"};i;char*g(a){a%=22;i=(a+4)%10;return b[a<4?a:(a&12)>8?a-8:i<2?i:a%2+2];}

感谢@cleblanc提供了4个字节。在全局范围内声明b会引发关于将其强制转换为int的大量警告,但对我而言并没有破坏。

取消高尔夫:

*b[]={"head","shoulders","knees","toes","eyes","ears","mouth","nose"};
i;
char* g(a) {
    a%=22;
    i=(a+4)%10;
    return b[a < 4        ? a
            :(a & 12) > 8 ? a-8
            :i < 2        ? i
            :               a % 2 + 2];
}

这不是最小的答案,但是我喜欢这种技术,并且很有趣地找到了一些模式。

变更日志:

  • 移至b全局以避免char(4个字节)
  • a > 11 && a < 16=> (a & 12) > 8(2个字节)
  • i=(a-6)%10=> i=(a+4)%10这样i < 2 && i >= 0=> i < 2(6个字节)

1
You can golf this down a bit further. By moving b[] to a global scope it can be declared without using char* like this *b[]={"head","shoulders","knees","toes","eyes","ears","mouth","nose"},i' and then replace the return b[...] with a puts(b[...]) you can get it down to 143 bytes
cleblanc

+1 And in addition to @cleblanc's suggestion, you can also change both && to &.
Kevin Cruijssen

I'm curious how @cleblanc suggestion about declaring b globally works. The compiler told me it would be an *int[], and I thought that the size difference would break the code. It didn't though, so thanks!
nmjcman101

2

JavaScript (ES6) 91 89 Bytes

f=
n=>((d='head:shoulders:'+(b='knees:toes:')+b)+d+'eyes:ears:mouth:nose:'+d).split`:`[n%22]

console.log(f.toString().length)
console.log(f(0) === 'head')
console.log(f(1) === 'shoulders')
console.log(f(7) === 'shoulders')
console.log(f(13) === 'ears')
console.log(f(20) === 'knees')
console.log(f(35) === 'ears')
console.log(f(37) === 'nose')
console.log(f(98) === 'knees')
console.log(f(543) === 'nose')
console.log(f(1000) === 'knees')


1
Nice! +1. When I port your answer to Java 7 it's a solid -7 bytes compared to @Arnauld's already-shorter-than-mine answer. ;) Thanks!
Kevin Cruijssen

1
I saved a byte by being creative with my use of %: n=>`head:shoulders:knees:toes:knees:toes:eyes:ears:mouth:nose`.split`:`[(n+16)%22%16%10].
Neil

2

R, 95 bytes

c(o<-c("head","shoulders",y<-c("knees","toes"),y),o,"eyes","ears","mouth","nose",o)[scan()%%22]

Creates a character vector to function as a lookup table. Takes input from stdin (1-indexed) and %%22 to find the corresponding body part.

Bonus: %% is vectorized which means that this will work with a vector inputs as well.

Test cases on R-fiddle (Note that this is a named function because scan doesn't work on R-fiddle)


2

jq, 80 characters

(77 characters code + 3 characters command line option)

((("head shoulders "+"knees toes "*2)*2+"eyes ears mouth nose ")*2/" ")[.%22]

Sample run:

bash-4.3$ jq -r '((("head shoulders "+"knees toes "*2)*2+"eyes ears mouth nose ")*2/" ")[.%22]' <<< 1000
knees

On-line test (Passing -r through URL is not supported – check Raw Output yourself.)


2

WinDbg, 207 157 151 bytes

ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41

-50 bytes by encoding the offset/length of the body parts as ascii chars.

-6 bytes by using a local var when looking up the offset/length.

Input is done with a value set in the pseudo-register $t0.

How it works:

* Initialization, writes this string at address 0x2000000. The nonsense after the body parts
* are the offsets and lengths of the body parts in the first part of the string, each of
* which is incremented by 0x41 to make it a printable ascii character.
ea 2000000 
        "headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";


* Display the output:
r$t4=(@$t0%16)*2+2000027
da1FFFFBF+by(@$t4) Lby(@$t4+1)-41

* Display output explanation:
r $t4 = (@$t0%16)*2+2000027   * Set $t4 = input, @$t0, mod 22, doubled +0x2000027
by(@$t4)                      * byte_at(@$t4)-0x41 is the {Offset} into the string 
                              * for the start of output. The -0x41 is already subtracted
                              * from 0x2000000 to make 0x1FFFFBF.
Lby(@$t4+1)-41                * byte_at(@$t4+1)-0x41 is the {Length} of the output.
da 1FFFFBF+{Offset} L{Length} * Display {Length} chars from {Offset} of the above string.

Sample output:

0:000> r$t0=0
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
02000000  "head"


0:000> r$t0=1
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
02000004  "shoulders"


0:000> r$t0=7
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
02000004  "shoulders"


0:000> r$t0=0n13
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
0200001a  "ears"


0:000> r$t0=0n20
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
0200000d  "knees"


0:000> r$t0=0n35
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
0200001a  "ears"


0:000> r$t0=0n37
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
02000023  "nose"


0:000> r$t0=0n98
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
0200000d  "knees"


0:000> r$t0=0n543
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
02000023  "nose"


0:000> r$t0=0n1000
0:000> ea2000000"headshoulderskneestoeseyesearsmouthnoseAEEJNFSENFSEAEEJNFSENFSEWE[E_FdEAEEJNFSENF";r$t4=(@$t0%16)*2+2000027;da1FFFFBF+by(@$t4) Lby(@$t4+1)-41
0200000d  "knees"

2

PHP, 91 102 118 128 129 Bytes

<?=[head,shoulders,knees,toes,eyes,ears,mouth,nose]['0123230123234567012323'[$argv[1]%22]];

0-Indexed

Down to 91 following removal of str_split, didn't realise PHP string were accessible as a char array (a PHP 5+ thing?)

Down to 102 thanks to insertusername suggestion for removing string quotes and allowing the notices


-16 bytes: remove all ' around words, like 'head' becomes head etc.
insertusernamehere

Not sure what the rules are with this, but with a default PHP install, I get the expected undefined constant warnings when doing that
CT14.IT

1
Yes, but this is absolutely fine with the site's rules. Notices and warnings can be ignored.
insertusernamehere

@CT14.IT, that is not a warning, is a notice. “PHP 5.3 or later, the default value is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED. This setting does not show E_NOTICE, E_STRICT and E_DEPRECATED level errors.” – PHP documentation about error_reporting.
manatwork

1
It seems that str_split() is useless
Crypto

1

Jelly, 55 bytes

“¥ḷne“¥ṇṭḲ»ẋ2ṭ“¢1$“@⁼5⁼»µẋ2;“¥ḳVo“¥ḳ'k“£Qo“£³ạ»;⁸FḊḲ
ị¢

Try it online! (1-based index)

Come on! Really?

As a bonus, this is the compressed string I was supposed to use instead of the top line:

“¡¦ṡb[wfe=⁺żɦ4Gƈġhḳ"ẇ⁴ż>oH¹8ṡʠʠḟṀUṿḶ>¬Þ:ĖẇrṗṁɼlDṫỤ¬ȷ⁶Dḥci*⁻³GḲOÞạṖṃ\»

Both encode this string:

head shoulders knees toes knees toes head shoulders knees toes knees toes eyes ears mouth nose head shoulders knees toes knees toes

Guess I should go exercise now :P


1

Powershell, 91 Bytes, Zero-Indexed

$a='head shoulders '+'knees toes '*2;($a*2+'eyes ears mouth nose '+$a).Split()[$args[0]%22]

Very straightforward approach, generate the array of the first 22 items using some string multiplication where possible, by compiling them with spaces and splitting at the end. (splitting is 2 bytes shorter than the equivalent setup as an array) then just find the point in that array using the modulus of the input, not exactly interesting or language-specific.

Test Case:

PS C:\++\golf> 0..1000|%{.\hskt $_}
head
shoulders
knees
toes
knees
toes
head
shoulders
knees
toes
knees
toes
eyes
ears
mouth
nose
head
shoulders
knees
toes
knees
toes
head
shoulders
knees
toes
....

etc.


1

ruby, 81 bytes

Lambda function using zero indexing.

->n{("head shoulders#{" knees toes "*2}eyes ears mouth nose".split*2)[n%22-6&15]}

explanation

We generate the following array, of which we use the first 16 elements, covering the correct lines 2,3,4 of the song:

%w{head shoulders knees toes knees toes
   eyes ears mouth nose
   head shoulders knees toes knees toes

   eyes ears mouth nose}                  #last 4 elements not used

We take n modulo 22 to reduce it to a single verse, then we subtract 6. Now the index 6 (for example) has been changed to 0 and points to the right word. Indicies 0..5 which point to the first line of the song are now negative. We use &15 (identical to %16 but avoids the need for brackets) to map the 1st line of the song to the 4th line. Thus index 0 -> -6 -> 10

in test program

f=->n{("head shoulders#{" knees toes "*2}eyes ears mouth nose".split*2)[n%22-6&15]}

#call as below to test index 0..43
44.times{|i|p f[i]}

Interesting index formula. But the same length can be achieved without it: ->n{(((%w{head shoulders}+%w{knees toes}*2)*2+%w{eyes ears mouth nose})*2)[n%22]}
manatwork

1

Befunge, 129 119 bytes

0-indexed

&29+2*%:2/v>00p>%#7_v
+%2\-"/"g2<|<:-1g007<"head*shoulders*knees*toes*eyes*ears*mouth*nose"p00
02202246022>$$:>7#:%#,_@

Try it online!

Explanation

As Arnauld pointed out, the words come in pairs, so we have an index of just 11 values and then add the word number % 2 to get the appropriate word in the pair. The words are pushed onto the stack as a single string separated by asterisks to save space. We test for word breaks by taking the char value modulo 7, since only the asterisk is a multiple of 7.

&29+2*%               n = getint() % 22             // % 22 to ensure it's in range
:2/2g                 i = index_array[n/2]          // we use n/2 because words are paired
-"/"                  i -= '/'                      // convert from ASCII to 1-based value
\2%+                  i += n%2                      // get the correct word in the pair
00p                   index = i                     // save for later

"head*shoulders*knees*toes*eyes*ears*mouth*nose"    // push all the words onto the stack

700g1-:|              while (index-1 != 0) {        // the 7 is used in the drop loop   
  00p                   index = index-1             
  >%#7_                 do while (pop() % 7)        // drop up to the next '*' (%7==0)
                      }                    

$$                    pop();pop()                   // get rid of index and extra 7

: 7 % _               while ((c = pop()) % 7)       // output up to the next '*' (%7==0)
 > : ,                  putchar(c)

1

SQL 2005 747 Bytes

Golfed:

GO
CREATE PROCEDURE H @n INT AS BEGIN IF NOT EXISTS(SELECT*FROM R)BEGIN INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('eyes')INSERT INTO R VALUES('ears')INSERT INTO R VALUES('mouth')INSERT INTO R VALUES('nose')INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')END SELECT W FROM R WHERE I=@n%22 END

Ungolfed:

GO
CREATE PROCEDURE H
@n INT 
AS 
BEGIN IF NOT EXISTS(SELECT*FROM R)
BEGIN 
INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('eyes')INSERT INTO R VALUES('ears')INSERT INTO R VALUES('mouth')INSERT INTO R VALUES('nose')INSERT INTO R VALUES('head')INSERT INTO R VALUES('shoulders')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')INSERT INTO R VALUES('knees')INSERT INTO R VALUES('toes')
END 
SELECT W FROM R WHERE I=@n%22 END

Needs a table like this, where the first column is auto-incremented:

enter image description here

This is a one-indexed answer. The table is populated the first time stored procedure is created - it wouldn't let me do all the INSERT in one statement, disappointingly, this feature is only available in >=SQL 2008. After this, it uses the %22 trick from the other answers. Once the table has been populated, it only uses the last part:

SELECT W FROM R WHERE I=@n%22

Input:  Output:
R 1       head
R 2       shoulders
R 8       shoulders
R 14      ears
R 21      knees
R 36      ears
R 38      nose
R 99      knees
R 54      nose
R 1001    knees

"it wouldn't let me do all the INSERT in one statement" why? Shouldn't something like this be possible in SQL after 2008?
Kevin Cruijssen

@KevinCruijssen I'm using SQL Server 2008 R2, so it is strange... I've just done some more Googling, apparently it's something to do with the "Compatibility Level" of the database, which I've just tried and failed to change - it's set to 2005 and this is the max value, so it hasn't got this feature. Should I either, specify the SQL version in my answer, or delete the answer if it can't be shortened properly? Gutted as that would save me a lot of text...
Pete Arden

Either is fine by me, so it's your call. I personally usually golf in Java 7 which I specify, because in most cases shorter answers are available in Java 8. You could specify it's 2005 in the same way.
Kevin Cruijssen

@KevinCruijssen Yeah, I've seen people doing that for Java and Python. Wouldn't really like to make the change without being able to test the code either, so I'll specify 2005, cheers :)
Pete Arden

1

bash (with ed), 83 chars

1-indexed

ed<<<"a
head
shoulders
knees
toes
eyes
ears
mouth
nose
.
3,4t4
1,6y
6x
$(($1%22))"

Sample call:

 $ bash test.sh 1001
 knees

1

dc, 135 bytes

6[head]6[:add6-r;ar:adA+r;ar:a]dshx7[shoulders]7lhx8[knees]8lhxA 2;aAlhx9[toes]9lhxB 3;aBlhx[eyes]C:a[ears]D:a[mouth]E:a[nose]F:a22%;ap

Try it online!

Arrays in dc have to be built an element at a time, which takes up the brunt of this exercise. Since 'eyes', 'ears', 'mouth', and 'nose' only appear once in our array, we just pop them in. But for the others, we save a few bytes by putting them on the stack like x[head]x, where x is the middle of its three values, then we run the macro [:add6-r;ar:adA+r;ar:a]dshx to put it in the array, pull it back, put it in at the same value less six, pull it back, and then put it in one last time at the original value plus ten. We use the middle value because dc allows us to use hex digits even in decimal mode, and subtracting A is one less byte than adding 16 - this also only works because all of the middle values are under fifteen. We have to do knees and toes twice, and making our macro smart enough to sort that out is more expensive than just running the macro twice; but we do save bytes here by loading a previously stored copy of the string instead of writing it out again (B 3;aB vs. B[toes]B - I think this saves 3 bytes total).

Once we have the array built, all we need to do is 22% and then ;ap to pull it from the array and print.


0

C#6, 138 bytes

string F(int i)=>(i+10)%22<4?"eyes,ears,mouth,nose".Split(',')[(i+10)%22%4]:"head,shoulders,knees,toes,knees,toes".Split(',')[(i+6)%22%6];

repl.it demo

Ungolfed + comments:

string F(int i)=>
    // Is it eyes/ears/mouth/nose?
    (i+10)%22<4
        // If yes, then set index to 4-word line and take modular 4
        // String array constructed by splitting comma-delimited words
        ? "eyes,ears,mouth,nose".Split(',')
            [(i+10)%22%4]
        // Else set index to last 6-word line and take modular 6
        : "head,shoulders,knees,toes,knees,toes".Split(',')
            [(i+6)%22%6];

You could combine the string and use a single Split, and have your same check as ternary (?:) inside the square-brackets (with +4 for the second part), like this: string F(int i)=>"eyes,ears,mouth,nose,head,shoulders,knees,toes,knees,toes".Split(',')[(i+10)%22<4?(i+10)%22%4:(i+6)%22%6+4]; (126 bytes)
Kevin Cruijssen

0

Excel, 146 bytes

=MID("Head     ShouldersKnees    Toes     Eyes     Ears     Mouth    Nose",CHOOSE(MOD(MOD(MOD(B1+16,22),16),10)+1,1,10,19,28,19,28,37,46,55,64),9)

Uses @Neil's MOD(MOD(MOD(B1+16,22),16),10) to save 15 bytes.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.