Last active
October 31, 2018 15:30
-
-
Save jamby77/6d09b56e49d0076233b4fbc9a435d881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Zad 2 | |
const num = 14; // input | |
let w = n * 2; // for width we need double of N | |
let h = 2 * n + 2; // height in problem description | |
for (let i = 0; i < h; i++) { | |
let row = ''; | |
// iterate each level | |
for (var j = 0; j < w; j++) { | |
// iterate width | |
if (i < n) { | |
if (i + j === n - 1) { | |
row += '/'; | |
} else if (j - i === n) { | |
row += '\\'; | |
} else { | |
row += ' '; | |
} | |
} else if (i === n) { | |
// this is level bellow roof | |
row += '-'; | |
} else if (i > n && i < (h - 1) && (j === 0 || j === w - 1)) { | |
// walls | |
row += '|'; | |
} else if (i === (h - 1)) { | |
// this is bottom level | |
row += '='; | |
} else { | |
row += ' '; | |
} | |
} | |
console.log(row); | |
} | |
// end zad 2 | |
// zad 3 | |
function isPrime(num) { | |
if (num === 1) { | |
return false; | |
} | |
if (num === 2) { | |
return true; | |
} | |
if (num === 3) { | |
return true; | |
} | |
if (num % 2 === 0) { | |
return false; | |
} | |
if (num % 3 === 0) { | |
return false; | |
} | |
let i = 5; | |
let w = 2; | |
while (i * i <= num) { | |
if (num % i === 0) | |
return false; | |
i += w; | |
w = 6 - w; | |
} | |
return true; | |
} | |
const n = Math.floor(Math.random() * 10000); | |
const nums = new Array(n); | |
for (var i = 0; i < n; i++) { | |
nums[i] = i + (isPrime(i) ? ' - Prime' : ' - Not Prime'); | |
} | |
console.log(nums); | |
// end zad 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment