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
| (defun read-coords (path) | |
| (with-open-file (stream path :direction :input :if-does-not-exist :error) | |
| (let ((res (make-array 0 :adjustable t :fill-pointer 0))) | |
| (loop :for (x1 y1 _ x2 y2) | |
| := (uiop:split-string (read-line stream nil nil) :separator ", ") | |
| :while x1 | |
| :do (vector-push-extend (list (parse-integer x1) | |
| (parse-integer y1) | |
| (parse-integer x2) | |
| (parse-integer y2)) res)) |
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
| (defmacro do-table (indexes &body body) | |
| (if (null indexes) | |
| `(progn ,@body) | |
| `(loop :for ,(caar indexes) :from 0 :below ,(cadar indexes) | |
| :do (do-table ,(cdr indexes) ,@body)))) | |
| (defun read-nums (stream) | |
| (map 'vector #'parse-integer |
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
| (defun update-maxs (line maxs) | |
| (loop :for ch :across line | |
| :for i :from 0 | |
| :when (char= ch #\1) | |
| :do (incf (aref maxs i)))) | |
| (defun day3.1 (path) | |
| (with-open-file (stream path :direction :input | |
| :if-does-not-exist :error) | |
| (let ((firstline (read-line stream nil nil))) |
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 <unordered_map> | |
| #include <mutex> | |
| #include <functional> | |
| #include <forward_list> | |
| #include <vector> | |
| #include <utility> | |
| #include <algorithm> | |
| #include <memory> | |
| template <class K, class V, class Hash = std::hash<K>> |
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
| template <class RandomAccessIterator, class T, class Func> | |
| T Reduce(RandomAccessIterator first, RandomAccessIterator last, const T& initial_value, Func func) { | |
| std::vector<std::thread> workers; | |
| std::atomic<T> cur_value(initial_value); | |
| auto dist = std::distance(first, last); | |
| auto seglen = dist / 7; | |
| auto rem = dist % 7; | |
| if (seglen != 0) { | |
| for (size_t i = 0; i < 7; 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
| #include <iostream> | |
| #include <memory> | |
| template <class T> | |
| class List { | |
| struct Node { | |
| public: | |
| Node(T data, Node* next) : data_(data), next_(next) { | |
| } |
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 <memory> | |
| template <class T> | |
| class SLList { | |
| public: | |
| SLList() : size_(0), first_(nullptr) { | |
| } | |
| SLList(std::initializer_list<T> list) : size_(list.size()) { |
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
| /// A munger which XORs a key with some data | |
| use std::borrow::Borrow; | |
| #[derive(Clone)] | |
| pub struct Xorcism<'a> { | |
| key: &'a [u8], | |
| position: usize, | |
| } | |
| pub trait Captures<'a> {} |
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
| (ql:quickload 'adhoc-polymorphic-functions) | |
| (use-package :adhoc-polymorphic-functions) | |
| (deftype ind () `(integer 0 #.array-dimension-limit)) | |
| (defparameter *default-impl* (make-hash-table)) | |
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
| (defmacro define-struct (name inheritance &body slots) | |
| (let ((trueslots (loop :for (name . rest) :in slots | |
| :collect (ecase (length rest) | |
| (1 `(,name . ,rest)) | |
| (2 (let ((type (cadr (member :t rest)))) | |
| `(,name ,(default type) :type ,type))) | |
| (3 (let ((type (cadr (member :t rest)))) | |
| `(,name ,(third rest) :type ,type))))))) | |
| `(progn |