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 pair-to-alphanumeric (a b) | |
| (loop | |
| for n = a then (truncate n 26) | |
| until (zerop n) | |
| collect (mod n 26) into chars | |
| finally | |
| (setf chars (nreverse chars)) | |
| (when (cdr chars) | |
| (decf (car chars))) | |
| (unless chars |
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
| (de num->alnum (Col Row) | |
| (let N Nil | |
| (until (=0 Col) | |
| (push 'N (if (=0 (/ Col 27)) (% Col 27) (inc (% Col 27)))) | |
| (setq Col (/ Col 27))) | |
| (pack (mapcar '((C) (char (+ 96 C))) N) Row))) | |
| (test (num->alnum 1 1) "a1") | |
| (test (num->alnum 26 26) "z26") | |
| (test (num->alnum 27 27) "aa27") |
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
| // The premise is that you define an 'hourglass' as the following shape in an array: | |
| // ### | |
| // # | |
| // ### | |
| // Given a two-dimensional array, find the highest sum of elements "masked" by moving | |
| // the hourglass-shaped mask over the array | |
| int hourglassSum(int arr_rows, int arr_columns, int** arr) { | |
| // Naive, inefficient approach | |
| /* |
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 <stdlib.h> | |
| #include "vector.h" | |
| vector make_vector() { | |
| vector vec = { | |
| (int*)malloc(BUFSIZE*sizeof(int)), | |
| BUFSIZE, | |
| 0 | |
| }; | |
| return vec; |
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<stdlib.h> | |
| #include "stack.h" | |
| stack make_stack() { | |
| stack s = { | |
| (int*)malloc(BUFSIZE*sizeof(int)), | |
| BUFSIZE, | |
| 0 | |
| }; | |
| return s; |
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> | |
| using namespace std; | |
| int (*functions[4])(int) = { | |
| [](int x) -> int { | |
| return x + 10; | |
| }, | |
| [](int x) -> int { | |
| return x - 10; |
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 <functional> | |
| using namespace std; | |
| // Return a custom, parametrized adder function (lambda) | |
| auto make_adder(int n) { | |
| return [n](int x) { | |
| return x + 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
| import math | |
| # Assume 'points' is a list of tuples representing 2D points | |
| # Returns a tuple of top-left corner, and side length | |
| def circumscribe_square(points): | |
| # Initialize extremes | |
| x_min = math.inf | |
| x_max = -math.inf | |
| y_min = math.inf |
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
| # Kattis - ABC | |
| # https://open.kattis.com/problems/abc | |
| (de getInput () | |
| (let (Numbers (sort (list (read) (read) (read))) | |
| Seq (chop (read)) | |
| Alist (mapcar '((K V) (cons K V)) '("A" "B" "C") Numbers)) | |
| (list Alist Seq))) | |
| (de processInput(Numbers Sequence) |
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
| # Kattis - Above Average | |
| # https://open.kattis.com/problems/aboveaverage | |
| (load "@lib/math.l") | |
| (de getInput () | |
| (mapcar '((Row) (mapcar '((El) (read)) | |
| (range 1 (read)))) | |
| (range 1 (read)))) |