두 문자열을“곱하기” ++ 에

이것은 최근에 언어 Add ++ 에 추가 한 기능에서 영감을 얻었습니다 . 따라서 Add ++로 짧은 답변을 제출하지만 이기면 받아들이지 않습니다 (공평하지 않음).

숫자는 곱할 수 있지만 문자열은 할 수 없을 때 싫어하지 않습니까? 그래서 당신은 그것을 바로 잡아야합니까?

비어 있지 않은 두 개의 문자열을 입력으로 사용하여 곱한 버전을 출력하는 함수 또는 전체 프로그램을 작성해야합니다.

문자열을 어떻게 곱합니까? 내가 말해 줄게!

두 개의 문자열을 곱하려면 두 개의 문자열을 사용하여 각 문자를 비교하십시오. 그런 다음 코드 포인트가 가장 높은 문자가 출력에 추가됩니다. 동일하면 문자를 출력에 추가하십시오.

문자열의 길이가 같을 수는 없습니다. 길이가 다른 경우 최종 문자열의 길이는 가장 짧은 문자열의 길이입니다. 입력은 항상 소문자이며 0x20 - 0x7E대문자를 제외한 인쇄 가능한 ASCII 범위 ( )의 문자를 포함 할 수 있습니다 .

문자열,리스트 등과 같은 합리적인 형식으로 출력 할 수 있습니다.이 도전에서는 정수가 합리적인 출력 방법이 아닙니다.

hello,및의 입력을 사용하면 world!이것이 작동하는 방식입니다.

hello,
world!

w > h so "w" is added ("w")
o > e so "o" is added ("wo")
r > l so "r" is added ("wor")
l = l so "l" is added ("worl")
d < o so "o" is added ("worlo")
! < , so "," is added ("worlo,")

최종 출력 그래서 hello,world!worlo,!

더 많은 테스트 사례

(단계없이)

input1
input2 => output

programming puzzles & code golf!?
not yet graduated, needs a rehaul => prtgyetmirgduuzzlesneedsde rolful

king
object => oing

blended
bold => boln

lab0ur win.
the "super bowl" => the0usuwir.

donald j.
trumfefe! => trumlefj.

이것은 이므로 가장 짧은 코드가 승리합니다! 루크!



답변

하스켈, 11 바이트

zipWith max

온라인으로 사용해보십시오!

설명 할 것이 많지 않습니다.


답변

05AB1E , 4 바이트

øΣà?

05AB1E 인코딩을 사용합니다 . 온라인으로 사용해보십시오!


답변

펄 6 , 22 바이트

{[~] [Zmax] @_».comb}

보너스로 두 개가 아닌 여러 개의 배수를 사용할 수 있습니다.


답변

Japt , 16 바이트

ñl g îUy ®¬ñ oÃq

온라인으로 테스트하십시오! 입력을 두 문자열의 배열로 가져옵니다.

최소 및 최대 내장 기능이 없으면 Japt가 손상되었지만 여전히 다소 괜찮은 점수를 얻습니다 …

설명

 ñl g îUy ®   ¬ ñ oà q
Uñl g îUy mZ{Zq ñ o} q
                        // Implicit: U = input array     ["object", "king"]
       Uy               // Transpose the strings of U.   ["ok", "bi", "jn", "eg", "c ", "t "]
          mZ{      }    // Map each string Z to
             Zq ñ o     //   the larger of the two chars. (Literally Z.split().sort().pop())
                        //                               ["o", "i", "n", "g", "c", "t"]
                     q  // Join into a single string.    "oingct"
Uñl g                   // Sort the two input strings by length and take the shorter.
      î                 // Trim the previous result to this length.
                        //            "king"î"oingct" -> "oing"
                        // Implicit: output result of last expression


답변

젤리 , 5 바이트

żœ-"«

온라인으로 사용해보십시오!

작동 원리

żœ-"«  Main link. Arguemts: s, t (strings)

ż      Zipwith; form all pairs of corresponding characters from s and t.
       If one of the strings is longer than the other, its extra characters are
       appended to the array of pairs.
    «  Dyadic minimum; get all minima of corresponding characters.
       This yields the characters themselves for unmatched characters.
 œ-"   Zipwith multiset subtraction; remove a single occurrence of the minimum from
       each character pair/singleton.
       This yields the maximum for pairs, but an empty string for singletons.

하자 의 =은 혼합t 대담 = .

ż수율 ["bb", "lo", "el", "nd", 'd', 'e', 'd']. 마지막 세 요소는 문자입니다.

«벡터화, 최소 최소값이므로을 산출 ['b', 'l', 'e', 'd', 'd', 'e', 'd']합니다.

œ-"첫 번째 배열 의 n 번째 문자열 / 문자에서 두 번째 배열 의 n 번째 문자를 정확히 한 번 제거 하여 yield를 산출 합니다. 는 IS MULTISET 뺄셈 원자, 퀵 는 벡터화 수 있습니다.["b", "o", "l", "n", "", "", ""]œ-"

인쇄 될 때 간단히 boln을 읽습니다 .


답변

PHP> = 7.1, 52 바이트

for(;$t=min(~$argv[1][$i],~$argv[2][$i++]);)echo~$t;

PHP 샌드 박스 온라인

PHP> = 7.1, 69 바이트

for([,$a,$b]=$argv;(~$c=$a[$i])&&~$d=$b[$i++];)$r.=max($c,$d);;echo$r;

PHP 샌드 박스 온라인

PHP> = 7.1, 70 바이트

for([,$a,$b]=$argv;(~$c=$a[$i])&&~$d=$b[$i++];)$r.=$c>$d?$c:$d;echo$r;

PHP 샌드 박스 온라인


답변

Alice , 8 바이트

/oI\
@m+

온라인으로 사용해보십시오!

설명

Alice는이 연산자 (내가 superimpose )를 가지고 있지만 출력을 더 짧은 문자열의 길이로 제한하지 않습니다 (대신 더 긴 문자열의 나머지 문자가 추가됩니다). 그러나 두 문자열 중 더 긴 문자열을 더 짧은 문자열의 길이로 자르는 연산자도 있습니다.

/   Reflect to SE, switch to Ordinal. The IP bounces diagonally up and down
    through the code.
m   Truncate, doesn't really do anything right now.
I   Read a line of input.
    The IP bounces off the bottom right corner and turns around.
I   Read another line of input.
m   Truncate the longer of the two input lines to the length of the shorter.
+   Superimpose: compute their elementwise maximum.
o   Output the result.
@   Terminate the program.