在这个挑战中,我们只考虑love和hate作为感觉。如果我们想表达顺序N的情感表达,我们可以在这两者之间交替使用(从hate开始):
order | expression
1 I hate it.
2 I hate that I love it.
3 I hate that I love that I hate it.
4 I hate that I love that I hate that I love it.对于每个正整数N,模式如下。给定N,输出顺序N的相关情感表达式。
.)是强制性的,N的输出未定义,发布于 2016-08-31 10:21:52
lambda n:("I hate that I love that "*n)[:12*n-5]+"it."发布于 2016-08-31 10:28:22
ri{"hatlov"3/='IS@"e that "}/2<"it."在网上试试!
ri e# Read input and convert to integer N.
{ e# For each i from 0 to N-1...
"hatlov"3/ e# Push ["hat" "lov"].
= e# Use i as a cyclic index into this array to alternate between
e# "hat" and "lov".
'IS e# Push character 'I' and a space.
@ e# Pull "hat" or "lov" on top of it.
"e that " e# Push "e that "
}/
2< e# Truncate the last "e that " to just "e ".
"it." e# Push "it."发布于 2016-08-31 11:22:20
i->{for(int j=0;j++<i;)System.out.printf("I %se %s",j%2>0?"hat":"lov",j<i?"that ":"it.");};public static void main(String[] args) {
Consumer<Integer> c = i -> {
for (int j = 0; j++ < i;) {
System.out.printf("I %se %s", j % 2 > 0 ? "hat" : "lov", j < i ? "that " : "it.");
}
};
c.accept(1);
c.accept(2);
c.accept(3);
}https://codegolf.stackexchange.com/questions/91797
复制相似问题