@@ -29,6 +29,28 @@ type Scorecard struct {
2929 Took time.Duration
3030}
3131
32+ func preprocessKCode (holeID , code string ) string {
33+ if holeID == "quine" {
34+ length := len (code )
35+ var newCode []byte
36+
37+ // Disable implicit output by inserting a ';' before all newlines, except when
38+ // the next line begins with a space (for a continuation).
39+ for i := 0 ; i < length ; i ++ {
40+ x := code [i ]
41+ if x != '\n' || i + 1 < length && code [i + 1 ] == ' ' {
42+ newCode = append (newCode , x )
43+ } else {
44+ newCode = append (newCode , ';' , '\n' )
45+ }
46+ }
47+
48+ return string (newCode )
49+ } else {
50+ return code + "\n "
51+ }
52+ }
53+
3254func getAnswer (holeID , code string ) (args []string , answer string ) {
3355 args = []string {}
3456
@@ -148,6 +170,8 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
148170 cmd .Args = []string {"/hexagony/Hexagony" , "-d" , "-" }
149171 case "j" :
150172 cmd .Args = []string {"/usr/bin/j" , "/tmp/code.ijs" }
173+ case "k" :
174+ cmd .Args = []string {"/usr/bin/kwrapper" , "/tmp/code.k" }
151175 case "javascript" :
152176 cmd .Args = []string {"/usr/bin/d8" , "-e" , code , "--" }
153177 case "julia" :
@@ -189,6 +213,9 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
189213 switch langID {
190214 case "brainfuck" , "fish" , "javascript" :
191215 // For these code is passed as an argument above.
216+ case "k" :
217+ code = preprocessKCode (holeID , code )
218+ cmd .Stdin = strings .NewReader (code )
192219 case "php" :
193220 code = "<?php " + code + " ;"
194221 fallthrough
0 commit comments