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
# Naive implementation for finding the superpermutation of n symbols | |
# https://en.wikipedia.org/wiki/Superpermutation | |
n = 4 | |
permutations = (1..n).to_a.permutation.map{|a| a.join} | |
s = permutations.first | |
permutations.shift | |
while (permutations.length > 0) | |
idx = nil |
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
for line in 0...32 { | |
println("".join((0...78).map { (col: Int) -> String in | |
var x = 0.0, y = x, i = 0 | |
do { | |
x = x * x - y * y + Double(col) / 20.0 - 2.3 | |
y = 2 * x * y + Double(line) / 10.0 - 1.5 | |
i++ | |
} while (x * x + y * y) < 4 && i < 78 | |
return "\(UnicodeScalar(0x1f35b + i))" |
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
func standardDeviation(arr : [Double]) -> Double | |
{ | |
let length = Double(arr.count) | |
let avg = arr.reduce(0, {$0 + $1}) / length | |
let sumOfSquaredAvgDiff = arr.map { pow($0 - avg, 2.0)}.reduce(0, {$0 + $1}) | |
return sqrt(sumOfSquaredAvgDiff / length) | |
} | |
let responseTimes = [ 18.0, 21.0, 41.0, 42.0, 48.0, 50.0, 55.0, 90.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
interface Test { | |
done: boolean, | |
name: string, | |
} | |
function fn(input: Test) { | |
console.log(input.name) | |
} | |
let param1 : Test = {"done": true, "name": "Billie"} |
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
The 10 longest user-agent strings from my access log. | |
All of the are from Internet Explorer and the longest is 370 characters. This is silly! | |
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS129735; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; WWTClient2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; InfoPath.2; InfoPath.3; .NET4.0C; .NET4.0E) | |
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS125042; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; BO1IE8_v1;ENUS) | |
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; YPC 3.2.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.0.3705; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; msn OptimizedIE8;ENGB) | |
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5. |
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 com.example; | |
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.regex.*; | |
public class Main { | |
final static String DATE_FORMAT = "yyMMdd"; |
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
JSON strings can contain {}. | |
test_data = ["{dsfgsdf}", "{asdf}, {sdfsdf}", "{{dfgd}, {sadf}}", "sdfd}{", "{asdfsad}, {sdfs}}", "{{asdf},{sdfsdf}", '{"test{{{"}, {"{{{fest"}'] | |
test_data.each { |s| | |
instring = false; | |
res = s.split(//).reduce(0) { |sum, c| | |
break sum if sum < 0 | |
instring = !instring if c == '"' | |
if !instring |
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
test_data = ["{dsfgsdf}", "{asdf}, {sdfsdf}", "{{dfgd}, {sadf}}", "sdfd}{", "{asdfsad}, {sdfs}}", "{{asdf},{sdfsdf}"] | |
test_data.each { |s| | |
res = s.split(//).reduce(0) { |sum, c| | |
break sum if sum < 0 | |
sum +=1 if c == "{" | |
sum -=1 if c == "}" | |
sum | |
} | |
puts s + " is #{res != 0 ? "no ":""}good!" |
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 collatzConjecture(n) | |
steps = 0 | |
max = 0 | |
until n == 1 | |
steps += 1 | |
n = n.odd? ? n * 3 + 1 : n / 2 | |
max = n if max < n | |
end | |
[steps, max] | |
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
using System; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace test | |
{ | |
class Person | |
{ | |
public int Number { get; set; } |
NewerOlder