为我的Scan-tron分级!


10

标准化测试通常带有scan-tron或记录您答案的某种类型的答案文档。然后,计算机或人员将检查您的答案并确定您的成绩。因此,在这里,给定scan-tron和答案键,即可确定分数和错过的问题(如果有)。scan-tron只是具有多行答案的文档,用户可以在其中填写(在本例中为带圆圈的)答案。例:

   ---
1. |a| b c d
   --- 

如您所见,这是选择了答案选择的问题1,a因为它周围有一个框。对于挑战,你将得到一个扫描-TRON与n问题(1 <= n <= 10),只有四个答案表示为abc,或d。答案键将以无空格且全部小写的字符串形式给出。带有答案键的示例scan-tron:

Scan-tron
   ---
1. |a| b c d
   ---
     ---
2. a |b| c d
     ---
       ---
3. a b |c| d
       ---

Answer Key
abb

您可以将答案键和scan-tron作为单独的输入或以选定的顺序输入,只要它们可以被识别(即,答案键与scan-tron分开)即可。分数将四舍五入到最接近的十分之一。上面的示例输出:

Score: 66.7
Missed #: 3

其他可接受的答案是:

66.7 
3

或者错过了多个问题

66.7
3 4 5

只要错过的问题编号与空格之间用空格分隔,并且与分数不在同一行。

规则和规格

  • 可以将scan-tron输入为多行字符串或一次输入一个问题(因为可以使用带换行符的字符串)
  • 给定一个scan-tron和Answer键,您必须在一行上输出分数,而在另一行上输出遗漏的问题,数字之间用空格分隔。如果没有遗漏任何问题,则不应输出任何问题编号
  • 分数四舍五入到最接近的十分之一
  • 所选答案被此框包围:

    ---
    | |
    ---
    
  • 在scan-tron上,每个问题都占用三个空格(方框的顶部和底部占用额外的两行)
  • 必须为上述示例工作
  • 假设总是只装一个答案

获奖标准

最短的代码胜出!


scan-tron可以是问题列表吗?每个问题都是带换行符的单个字符串?
Rod

@Rod是的,我将澄清一下
安东尼·

2
“未命中”的语言令我感到困惑,因为“未命中”的问题可能意味着学生未能回答问题(与您的明显意思相反,回答不正确)。
DLosc

@DLosc永远只有一个圈出的答案
Anthony Pham

分数是否50可以接受,还是一定要50.0
DLosc

Answers:


2

05AB1E,43个字节

U|3ôø`\vyy'|k>èXNèQˆ}¯OXg/3°*2z+ïT/XgL¯_Ï‚»

在线尝试!

说明

U                                            # store the answer key in X
 |3ô                                         # split the question-rows in chunks of 3
    ø`                                       # zip and flatten
      \                                      # discard top of stack, leaving the list of
                                             # answer rows on top
       v                                     # for each answer row
         y'|k                                # get the index of the first "|"
        y    >è                              # get the character after that from the row
               XNèQ                          # compare it to the corresponding entry in 
                                             # the answer key
                   ˆ                         # add it to the global list
                    }                        # end loop
                     ¯O                      # calculate the number of correct answers
                       Xg/                   # divide by the length of the answer key
                          3°*                # multiply by 1000
                             2z+             # add 0.5
                                ï            # convert to integer
                                 T/          # divide by 10
                                   XgL       # push range [1 ... len(answer key)]
                                      ¯_Ï    # keep only numbers corresponding to 
                                             # wrong answers
                                          ‚» # format output

4

堆叠,68 +1 = 69字节

'|'split[#'1-]NO neq::size:@z~>*[]YES' '#`out is0 sum z/100*1 nround

在线尝试!-p标记为+1 (此脚本可以执行为stacked -pe "..."

从堆栈的顶部获取两个输入。

一些有趣的功能:

[#'1-]NO
[    ]NO   do not keep members where
 #'          its length
   1-          -1
             is truthy (in this case, not equal to zero).

这将产生所有被管道包围的字母。

:size:@z~>*[]YES
:                 duplicate indices of incorrect answers
 size             length of incorrect answers
     :@z          (stored into z)
        ~>        range from 1 to this length
          *       and multiply by this range
           []YES  keep truthy elements

这给我们所有不正确的问题编号。


3

Python 2中94 93个字节

-1个字节感谢L3viathan

s,a=input()
l=len(s)
w=[i+1for i in range(l)if"|%s|"%a[i]not in s[i]]
print(l-len(w))*1e2/l,w

在线尝试!


很好,比我的好得多。您可以替换100.1e2
L3viathan,2017年

我不认为这符合将分数四舍五入至“最接近的十分之一”的要求,对吗?
DLosc

3

49 46 44 48 45字节

gh,舍入需要这么多字节... 44个字节的代码,-s标志为+1 。

(/2+m-m/#b*#P_FI{++nbNa?un}MZa@`\|..`b)//1/t

将输入作为命令行参数(如果从实际命令行运行,scan-tron页面将需要引用和转义换行符)。首先输出遗漏的问题,然后输出分数。在线尝试!

说明

我将分为两个部分:错误的问题清单和分数。

P_FI{++nbNa?un}MZa@`\|..`b
                            a,b are cmdline args, u is nil, n is newline (implicit)
                            Note that a string like n, in math contexts, is equivalent to 0
                 a@`\|..`   Find all occurrences in a of | followed by 2 chars
                            Because regex matches don't overlap, this does what we need
    {         }MZ        b  Zip with b and map this function to each pair of items:
     ++n                     Increment n (so the first time through, it's 1)
        bNa                  Is 2nd arg a substring of 1st?
           ?un               If so, return nil; if not, return n
                            Now we have a list containing nil for correct questions
                            and the question number for incorrect questions
 _FI                        Filter on identity function (keep only truthy values)
P                           Print, joining on spaces (-s flag)

(/2+m-m/#b*#...)//1/t
                       a,b are cmdline args, m is 1000 (implicit)
            ...        The code from the first part
           #           Length of that list (i.e. number of incorrect questions)
      m/#b*            Times 1000/(number of questions)
    m-                 Subtracted from 1000
 /2+                   Plus 1/2 (= 0.5)
                       We now have a number like 667.1666666666667
(              )//1    Int-divide by 1 to truncate
                   /t  and divide that by 10
                       Print (implicit)

2

JavaScript(ES6),88个字节

x=>y=>x.replace(/\w(?=\|)/g,c=>c==y[i++]?t++:a+=i+" ",a=i=t="")&&(t/i*1e3+.5|0)/10+`
`+a

通过使用逗号并返回所有内容,我可以节省5个字节:

x=>y=>x.replace(/\w(?=\|)/g,c=>c==y[i++]?t++:a+=[,i],a=i=t="")&&(t/i*1e3+.5|0)/10+a

1

批处理,242字节

@echo off
set/as=c=0
set m=
set/pk=
:l
set/ac+=1
set/pt=
set/pl=
set/pt=
set "l=%l:*|=%
if %l:~,1%==%k:~,1% (set/as+=1)else set m=%m% %c%
set k=%k:~1%
if not "%k%"=="" goto l
set/as=(s*2000/c+1)/2
echo(%s:~,-1%.%s:~-1%
echo(%m%

首先读取STDIN上的答案键,然后读取n*3问题行。注意:如果分数小于,则打印分数时不带前导零1.0。遗漏的答案带有前置空格。


0

CJam47 45字节

lqN/(;3%_'|f#:).=.=__:+\,d/e2XmOn:!_,,:).*0-p

在线尝试!

说明

该程序分为三个主要部分:

Right/wrong list

l                    e# Read the first line of input (answer key)
 qN/                 e# Read the rest of the input and split it on newlines
    (;3%             e# Delete the first line, then select every 3rd line 
        _            e# Duplicate the array
         '|f#        e# Find the index of the first | in each answer
             :)      e# Increment each, gives the index of the selected letter for each answer
               .=    e# Vectorized get-element-at with the answer strings
                 .=  e# Vectorized equality check with the answer key

在本节之后,我们有一个由0s和1s组成的数组,其中0表示错误的答案和1正确的答案。

Score

__              e# Duplicate the right/wrong list twice
  :+            e# Take the sum of it (number of right answers)
    \,          e# Swap top elements and take the length (total number of questions)
      d/        e# Divide (casting to double so it's not integer division)
        e2      e# Multiply by 10^2
          XmO   e# Round to 1 decimal place
             n  e# Pop and print with a newline

在此部分之后,堆栈仅包含正确/错误列表,并且已输出百分比分数。

Wrong answers

:!            e# Logically negate each element of the right/wrong list
  _,,:)       e# Generate the inclusive range 1...length(list)
       .*     e# Vectorized multiplication of the two lists
         0-   e# Remove any 0s from the result
           p  e# Print it

0

Jolf,46个字节

我似乎无法破坏46个字节。我有两种解决方案。在这里尝试一个!

ΆRγψ~mΖ mi«\|..»d?=€H.xSEhSdHήSmX*~1/-lζlγlζ_1

(替换0x7f在未来的一个)

ΆRγψΜΖψGi'|d=1lHd?□=H.xShSEdHήSmX*~1/-lζlγlζ_1

无论哪种情况,都需要15个字节四舍五入:mX*~1/-lζlγlζ_1。它们在大多数情况下是相同的,除了一个使用正则表达式匹配来获取结果,另一个使用管道拆分。

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.