Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6), 139 135 140 + 1 bytes

JavaScript (ES6), 139 135 140 + 1 bytes

#JavaScript (ES6), 139 135 140 + 1 bytes

JavaScript (ES6), 139 135 140 + 1 bytes

deleted 501 characters in body
Source Link

#JavaScript (ES6), 139 135135 140 + 1 bytes

newfixed:

t=(n,m)=>(m=2*n+1,Array.from(Array(m),(d,i)=>Array.from(Array(m),(e,j)=>" /-\\  O"[(m-1==j+i)+2*(i==n)+3*(i==j)]).join("")).join("\n"))

So the trick was the new one was to use a string: " /-\\O" and then select the index based on a "score."

score = (m - 1 == j + i) + 2*(i == n) + 3*(i==j)

If m - 1 == j + i, the score would be 1, which will be the forward slash. This covers the first diagonal. If i == n, the score would be 2, which selects the dash, - . If i == j, the score will be 3, which is the other diagonal (so \). However, if i == j && m - 1 == j + i && i == n, then the score will be 6, so "O" is selected.

old:

t=(n,mA=Array)=>(m=2*n+1,Array.from(ArrayA(m),(d,i)=>Array=>A.from(ArrayA(m),(e,j)=>i==j?j==n?"O":"\\":m-1==j+i?"/":i==n?"-":j==n?"|":" ").join("")).join("\n"))
t(3)
/*
\   |  /
 \  | / 
  \ \|/  
---O---
  / \|\  
 /  | \ 
/   |  \
*/
var makeSun = function (n, m) {
    m = 2 * n + 1;    // there are 2*n+1 in each row/column
    return Array.from(Array(m), function (d, i) {
        return Array.from(Array(m), function (e, j) {
            // if i is j, we want to return a \
            // unless we're at the middle element
            // in which case we return the sun ("O")
            if (i == j) {
                return j == n ? "O" : "\\";
            // the other diagonal is when m-1 is j+i
            // so return a forward slash, /
            } else if (m - 1 == j + i) {
                return "/";
            // the middle row is all dashes
            } else if (i == n) {
                return "-";
            // the middle column is all pipes
            } else if (j == n) {
                return "|";
            // everything else is a space
            } else {
                return " ";
            }
        }).join("");
    }).join("\n");
}

#JavaScript (ES6), 139 135 + 1 bytes

new:

t=(n,m)=>(m=2*n+1,Array.from(Array(m),(d,i)=>Array.from(Array(m),(e,j)=>" /-\\  O"[(m-1==j+i)+2*(i==n)+3*(i==j)]).join("")).join("\n"))

So the trick was the new one was to use a string: " /-\\O" and then select the index based on a "score."

score = (m - 1 == j + i) + 2*(i == n) + 3*(i==j)

If m - 1 == j + i, the score would be 1, which will be the forward slash. This covers the first diagonal. If i == n, the score would be 2, which selects the dash, - . If i == j, the score will be 3, which is the other diagonal (so \). However, if i == j && m - 1 == j + i && i == n, then the score will be 6, so "O" is selected.

old:

t=(n,m)=>(m=2*n+1,Array.from(Array(m),(d,i)=>Array.from(Array(m),(e,j)=>i==j?j==n?"O":"\\":m-1==j+i?"/":i==n?"-":" ").join("")).join("\n"))
t(3)
/*
\     /
 \   / 
  \ /  
---O---
  / \  
 /   \ 
/     \
*/
var makeSun = function (n, m) {
    m = 2 * n + 1;    // there are 2*n+1 in each row/column
    return Array.from(Array(m), function (d, i) {
        return Array.from(Array(m), function (e, j) {
            // if i is j, we want to return a \
            // unless we're at the middle element
            // in which case we return the sun ("O")
            if (i == j) {
                return j == n ? "O" : "\\";
            // the other diagonal is when m-1 is j+i
            // so return a forward slash, /
            } else if (m - 1 == j + i) {
                return "/";
            // the middle row is all dashes
            } else if (i == n) {
                return "-";
            // everything else is a space
            } else {
                return " ";
            }
        }).join("");
    }).join("\n");
}

#JavaScript (ES6), 139 135 140 + 1 bytes

fixed:

t=(n,m)=>(m=2*n+1,(A=Array).from(A(m),(d,i)=>A.from(A(m),(e,j)=>i==j?j==n?"O":"\\":m-1==j+i?"/":i==n?"-":j==n?"|":" ").join("")).join("\n"))
t(3)
/*
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
*/
var makeSun = function (n, m) {
    m = 2 * n + 1;    // there are 2*n+1 in each row/column
    return Array.from(Array(m), function (d, i) {
        return Array.from(Array(m), function (e, j) {
            // if i is j, we want to return a \
            // unless we're at the middle element
            // in which case we return the sun ("O")
            if (i == j) {
                return j == n ? "O" : "\\";
            // the other diagonal is when m-1 is j+i
            // so return a forward slash, /
            } else if (m - 1 == j + i) {
                return "/";
            // the middle row is all dashes
            } else if (i == n) {
                return "-";
            // the middle column is all pipes
            } else if (j == n) {
                return "|";
            // everything else is a space
            } else {
                return " ";
            }
        }).join("");
    }).join("\n");
}
added 2 characters in body
Source Link

So the trick was the new one was to use a string: " /-\\O" and then select the index based on a "score."

So the trick was the new one was to use a string: " /-\\O" and then select the index based on "score."

So the trick was the new one was to use a string: " /-\\O" and then select the index based on a "score."

added 700 characters in body
Source Link
Loading
added 28 characters in body
Source Link
Loading
Source Link
Loading