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
| def spherical_y_up(theta, phi): | |
| return ( | |
| sin(pi/2 - theta) * sin(phi), | |
| cos(pi/2 - theta), | |
| sin(pi/2 - theta) * cos(phi) | |
| ) |
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
| class Sprite: | |
| def __init__(self, image): | |
| self.image = image | |
| self.rect = image.get_rect() | |
| def draw(self, screen): | |
| screen.blit(self.image, self.rect) | |
| def set_pos(self, pos): |
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
| # n: sequence length | |
| # S: the sequence | |
| # s: the integer value which each sequence sums to | |
| # The computed index, starts at 0 | |
| v = 0 | |
| # algorithm: Consider each element of the sequence S as a subsequence, where each element is an increasingly smaller subsequence. By summing together the indices of each subsequence, we get the index of the whole sequence. We start with the longest subsequence. | |
| for i in range(n - 1): | |
| # l: Max index of subsequence that sums to n minus whatever we've seen so far |
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 <memory> | |
| #include <vector> | |
| #include <spdlog/fmt/fmt.h> | |
| #include "pool.hpp" | |
| struct A { | |
| int x = 0; | |
| uint64_t arr[16]; | |
| A(int x) { |
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
| /* | |
| Transform one unordered map to another, useful for inverting maps at compile time | |
| See it run here: https://replit.com/@_bm/transformmap | |
| */ | |
| #include <iostream> | |
| #include <functional> | |
| #include <unordered_map> | |
| //Function which can transform an std::unordered_map of one type to another with a given transform 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
| " C and S write the buffer | |
| nnoremap cs :update<cr> | |
| " Shift + C and S writes and quits | |
| nnoremap CS :wq<cr> | |
| " F7 fixes indention automagically! Thanks @haydn-jones | |
| map <F7> mzgg=G`z | |
| " J and K quits insert mode |
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
| for (var i = 0; i < 16; i++) { | |
| for (var ii = 0; ii < i + 1; ii++) { | |
| console.log(x - i + ii, y + ii); | |
| console.log(x + ii, y - i + ii); | |
| console.log(x - i + ii, y - ii); | |
| console.log(x + ii, y + i - ii); | |
| } | |
| } |
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
| def lex(i, n): | |
| return (i >> n) & 1; |
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
| //Returns the chess distance between x and y | |
| function chessDistance(x1, y1, x2, y2) { | |
| return Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1)); | |
| } | |
| //Returns the chess 'direction' between x and y | |
| function chessDirection(x1, y1, x2, y2) { | |
| return [Math.sign(x2 - x1), Math.sign(y2 - y1)]; | |
| } |
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
| var run = { | |
| encode: function (data) { | |
| var result = new Uint16Array(data.length * 2 + 1); | |
| let ii = 1; | |
| result[0] = data.length; | |
| result[ii] = data[0]; | |
| for (let i = 0; i < data.byteLength; i++) { | |
| if (result[ii] != data[i]) { | |
| ii += 2; | |
| result[ii] = data[i]; |
NewerOlder