首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印我的阻止计划

打印我的阻止计划
EN

Code Golf用户
提问于 2015-09-15 00:14:19
回答 2查看 352关注 0票数 11

我的高中和其他许多学校都实施了一种叫做旋转块计划的计划。这是一种让人们有8节课的方式,但在一天中有6节课。

一周中有四天时间重复一遍又一遍,与一周中的实际日子没有任何关系。每个人都分配了一个数字[1-4]

时间表的工作方式是列出所有上午的课程,周期为1-4[1, 2, 3, 4]。这是你第一天或第一天的日程安排,剩下的时间只需旋转列表:[2, 3, 4, 1][3, 4, 1, 2][4, 1, 2, 3]

然而,早上的最后一节课是“放弃”的,那天你看不到那个老师。因此,日子是:[1, 2, 3][2, 3, 4][3, 4, 1][4, 1, 2]

下午是一样的,只不过它使用句点5-8[5, 6, 7][6, 7, 8][7, 8, 5][8, 5, 6]

您的任务

所有这些旋转是很难保持跟踪,所以你必须写一个程序来打印出我的时间表,因为它是作为输入的哪一天。你的代码必须把教室和午餐放在正确的位置。下面是您的代码需要的输入1-4的确切输出:

代码语言:javascript
复制
Homeroom    Homeroom    Homeroom    Homeroom
Period 1    Period 2    Period 3    Period 4
Period 2    Period 3    Period 4    Period 1
Period 3    Period 4    Period 1    Period 2
Lunch       Lunch       Lunch       Lunch
Period 5    Period 6    Period 7    Period 8
Period 6    Period 7    Period 8    Period 5
Period 7    Period 8    Period 5    Period 6

,但是等等-还有一件事!

有时,在开学的第一天,或者在其他特殊的日子里,我的学校有一个“第0天”。这只是意味着我将在那天所有的课程,连同教室和午餐。您的代码必须处理第0天的S。这是第0天的输出:

代码语言:javascript
复制
Homeroom
Period 1
Period 2
Period 3
Period 4
Lunch
Period 5
Period 6
Period 7
Period 8

这是密码-高尔夫,所以最短的代码以字节为单位获胜!

EN

回答 2

Code Golf用户

发布于 2015-09-15 01:06:55

雪人1.0.2,190个字节

代码语言:javascript
复制
}vg10sB*:#NdE*!1*"Homeroom
"sP0vn3nR:|%+#nA4NmO'"Period "sP'!#nAtSsP"
"sP|%;ae|"Lunch
"sP5*|ae;:"Homeroom
"sP0vn4nR*#:`"Period "sP`NiNtSsP"
"sP;aE"Lunch
"sP#:`"Period "sP`5nAtSsP"
"sP;aE;#bI

最左边的那列看起来很不错,不是吗?

..。

..。我开玩笑的是谁,我宁愿用PHP编程,也不愿用这个。

“可读”版本:

代码语言:javascript
复制
}vg10sB*   // store day # in permavar
// big if statement coming up, depending on whether the input (n) is 0 or not

// THE FOLLOWING BLOCK IS FOR N != 0
:

#NdE*      // decrement number (because we like 0-based indeces) and re-store
!1*        // store the number 1 in permavar ! for later
"Homeroom
"sP        // print "Homeroom"
0vn3nR     // generate [0 1 2]
// for each element in this array...
:
    |%            // shuffle around some variables so we have room
    +#nA          // add day number (in permavar +)
    4NmO          // modulo by 4
    '"Period "sP  // print "Period "
    '!#nAtSsP     // add whatever is in permavar ! and print
    "
"sP               // print a newline
    |%            // return variables to their original state
;ae
// this is a rare occasion in which we use "ae" instead of "aE"
// we use non-consume mode here because we need the block again
// since we've used a permavar ! to determine what to add to the period number,
//   we can set the permavar to 4 more than it used to be and run the same
//   exact block
|"Lunch
"sP        // print "Lunch"
5*         // store the number 5 in permavar !, as described above
|ae        // run the same block over the same array again

;

// THE FOLLOWING BLOCK IS FOR N == 0

:

// after much frustration, I have determined that the easiest way to go about
//   this is to simply code the "day 0" separately
// yes, snowman is *that* bad
"Homeroom
"sP           // you know the drill
// for each number in [0 1 2 3]
0vn4nR*#:
    `"Period "sP
    `NiNtSsP  // increment and print
    "
"sP
;aE
"Lunch
"sP           // same stuff from here
// only interesting thing is we saved the range from before with *#, so we can
//   get it back easily
#:`"Period "sP`5nAtSsP"
"sP;aE

;

#bI

思想和思考:

  • 第一,我一定要用一种更漂亮的方法来打印新的线条。因为缩进块中带有换行符的字符串非常难看。
  • 我喜欢使用ae-you的技巧,很少会看到ae运算符没有真正的雪人代码大写的E。(你也很少看到不是我写的雪人代码,但这不是重点。)对于不熟悉的人来说,雪人有两种打电话给操作员的方式。“消费”模式和“非消费”模式。“消费”模式将使用所请求的变量调用操作符,然后丢弃变量。非消耗模式将调用操作符,并且仍然保持变量不变。这通常不是您想要的ae (数组-每个),因为您在每个元素上调用的块将停留在那里,并阻碍您的前进,消耗掉八个变量中的一个。然而,这是一种罕见的情况,在这种情况下,ae实际上是我们想要的(请参阅代码中的注释以获得进一步的解释)。
  • 我真的,真的开始认为雪人需要两种不同的模式,而不仅仅是“消费”和“不消费”。例如,使用aa (基本上是数组索引),您只能得到两种方法来调用它:“foo”0 -> “f” -> “foo”0“f” --您通常需要["foo" "f"] (即使用索引变量,而不是原始变量)。这是一个超级复杂的过程,如果您使用“不消费”模式,就可以摆脱这种烦人的0。在“不消费”模式下调用“数组-每个”时,也会发生类似的情况,就像这里所做的那样。数组和块保持不变,即使在执行所述块时也是如此。这是..。真的真的很奇怪。再说一遍,雪人的设计目标是尽可能的让人困惑,所以我不确定这是否是一个问题。
票数 3
EN

Code Golf用户

发布于 2015-09-15 16:24:10

Pyth,51字节

代码语言:javascript
复制
"Homeroom"j"Lunch
"c2jb+L"Period "+J?QP.<S4tQS4+L4J
票数 0
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/57954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档