Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 30 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Thanks to @jimmy23013 for golfing off 46 bytes and paving the way for 2 more!

Try it online.!

Thanks to @jimmy23013 for golfing off 4 bytes and paving the way for 2 more!

Try it online.

Thanks to @jimmy23013 for golfing off 6 bytes!

Try it online!

added 49 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

CJam, 33(削除) 33 (削除ここまで) 27 bytes

La'|ali(LN{_'|f+@"——"f++}*\;ri*\;{N+_N_N}/

Thanks to @jimmy23013 for golfing off 4 bytes and paving the way for 2 more!

Try it online.

Background

[Try it online.][1]

La'|aLN  " A:= [''] B:= ['|']  ['\n'] ";
 { li({ }ri* }* " Repeat int(input()) - 1 times: ";
 _'|f+ _'|f+ " C = copy(B); for T ∊ C: CT += '|' ";
 @ " Swap A and B. ";
 "--"f+"——"f+ " for T ∊ B: T += '--'  "——" ";
 + " B = C + B ";
 \; " Discard A. ";
 {N+_N_N}/ " for T ∊ B: print T + '\n', T + '\n', '\n' ";
$ alias cjam='java -jar cjam-0.6.2.jar'
$ cjam domino.cjam <<< 3
|||
|||
——|
——|
|——
|——
$ for i in {1..10}; do echo $[$(cjam domino.cjam <<< $i | wc -l) / 3]; done
1done1
2
3
5
8
13
21
34
55
89

[1]: http://cjam.aditsu.net/#code=La'%7Cali(%7B_'%7Cf%2B%40%22%E2%80%94%E2%80%94%22f%2B%2B%7D*%5C%3B%7BN%2B_N%7D%2F&input=6 "CJam interpreter"

CJam, 33 bytes

La'|ali({_'|f+@"——"f++}*\;{N+_N}/

[Try it online.][1]

La'|a " A:= [''] B:= ['|']  ";
 li({ }* " Repeat int(input()) - 1 times: ";
 _'|f+ " C = copy(B); for T ∊ C: C += '|' ";
 @ " Swap A and B. ";
 "--"f+ " for T ∊ B: T += '--'  ";
 + " B = C + B ";
 \; " Discard A. ";
 {N+_N}/ " for T ∊ B: print T + '\n', T + '\n', '\n' ";
$ cjam domino.cjam <<< 3
|||
|||
——|
——|
|——
|——
$ for i in {1..10}; do echo $[$(cjam domino.cjam <<< $i | wc -l) / 3]; done
1
2
3
5
8
13
21
34
55
89

[1]: http://cjam.aditsu.net/#code=La'%7Cali(%7B_'%7Cf%2B%40%22%E2%80%94%E2%80%94%22f%2B%2B%7D*%5C%3B%7BN%2B_N%7D%2F&input=6 "CJam interpreter"

CJam, (削除) 33 (削除ここまで) 27 bytes

LN{_'|f+@"——"f++}ri*\;{_N}/

Thanks to @jimmy23013 for golfing off 4 bytes and paving the way for 2 more!

Try it online.

Background

LN  " A:= [''] B:= ['\n'] ";
 { }ri* " Repeat int(input()) times: ";
 _'|f+ " C = copy(B); for T ∊ C: T += '|' ";
 @ " Swap A and B. ";
 "——"f+ " for T ∊ B: T += "——" ";
 + " B = C + B ";
 \; " Discard A. ";
 {_N}/ " for T ∊ B: print T, T + '\n' ";
$ alias cjam='java -jar cjam-0.6.2.jar'
$ cjam domino.cjam <<< 3
|||
|||
——|
——|
|——
|——
$ for i in {1..10}; do echo $[$(cjam domino.cjam <<< $i | wc -l) / 3]; done1
2
3
5
8
13
21
34
55
89
added 101 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

The possible tilings for n can be obtained by adding a vertical domino to the possible tilings for n - 1 and atwo horizontal dominodominos to the possible tilings for n - 2.

This way, the number of tilings for n is the sum of the numbers of tilings for n - 1 and n - 2, i.e., the nth Fibonacci number.

Try it online. [Try it online.][1]

[1]: http://cjam.aditsu.net/#code=La'%7Cali(%7B_'%7Cf%2B%40%22%E2%80%94%E2%80%94%22f%2B%2B%7D*%5C%3B%7BN%2B_N%7D%2F&input=6 "CJam interpreter"

The possible tilings for n can be obtained by adding a vertical domino to the possible tilings for n - 1 and a horizontal domino to the possible tilings for n - 2. This way, the number of tilings for n is the sum of the numbers of tilings for n - 1 and n - 2, i.e., the nth Fibonacci number.

Try it online.

The possible tilings for n can be obtained by adding a vertical domino to the possible tilings for n - 1 and two horizontal dominos to the possible tilings for n - 2.

This way, the number of tilings for n is the sum of the numbers of tilings for n - 1 and n - 2, i.e., the nth Fibonacci number.

[Try it online.][1]

[1]: http://cjam.aditsu.net/#code=La'%7Cali(%7B_'%7Cf%2B%40%22%E2%80%94%E2%80%94%22f%2B%2B%7D*%5C%3B%7BN%2B_N%7D%2F&input=6 "CJam interpreter"

Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading

AltStyle によって変換されたページ (->オリジナル) /