ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: code-generation

code-generation

HTML๋กœ am * n ํ…Œ์ด๋ธ” ์ƒ์„ฑ 1๊ณผ ๋™์ผ. ์ถœ๋ ฅ : m ๊ฐœ์˜

์ž…๋ ฅ :

๋‘ ์ง„์ˆ˜ ์ •์ˆ˜ m๋ฐ n๊ทธ ๊ฐ๊ฐ ํ…Œ์ด๋ธ”์˜ ํ–‰๊ณผ ์—ด ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
m๊ทธ๋ฆฌ๊ณ  n์ด์ƒ ๋˜๋Š” 1๊ณผ ๋™์ผ.

์ถœ๋ ฅ :

m ๊ฐœ์˜ ํ–‰๊ณผ n ๊ฐœ์˜ ์—ด์ด์žˆ๋Š” HTML์˜ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค.

ํ…Œ์ด๋ธ”์€ ์„ ํƒํ•œ ์ตœ์‹  ๋ธŒ๋ผ์šฐ์ €๋กœ ํ‘œ์‹œ ํ•  ์ˆ˜ ์žˆ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๋ธŒ๋ผ์šฐ์ €๋Š” ํƒœ๊ทธ๋ฅผ ๋‹ซ์ง€ ์•Š์•„๋„ ๋ชจ๋“  ๊ฒƒ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. ์ ์ ˆํ•œ ๋“ค์—ฌ ์“ฐ๊ธฐ ๋ฐ ๊ฐ„๊ฒฉ์€ ์„ ํƒ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค.

๊ฐ ์…€์—๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ (๊ณต๋ฐฑ์ด ์•„๋‹Œ) ์ธ์‡„ ๊ฐ€๋Šฅํ•œ ๋ฌธ์ž๊ฐ€ ์žˆ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์ฒซ ๋ฒˆ์งธ ์ค„์˜ ์…€์€ <th>ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ ๋‹ค์Œ ์ค„์˜ ์…€์€ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ <td>ํ•ฉ๋‹ˆ๋‹ค.

์Šน๋ฆฌ ์กฐ๊ฑด :

์ด๊ฒƒ์€ ์ด๋ฏ€๋กœ ๊ฐ ์–ธ์–ด์— ๋Œ€ํ•œ ๊ฐ€์žฅ ์งง์€ ์†Œ์Šค ์ฝ”๋“œ๊ฐ€ ์Šน๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ž…๋ ฅ ์˜ˆ :

2 3

์ถœ๋ ฅ ์˜ˆ :

<table>
 <tr>
   <th>A</th>
   <th>A</th>
   <th>A</th>
 </tr>
 <tr>
   <td>A</td>
   <td>A</td>
   <td>A</td>
 </tr>
</table>

๋˜๋Š” :
<table><tr><th>A<th>A<th>A<tr><td>A<td>A<td>A



๋‹ต๋ณ€

APL (Dyalog ์œ ๋‹ˆ ์ฝ”๋“œ) ์™€ MiServer 3.0 , 31 30 ๋ฐ”์ดํŠธ SBCS

์ „์ฒด ํ”„๋กœ๊ทธ๋žจ. ๋‘ ์š”์†Œ ๋ชฉ๋ก์„ ํ‘œ์‹œํ•˜๋„๋ก stdin์— ํ”„๋กฌํ”„ํŠธ [m,n]ํ•˜๊ณ  ์—„๊ฒฉํ•œ XHTML์„ stdout์— ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค.

(โŽ•NEW _.Table((โŽ•โด0)โฌ1)).Render

์„ธ์…˜ ์˜ˆ :

      )xload C:\Users\Adam.DYALOG\Documents\MiServer\miserver.dws
C:\Users\Adam.DYALOG\Documents\MiServer\miserver.dws saved Wed Mar  7 17:19:40 2018
      Load ''
Development environment loaded
MiSite "C:/Users/Adam.DYALOG/Documents/MiServer/MS3/" loaded
      (โŽ•NEW _.Table((โŽ•โด0)โฌ1)).Render
โŽ•:
      2 3
<table id="id691498143"><thead><tr><th>0</th><th>0</th><th>0</th></tr></thead><tbody><tr><td>0</td><td>0</td><td>0</td></tr></tbody></table>

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์„ค๋ช…:

(โ€ฆ ).Renderโ€ƒ๋‹ค์Œ HTML ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•˜์‹ญ์‹œ์˜ค.

โ€ƒโŽ•NEW _.Table (โ€ฆ )โ€ƒ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ€์žˆ๋Š” ์ƒˆ ํ…Œ์ด๋ธ” :

โ€ƒโ€ƒ(โ€ฆ ) โฌ 1โ€ƒ๋‹ค์Œ ๋‚ด์šฉ, ํŠน๋ณ„ํ•œ ์Šคํƒ€์ผ๋ง ์—†์Œ, ํ—ค๋” ํ–‰ 1 ๊ฐœ :

โ€ƒโ€ƒโ€ƒโŽ•โด0โ€ƒํ‰๊ฐ€ ๋œ ์ž…๋ ฅ์ด 0์„ ์žฌ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค (์ฆ‰, m ํ–‰, n ์—ด์˜ 0 ํ–‰๋ ฌ)


๋‹ต๋ณ€

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ (ES6), 70 ๋ฐ”์ดํŠธ

@RickHitchcock ๋•๋ถ„์— 2 ๋ฐ”์ดํŠธ ์ ˆ์•ฝ

์นด๋ ˆ ๊ตฌ๋ฌธ์œผ๋กœ ์ž…๋ ฅ์„ (m)(n)๋ฐ›์Šต๋‹ˆ๋‹ค.

m=>n=>'<table>'+(g=c=>'<tr>'+`<t${c}>A`.repeat(n))`h`+g`d`.repeat(m-1)

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

๋ฐ๋ชจ

f=

m=>n=>'<table>'+(g=c=>'<tr>'+`<t${c}>A`.repeat(n))`h`+g`d`.repeat(m-1)

O.innerHTML = f(2)(3)
<div id=O></div>

๋‹ต๋ณ€

ํŒŒ์ด์ฌ 2 , 57 ๋ฐ”์ดํŠธ

lambda m,n:'<table><tr>'+'<th>A'*n+('<tr>'+'<td>A'*n)*~-m

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค! m0์ด ์•„๋‹ˆ๋ผ๊ณ  ๊ฐ€์ • ํ•ฉ๋‹ˆ๋‹ค.


๋‹ต๋ณ€

์บ”๋ฒ„์Šค , 31 ๋ฐ”์ดํŠธ

<ล—>
tableโธ๏ฝโ•ถ๏ผปtrโธโถ๏ฝ›ยน๏ผ‘โ‰กโ•ตdh๏ผ tร—โธ๏ผ›๏ฝ๏ผฝ

์—ฌ๊ธฐ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค! ๋˜๋Š”
์‹œ๊ฐํ™” ํ•ด๋ณด์‹ญ์‹œ์˜ค!

์ธํ„ฐํ”„๋ฆฌํ„ฐ์—์„œ 2 ๊ฐœ์˜ ๋ฒ„๊ทธ (เฒ _เฒ )๋ฅผ ์ˆ˜์ • ํ•œ ํ›„ 30 ๋ฐ”์ดํŠธ๋„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.


๋‹ต๋ณ€

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ, 65 ๋ฐ”์ดํŠธ

f=(m,n)=>m?f(--m,n)+'<tr>'+`<t${m?'d':'h'}>x`.repeat(n):'<table>'

document.write(f(4,3));

๋‹ต๋ณ€

05AB1E , 30 ๋ฐ”์ดํŠธ

โ€™<โ€ฆรˆ>โ€™sF"<tr>"โ€žhdNฤ€รจ"<tรฟ>A"Iร—J

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์„ค๋ช…

โ€™<โ€ฆรˆ>โ€™                           # push "<table>"
      sF                         # no-of-rows times do:
        "<tr>"                   # push "<tr>"
              โ€žhd                # push "hd"
                 Nฤ€              # push the iteration counter truthified
                   รจ             # index into the 2-char string with this
                    "<tรฟ>A"      # insert the result into the string "<tรฟ>A" instead of รฟ
                           Iร—    # repeat this string no-of-columns times
                             J   # join the stack to a single string

๋‹ต๋ณ€

Stax , 28 ๋ฐ”์ดํŠธ

รผร‰$โ™ โ•?Sโ”ผโ•ชโ”œ8ยฐโ€ผโ†sรญโ˜ผโ†Tโ‰กโ”ดโ•œรดโ€ผ\โ†‘0โฟ

์‹คํ–‰ ๋ฐ ๋””๋ฒ„๊น…

ํฌ์žฅ์„ ํ’€๊ณ  ํฌ์žฅ์„ ํ’€๊ณ  ์ฃผ์„์„ ๋‹ฌ์•˜์Šต๋‹ˆ๋‹ค.

"<table>"P  print "table"
"<th>A"*    "<th>A" repeated specified number of times
,D          repeat the rest of the program specified number of times
  "<tr>"p   print "<tr>" with no newline
  Q         print top of stack without popping
  .hd|t     replace "h" with "d"

์ด๊ฒƒ์„ ์‹คํ–‰