J - 5654 char
Function taking n as argument on the right.
0{::(];,"":&'];'--'@['&,"1@[,'|',"1~]"1])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('];'--''&,"1 _~[)"1@[,'|',"1~]"1])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&''--'@['&,"1@[ adds -- tiles to the left list, while '|',"1~]"1] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with |. Then, we add the new tiles to each row, and append the lists of matrices when we're joining the two sets of tilings together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'];'--'@['&,"1@[,'|',"1~]"1])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----|----|
--|--
--|--
|||--|||--|||
|----|
|----|
||--|
||--|
||
|--||
|
||--|
||--|
|||--|||
|||--|||
|||||
|||||
J - 56 char
Function taking n as argument on the right.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('--',"1 _~[),'|',"1~])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&'--'@[ adds -- tiles to the left list, while '|',"1~] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with |. Then, we add the new tiles to each row, and append the lists of matrices when we're joining the two sets of tilings together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----|----
--|--
--|--
|||--|||--
----|
----|
||--|
||--|
|--||
|--||
--|||
--|||
|||||
|||||
Try it for yourself at tryj.tk.
J - 54 char
Function taking n as argument on the right.
0{::(];'--'&,"1@[,'|',"1])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];'--'&,"1@[,'|',"1])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). '--'&,"1@[ adds -- tiles to the left list, while '|',"1] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with |. Then, we add the new tiles to each row, and append the lists of matrices when we're joining the two sets of tilings together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];'--'&,"1@[,'|',"1])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
----|----|
--|--
--|--
--|||--|||
|----
|----
|--||
|--||
||--|
||--|
|||--
|||--
|||||
|||||
Try it for yourself at tryj.tk.
J - 56 char
Function taking n as argument on the right.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('--',"1 _~[),'|',"1~])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&'--'@[ adds -- tiles to the left list, while '|',"1~] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with '|'|. Then, we add the new tiles to each row, and append the lists of matrices when we're joining those liststhe two sets of tilings together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----
|----
--|--
--|--
|||--
|||--
----|
----|
||--|
||--|
|--||
|--||
--|||
--|||
|||||
|||||
Try it for yourself at tryj.tk.
J - 56 char
Function taking n as argument on the right.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('--',"1 _~[),'|',"1~])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&'--'@[ adds -- tiles to the left list, while '|',"1~] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with '|'. Then, we add the new tiles to each row, and append the matrices when we're joining those lists together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----
|----
--|--
--|--
|||--
|||--
----|
----|
||--|
||--|
|--||
|--||
--|||
--|||
|||||
|||||
Try it for yourself at tryj.tk.
J - 56 char
Function taking n as argument on the right.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('--',"1 _~[),'|',"1~])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&'--'@[ adds -- tiles to the left list, while '|',"1~] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with |. Then, we add the new tiles to each row, and append the lists of matrices when we're joining the two sets of tilings together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----
|----
--|--
--|--
|||--
|||--
----|
----|
||--|
||--|
|--||
|--||
--|||
--|||
|||||
|||||
Try it for yourself at tryj.tk.
J - 56 char
Function taking n as argument on the right.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')
The main root of this golf is the (];('--',"1 _~[),'|',"1~])&>/. This takes a list of tilings of length (N-2) and (N-1), and returns a list of tilings of length (N-1) and N. This is the standard Fibonacci recurrence, à la linear algebra. ]; returns the right list as the new left (as there is no change). ,"":&'--'@[ adds -- tiles to the left list, while '|',"1~] adds | tiles to the right list, and those together are the new right list.
We iterate that over and over n times (that's the @[&0) and start with the empty tiling and the single tiling of length 1. Then we return the first of the pair with 0{::. Meaning, if we run it zero times, we just return the first i.e. the empty tiling. If we run it n times, we calculate up to the n and (n+1) pair, but discard the latter. It's extra work but less characters.
The (1 2,ドル:) is something J has to do in order to make the tilings in the lists easily extendable. We make the left starting list be a 1-item list of a 2-row matrix of characters, each row having length 0. The right starting list is the same, but has the rows be of length 1, filled with '|'. Then, we add the new tiles to each row, and append the matrices when we're joining those lists together. It's a simple application of a concept J calls rank: essentially manipulating the dimensionality of its arguments, and implicitly looping when necessary.
0{::(];,"":&'--'@[,'|',"1~])&>/@[&0&((1 2,ドル:)&.>'';,'|')5
|----
|----
--|--
--|--
|||--
|||--
----|
----|
||--|
||--|
|--||
|--||
--|||
--|||
|||||
|||||
Try it for yourself at tryj.tk.