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
/** | |
http://rosettacode.org/wiki/Run-length_encoding | |
Given a string containing uppercase characters (A-Z), | |
compress repeated 'runs' of the same character by storing the length of that run, | |
and provide a function to reverse the compression. | |
The output can be anything, as long as you can recreate the input with it. | |
*/ |
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
/** | |
http://rosettacode.org/wiki/Reverse_words_in_a_string | |
The task is to reverse the order of all tokens in each of a number of strings and display the result; | |
the order of characters within a token should not be modified. | |
Example: “Hey you, Bub!” would be shown reversed as: “Bub! you, Hey” | |
Tokens are any non-space characters separated by spaces (formally, white-space); | |
the visible punctuation forms part of the word within which it is located and should not be modified. |
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
/** | |
http://rosettacode.org/wiki/Handle_a_signal | |
Most general purpose operating systems provide interrupt facilities, sometimes called signals. | |
Unhandled signals generally terminate a program in a disorderly manner. Signal handlers are | |
created so that the program behaves in a well-defined manner upon receipt of a signal. | |
For this task you will provide a program that displays a single integer on each line of output at | |
the rate of one integer in each half second. Upon receipt of the SigInt signal (often created by the user typing ctrl-C) | |
the program will cease printing integers to its output, print the number of seconds the program has run, |
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
extension String { | |
var dramatically: String { return self + ", ..." } | |
} | |
func printWithDrama(items: Any..., separator: String = " ", terminator: String = "\n") { | |
print(items.map { "\($0)" }.joinWithSeparator(separator).dramatically, terminator: terminator) | |
} |
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
/** | |
http://rosettacode.org/wiki/Parsing/Shunting-yard_algorithm | |
Given the operator characteristics and input from the Shunting-yard algorithm page and tables | |
Use the algorithm to show the changes in the operator stack and RPN output as each individual token is processed. | |
*/ | |
import Foundation |
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
/** | |
http://rosettacode.org/wiki/Execute_a_Markov_algorithm | |
Create an interpreter for a Markov Algorithm. Rules have the syntax: | |
<ruleset> ::= ((<comment> | <rule>) <newline>+)* | |
<comment> ::= # {<any character>} | |
<rule> ::= <pattern> <whitespace> -> <whitespace> [.] <replacement> | |
<whitespace> ::= (<tab> | <space>) [<whitespace>] |
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 Reducer : NSObject | |
+ (id(^)())reduceToBoolMultiple:(NSNumber *)boolArgs, ... NS_REQUIRES_NIL_TERMINATION; | |
+ (id(^)())reduceToBoolArray:(NSArray *)array; | |
@end | |
@implementation Reducer | |
+ (id (^)())reduceToBoolMultiple:(NSNumber *)firstArg, ... NS_REQUIRES_NIL_TERMINATION { | |
BOOL retVal = firstArg.boolValue; |
NewerOlder