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
(ns aoc.day1 | |
(:require [clojure.string :as str])) | |
(def test-input "R5, L5, R5, R3") | |
(def real-input (-> "src/aoc/day1.txt" | |
slurp | |
str/trim-newline)) | |
(defn parse-step [step] |
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
// Gandrīz vienmēr | |
if ([self someThingOrOther]) { | |
return; | |
} | |
// Retos gadījumos (return, break, continue) | |
if ([self somethingOrOther]) return; | |
// Pretējā gadījumā vieglāk var notikt šis | |
if ([self somethingOrOther]) |
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
from itertools import groupby, izip | |
from operator import itemgetter | |
DATA = [ | |
{"service_date": "2013-10-28", "odometer": "115379"}, | |
{"service_date": "2013-10-11", "odometer": "115050"}, | |
{"service_date": "2013-09-27", "odometer": "114410"}, | |
{"service_date": "2013-05-15", "odometer": "107936"}, | |
{"service_date": "2013-05-09", "odometer": "107534"}, | |
{"service_date": "2012-10-16", "odometer": "101089"}, |
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
@interface CDYieldEnumerator : NSEnumerator | |
@end | |
typedef BOOL(^YieldBlock)(id); | |
#define YIELD_BLOCK ^(YieldBlock yield) | |
#define YIELD(OBJECT) do { if (!yield(OBJECT)) return; } while (0) | |
@implementation CDYieldEnumerator { | |
dispatch_queue_t _queue; | |
dispatch_semaphore_t _queueLock; |
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
typedef void(^LogBlock)(NSString *, ...); | |
#define LogBlock LogBlock NS_FORMAT_FUNCTION(1,2) | |
- (BOOL)loggingErrorsDo:(void (^)(LogBlock error))block | |
{ | |
__block BOOL success = YES; | |
block(^(NSString *messageFormat, ...) { | |
va_list args; | |
va_start(args, messageFormat); | |
NSString *message = [[NSString alloc] initWithFormat:messageFormat arguments:args]; |
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
#define COMPARE(A, B) ({ \ | |
__typeof__(A) __a = (A); \ | |
__typeof__(B) __b = (B); \ | |
__a < __b ? NSOrderedAscending : __a == __b ? NSOrderedSame : NSOrderedDescending; \ | |
}) |
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
// Shortest version | |
document.write("1,2,3,5,8,13,21,34,55,89,144,233") | |
// Shortest version without cheating | |
for(a=[],x=y=1;y<301;t=x,x=y,y+=t)a.push(y);document.write(a) | |
// If it's ok to start with 1,1, this can be shortened by another char: | |
for(a=[x=y=1];y<301;t=x,x=y,y+=t)a.push(y);document.write(a) | |
// Shortest version that doesn't introduce global variables |
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
@implementation NSObject (Extra) | |
- (BOOL)isEqualToAnyOf:(id)object, ... | |
{ | |
va_list args; | |
va_start(args, object); | |
for (id other = object; other != nil; other = va_arg(args, id)) { | |
if ([self isEqual:other]) return YES; | |
} | |
va_end(args); |
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
class Array | |
def pairs_for(k) | |
seen = Hash.new(0) | |
each_with_object([]) do |i, result| | |
complement = k - i | |
seen_count = seen[complement] | |
if seen_count > 0 | |
result << [complement, i] | |
seen[complement] -= 1 | |
else |
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
p = Product.find(546) | |
# Product Load (0.4ms) ... | |
p.price | |
# => #<BigDecimal:be36588,'0.0',9(18)> | |
p.changed | |
# => [] | |
p.price = '0.0' | |
# => "0.0" | |
p.price | |
# => #<BigDecimal:be30a34,'0.0',9(18)> |
NewerOlder