$ docker
This file contains hidden or 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
| FROM gcc:7.3.0 | |
| RUN apt-get -qq update | |
| RUN apt-get -qq upgrade | |
| RUN apt-get -qq install cmake | |
| RUN apt-get -qq install libboost-all-dev=1.62.0.1 | |
| RUN apt-get -qq install build-essential libtcmalloc-minimal4 && \ | |
| ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so |
This file contains hidden or 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
| function shuffle() { | |
| // Fisher-Yates shuffle algorithm | |
| for (let i = this.length - 1; i > 0; i--) { | |
| const j = Math.floor(Math.random() * (i + 1)); | |
| const temp = this[j]; | |
| this[j] = this[i]; | |
| this[i] = temp; | |
| } | |
| return this; | |
| } |
This file contains hidden or 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
| import mersenneSequence from "./mersenne_sequence"; | |
| import isPrime from "./isPrime"; | |
| const max: number = 100; | |
| // warning: this takes a long time to run?? you have been warned!! | |
| for (let n = 1; n < max; n++) { | |
| let primeCount: number = 0; | |
| const mList: number[] = mersenneSequence(n); |
This file contains hidden or 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
| const mersenneSequenceNumber = x => 2 * x + 1; // f(x) = 2x + 1 | |
| function mersenneSequence(upTo = 10) { | |
| const list = [0]; // init with the first number | |
| // make the rest using the previous number in the list | |
| for (let i = 0; i < upTo; i++) { | |
| list.push(mersenneSequenceNumber(list[i])); | |
| } |
This file contains hidden or 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
| const rgbColor = () => Math.floor(Math.random() * 256); // numbers betweer 0 - 255 | |
| // rgba === red, green, blue and alpha | |
| // rgba examples: white rgba(255, 255, 255, 1), black rgba(0, 0, 0, 1)... etc | |
| const randomRGBColor = (alpha = 1) => `rgba(${rgbColor()}, ${rgbColor()}, ${rgbColor()}, ${alpha})`; | |
| // RESULTS | |
| // rgba(204, 36, 145, 1), all values are random between 0 - 255, last value is definitely 1 | |
| console.log(randomColor()); | |
| // rgba(219, 106, 175, 0.5), all values are random between 0 - 255, last value is definitely 0.5 |
This file contains hidden or 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
| const sum = (x, y) => { | |
| if(Number(x) && Number(y)){ | |
| let result = x; | |
| while(y != 0){ | |
| // AND to get carry | |
| const carry = result & y; | |
| // XOR to get new result | |
| result = result ^ y; |
This file contains hidden or 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
| const Counter = { | |
| count: 0, | |
| incrementFunc: function(){ | |
| this.count++; | |
| }, | |
| incrementArrowFunc: () => { | |
| //this.count++; does nothing | |
| Counter.count++; | |
| }, | |
| getCountFunc: function(){ |
This file contains hidden or 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
| function operate(doOperation = () => 'Think of something creative.', ...args){ | |
| // doOperation has to be a function | |
| if (typeof doOperation != 'function') { | |
| return 'First argument must be a function.'; | |
| } | |
| if(args.length === 0){ | |
| return doOperation(); | |
| } else if( args.length === 1){ | |
| return doOperation(args[0]); |
This file contains hidden or 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
| #include <iostream> | |
| #include <math.h> | |
| using namespace std; | |
| template <class T> | |
| struct Node { | |
| T value; | |
| Node *left; | |
| Node *right; |
NewerOlder