λΉμ μ μμ
μ μ΄λ€ μ
λ ₯μμ§μ§ μμ΅λλ€ λ° λ£¨ν (λͺ¨λ μ’
λ₯μ μ€νλλ μ 체 νλ‘κ·Έλ¨μ΄λ κΈ°λ₯μ μμ±νλ κ²μ
λλ€ while, for, foreach, do, do-while, do-loop, gotoνλ‘κ·Έλ¨μ΄ μ€ν μ체λ₯Ό μ€μ§ν΄μΌ ν¨μ μλ―Έν©λλ€ μ€λ₯λ₯Ό μΌμΌν€λ μμΈμ΄ μ’
λ£λ©λλ€, μ¬κ· λ±) μΆκ΅¬.
κ·μΉ :
- μ€λ₯λ λ°νμ μ€λ₯, μ²λ¦¬λμ§ μμ μμΈ λλ νλ‘κ·Έλ¨ μ체λ₯Ό μ’ λ£μν€λ λͺ¨λ νλͺ©μ΄μ΄μΌν©λλ€.
- μ€λ₯λ
exit;νΉμ μμ μμ λͺ μ μ μΌλ‘ (λλ μ΄μ μμνλ) νΈμΆνμ§ μκ³ νλ‘κ·Έλ¨μ μ€μ§νκ³ μ’ λ£ν΄μΌν©λλ€ . - κ°μ λ©μμ§
Warning:,Notice:μ체 μ’ λ£ νλ‘κ·Έλ¨μ λ°μνμ§ μλ λ±, μ ν¨νμ§ μμ΅λλ€. μλ₯Ό λ€μ΄, PHP 0μΌλ‘ λλλ©΄Warningλ©μμ§κ° μμ± λμ§λ§ νλ‘κ·Έλ¨μ΄ μ€μ§λμ§ μκ³ κ³μ μ€νλ©λλ€. μ΄λ μ¬λ°λ₯Έ λ΅λ³μ΄ μλλλ€. - 루νλ νλ μ΄μμ μ 체주기λ₯Ό μ€νν΄μΌν©λλ€. μ¦, λ λ²μ§Έ μ¬μ΄ν΄μμ μμνμ¬ μ€λ₯κ° λ°μν μ μμ΅λλ€. μ΄λ μλͺ»λ μ½λ ꡬ문μ μ¬μ©νμ¬ μ€λ₯κ° λ°μνμ§ μλλ‘νκΈ°μν κ²μ λλ€. μ½λλ ꡬ문 μ μ νν΄μΌν©λλ€.
- 루νκ°
for(;;);μμ μΈκΈ λ κ·μΉμ μ€μνλ κ²½μ° λ¬΄νλ (μ π μΌ μ μμ§λ§ λ°νμ μ€λ₯λ‘ μΈν΄ μ체 μ’ λ£νλ λ° 2 ββλΆ μ΄μ κ±Έλ¦¬μ§ μμμΌν©λλ€. - Tail Call Optimizationμ΄μλ μ¬κ·λ μ ν¨νμ§ μμ΅λλ€ ( 1 , 2 ).
- μ΄κ²μ μ½λ 골ν μ΄λ―λ‘ κ°μ₯ μ§§μ μ½λκ° μΉλ¦¬ν©λλ€.
- νμ€ νμ μ κΈμ§λμ΄ μμ΅λλ€.
C # μμ ( μ¨λΌμΈ ν μ€νΈ ) :
using System;
public class Program {
public static void Main() {
int i;
int[] n;
n = new int[5];
for(i=0; i<7; i++) {
n[i] = i;
Console.WriteLine(n[i]);
}
}
}
Output:
0
1
2
3
4
Run-time exception (line 9): Index was outside the bounds of the array.
Stack Trace:
[System.IndexOutOfRangeException: Index was outside the bounds of the array.]
at Program.Main(): line 9
리λ 보λ :
var QUESTION_ID=104323,OVERRIDE_USER=59718;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important;font-family:Arial,Helvetica; font-size:12px}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
리λ 보λ μ€ λν«μ μν Martin Ender μκ² κ°μ¬ν©λλ€
λ΅λ³
MATL , 5 1 λ°μ΄νΈ
@MartinEnderμ CJam λ΅λ³ μμ κ°μ Έμ¨ μμ΄λμ΄
`
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
` % Do...while loop
% Implicit end. The loop continues if the top of the stack is true.
% After the first iteration, since the stack is empty, the program
% implicitly tries to take some non-existing input, and finishes
% with an error
ꡬ λ²μ
2:t"x
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
2: % Push [1 2]
t % Duplicate
" % For each (i.e. do the following twice)
x % Delete top of the stack. Works the first time. The second it tries to
% implicitly take some non-existing input, and finishes with an error
λ΅λ³
νμ΄μ¬, 16 λ°μ΄νΈ
λΉ κ΄μ¬ 0 λΆλ¬Έ μ κ·Ό :
for x in 1,0:x/x
첫 λ²μ§Έ λ°λ³΅μμ κ³μ° 1 / 1νμ¬ μ μμ μΌλ‘ μλν©λλ€. λ λ²μ§Έ λ°λ³΅μ κ³μ°μ μλνμ¬ 0 / 0κ²°κ³Ό ZeroDivisionErrorκ° λ°μν©λλ€.
17 λ°μ΄νΈ (κ°μΈ μ νΈ)
i=1
while i:del i
μ²μμλ i=1μ§μ€νκΈ° λλ¬Έμ 루νκ° μμλ©λλ€.
루νκ° μ²μ μ€νλ λ λ³μ iκ° μμ λ©λλ€.
μ΄λ λ λ²μ§Έ iλ‘ λ μ΄μ λ³μκ° μλλ―λ‘ νκ°κ° μ€ν¨ ν¨μ μλ―Έν©λλ€.NameError: name 'i' is not defined.
νμ΄μ¬μ 꼬리 μ¬κ·λ₯Ό μ΅μ ννμ§ μκΈ° λλ¬Έμ λ λ€λ₯Έ 15 λ°μ΄νΈ μ루μ
μ def _():_()(newline) _()μ
λλ€. κ·Έλ¬λ μ΄κ²μ κ·μΉ # 6μ μλ°ν©λλ€.
λ΅λ³
μ €λ¦¬ , 3 2 λ°μ΄νΈ
αΉΎΓ
λ©λͺ¨λ¦¬κ° λΆμ‘±νμ¬ μ체λ₯Ό μ’ λ£ν©λλ€. ~ 100 μ΄ νμ λ‘컬μμ μνν©λλ€.
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€! ( λλ²κ·Έ λλ‘μ΄μ μ¬λ§ μΈμ¦μ )
μλ μ리
αΉΎΓ Main link. Argument: x. Implicit first argument: 0
αΉΎ Uneval; yield a string representation of x.
Γ Recursively call the main link.
Jelly uses TCO, so the first cycle finishes successfully before entering
the next one.
μ²μ λͺ λ²μ λ°λ³΅μ λ€μκ³Ό κ°μ΅λλ€.
'0'
'β0'
'ββ,β0'
'ββ,ββ,β,,ββ,β0'
'ββ,ββ,β,,ββ,ββ,β,,ββ,β,,β,,ββ,ββ,β,,ββ,β0'
'ββ,ββ,β,,ββ,ββ,β,,ββ,β,,β,,ββ,ββ,β,,ββ,ββ,β,,ββ,β,,β,,ββ,ββ,β,,ββ,β,,β,,ββ,β,,β,,ββ,ββ,β,,ββ,ββ,β,,ββ,β,,β,,ββ,ββ,β,,ββ,β0'
κ·Έ ν, κ·Έκ²μ μΆμ νκ³ μ§μ§ λΉ λ¦ λλ€.
λ΅λ³
V , 2 λ°μ΄νΈ
Γ²l
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
λ΄κ° νμ κ·Έλ κ²νκΈ° λλ¬Έμ μ΄κ²μ Vμ λν μλ²½ν λμ μ
λλ€! μ€μ λ‘ Vμλ μ‘°κ±΄μ΄ μμΌλ©° μ€λ₯κ° λ°μνλ κΈ°λ₯ λ§ μμ΅λλ€. μ΄ κ²½μ° Γ²βμμν λ°λ³΅βμ΄λΌλ lμλ―Έμ βμ€λ₯Έμͺ½μΌλ‘ μ΄λβμ΄λΌλ μλ―Έμ
λλ€.
λΉ λ²νΌ (μ λ ₯ μμ)μμλ 첫 λ²μ§Έ ν¨μ€μμ μ€λ¨λκ³ μΆλ ₯μ΄ μμ±λμ§ μμ΅λλ€. μ λ ₯ μ΄μλ κ²½μ° μ λ ₯μ λ§μ§λ§ λ¬Έμλ₯Ό μ΄λ ν ν μ λ ₯μ΄ μ€λ¨λκ³ λͺ¨λ μ λ ₯μ΄ μΆλ ₯λ©λλ€ (κ³ μμ΄ νλ‘κ·Έλ¨μ΄κΈ°λ ν¨)
λ΅λ³
μλ° μ€ν¬λ¦½νΈ (ES6), 13 λ°μ΄νΈ
f=_=>f(_?a:1)
μ΄ κΈ°λ₯μ μ¬κ· ν¨μλ‘ ν λ² μ€ν λ λ€μ λμ§κ³ ReferenceError: a is not definedμ’
λ£λ©λλ€.
λ€μμ 15 λ°μ΄νΈ λΉ ES6 λ²μ μ λλ€.
for(i=0;;)i=i.a
μ΄κ²μ ν λ² μ μ€ν λ λ€μ λμ§κ³ TypeError: i is undefinedμ’
λ£λ©λλ€.
λ΅λ³
λ°°μ¬ 4.2, 22 λ°μ΄νΈ
exec $0 $@ $[2**$#%-1]
Bash 4.3μ΄ μκΈ° λλ¬Έμ TIOμμ μλνμ§ μμΌλ©° λ΄κ° μμ‘΄νλ λ²κ·Έκ° λ§μΉ¨λ΄ μμ λμμ΅λλ€.
νμΈ
$ xxd -c 22 -g 22 self-destruct
0000000: 6578656320243020244020245b322a2a2423252d315d exec $0 $@ $[2**$#%-1]
$ ./self-destruct
Floating point exception
νλ‘κ·Έλ¨μ΄ 2 63 mod -1 μ κ³μ°νλ €κ³ μλ νλ©΄ μλ €μ§ λ²κ·Έλ‘ μΈν΄ Bash 4.2 λ° μ΄μ λ²μ μμ μΆ©λμ΄ λ°μνλ©΄ μΆ©λμ΄ λ°μν©λλ€ .
λ΅λ³
PHP, 22 21 20 18 λ°μ΄νΈ
μ΄κ²μ PHPμ μμ‘΄νμ¬ λ³μμ ν¨μ μ΄λ¦μ λΆμ¬νκ³ μ€ννλ €κ³ ν©λλ€.
μ΄κ²μ λ¨μν piν¨μ μ΄λ¦μ λ λ² μ°κ²°ν©λλ€ . μ΄κ²μλ‘ PHPλ₯Ό μ£½ Fatal Error: Uncaught Error: Call to undefined function pipi() in [...][...]μ
λλ€.
while($x.=pi)$x();
μ΄κ²μ λμ μ λλ΅κ³Ό λΉμ·νκ² μλν©λλ€.
μ΄μ λ΅λ³, 20 λ°μ΄νΈ
PHPμμλ μ¦κ° μ°μ°μλ₯Ό μ¬μ©νμ¬ λ¬Έμλ₯Ό μ¦κ°μν¬ μ μμ΅λλ€. a-zλ²μ μμλ§ μλ νμ§λ§ μΆ©λΆν©λλ€.
for($x=pi;;)$x=$x();
λλ μ΄κ²μ΄ λͺ¨λ νμ ν¬μΈνΈλ₯Ό μΆ©μ‘±μν€κ³ 루νκ° ν λ² μ€νλλ€κ³ μκ°ν©λλ€.
μ€λ₯κ° λ°μνκΈ° λλ¬Έμ μ μ μμ΅λλ€ Fatal error: Function name must be a string.
μ΄κ²μ΄ μ΄λ»κ² μλνλμ§ λ¨κ³λ³λ‘ :
- ν λΉ
piμ$x.
μ΄νpiμΌμ μΌλ‘ μ¬μ©λκ³ μλ κ²½μ°, PHP νμΈνλ€.
PHPλUse of undefined constant pi - assumed 'pi'μ‘΄μ¬νμ§ μκΈ° λλ¬Έμ (κΈ°λ³Έμ μΌλ‘ μμκ° μ‘΄μ¬νμ§ μκΈ° λλ¬Έμ λ¬Έμμ΄μ΄λΌκ³ κ°μ ν©λλ€) κ²½κ³ λ©μμ§λ₯Ό νμν©λλ€ - μ²μμΌλ‘ 루ν
- κΈ°λ₯μ μ€ννμμμ€
$x().
λλ¬Έμ$xκ°μ κ°μ§κ³pi,μ΄ κΈ°λ₯μ μ€νν©λλ€pi().
- κΈ°λ₯μ μ€ννμμμ€
- μ κ°μ μ μ₯νμμμ€
$x.
$xμ΄μ λμ μ Ολ₯Ό κ°μ΅λλ€.pi - λ λ²μ§Έ 루ν
- κΈ°λ₯μ μ€ννμμμ€
$x().
μ΄ν$xΟ μμΌλ©°,μ΄ κΈ°λ₯μ μ€νν©λλ€3.14159...(). - Ολ λ¬Έμμ΄μ΄ μλλ―λ‘μ΄ μμ μμμ μ¬μ©νμ¬ νλ‘κ·Έλ¨μ μ’
λ£νμμμ€
Fatal Error.
- κΈ°λ₯μ μ€ννμμμ€
ν¨μ λ₯Ό μ°Ύμμ 1 λ°μ΄νΈλ₯Ό μ μ½ ν @Titus μκ² κ°μ¬λ립λλ€ !pi()