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
#! py | |
def solve(matrix, mul): | |
width = len(matrix) | |
if width == 1: | |
return mul * matrix[0][0] | |
else: | |
sign = -1 | |
total = 0 | |
for i in range(width): | |
m = [] |
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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func size(depth int, alpha *[]string) int { | |
return int(math.Pow(float64(len(*alpha)), float64(depth))) | |
} |
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
package main | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
) | |
type State struct { | |
name string |
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
import Data.List | |
import Data.List.Split | |
import Data.Ord | |
import System.Environment | |
theta :: (Num a, Eq a, Ord a, Fractional a) => (a,a) -> (a,a) -> a | |
theta (x1,y1) (x2,y2) | |
| dx == 0 && dy == 0 = 0 | |
| dx < 0 = 2 - t | |
| dy < 0 = 4 + t |
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
def self.pretty_json(o, l=0) | |
o.class == Hash ? "{\n" + o.keys.map { |k| (" " * (l + 1) * INDENT) + "\"#{k.to_s}\": " + pretty_json(o[k], l + 1) }.join(",\n") + "\n" + (" " * l * INDENT) + "}" : o.class == Array ? "[\n" + o.map { |k| (" " * (l + 1) * INDENT) + pretty_json(k, l + 1) }.join(",\n") + "\n" + (" " * l * INDENT) + "]" : o.inspect | |
end |
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
struct Point: CustomStringConvertible { | |
let x: Int | |
let y: Int | |
func theta(anchor: Point) -> Float { | |
let dx = Float(x - anchor.x) | |
let dy = Float(y - anchor.y) | |
let t = dy / (abs(dx) + abs(dy)) | |
if dx == 0 && dy == 0 { | |
return 0 |
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
def calculate(mat, mul=1): | |
return (mul * mat[0][0] if len(mat) == 1 else sum((mul * calculate(list(map(lambda j: list(filter(lambda el: el != None, (mat[j][k] if k != i else None for k in range(len(mat))))), range(1, len(mat)))), (-1 if i % 2 == 0 else 1) * mat[0][i])) for i in range(len(mat)))) | |
matrix = [ | |
[1, -2, 3], | |
[0, -3, -4], | |
[0, 0, -3] | |
] | |
print(calculate(matrix)) |
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
/// Please don't do this | |
func iff(condition: Bool, block: () -> ()) -> Bool { | |
if(condition) { | |
block() | |
} | |
return condition | |
} | |
func iff<T>(optional: Optional<T>, block: (val: T) -> ()) -> Bool { |
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
read("", :program, { | |
def(:program_length, send(program, :length)) | |
def(:program_location, 0) | |
def(:input, (1, 2, 3, 4)) | |
def(:input_location, 0) | |
def(:program_char, { | |
send(program, :substring, program_location, +(program_location, 1)) | |
}) |
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
defmodule RegexCond do | |
defmacro match(matchable, do: matches) do | |
IO.inspect matches | |
de_sigged = matches |> Enum.map(fn | |
{:"->", context, [[lhs], code]} -> | |
lhs = de_sig matchable, lhs | |
{:"->", context, [[lhs], code]} | |
end) | |
quote do |
OlderNewer