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.Threading.Tasks; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Identity; | |
using Microsoft.AspNetCore.Identity.UI; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore; | |
using WebApplication6.Data; | |
using Microsoft.Extensions.Configuration; |
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 positionsOfZeroNetForce(_ magnetPositions: [Double]) -> [Double] { | |
let threshold = 0.0000000000001 | |
// Utility function to give 1/fn(m0) + 1/fn(m1) + ... + 1/fn(mn) | |
// Used for working out the force at x, and its derivitive | |
func sumReciprocals(_ fn: (Double)->(Double)) -> Double { | |
return magnetPositions.map(fn).map { | |
guard $0 != 0 else { return Double.nan } | |
return 1.0/$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
import Foundation | |
public enum Associativity { | |
case left, right | |
} | |
public struct Operator: Equatable, CustomStringConvertible { | |
public var description: String { return body } | |
let body: 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 Foundation | |
public enum Associativity { | |
case left, right | |
} | |
public struct Operator: Equatable, CustomStringConvertible { | |
public var description: String { return body } | |
let body: 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 scala.collection.mutable.ListBuffer | |
object Main extends App { | |
def getOperator(s: String): Option[((Int, Int) => Int)] = { | |
s match { | |
case "+" => Some(_+_) | |
case "-" => Some(_-_) | |
case "/" => Some(_/_) | |
case "*" => Some(_*_) |
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
let tokens = "15 7 1 1 + - / 3 * 2 1 1 + + -".split(separator: " ").map { String($0) } | |
let operators: [String: (Int, Int) -> (Int)] = [ | |
"+" : (+), | |
"-" : (-), | |
"*" : (*), | |
"/" : (/) | |
] | |
let outstack = tokens.reduce([Int]()) { (stack, token) in |
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.Collections.Generic; | |
using System.Linq; | |
namespace LZ77 | |
{ | |
public static class Compressor | |
{ | |
// it's impossible for a pointer to start with this because that would mean a length of 1 | |
private const int Escape = 0x1; |
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 largestSquare(_ s: String, width: Int) -> Int { | |
let bits = s.map { $0 == "1" } | |
let height = bits.count/width | |
let longestLen = (0..<bits.count).reduce(0) { (curLongestLen, i) in | |
let maxLen = min(width - i%width, height - i/width) | |
let firstLenWhereAllBitsNotSet = (1...maxLen).first(where: { len in | |
!(0..<len).allSatisfy { n in | |
bits[i + width*(len-1) + n] && bits[i + (len-1) + width*n] |
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
public class TestHttpClientFactory : IHttpClientFactory | |
{ | |
private class MockHttpMessageHandler : HttpMessageHandler | |
{ | |
public readonly IList<(Predicate<HttpRequestMessage> predicate, Func<HttpRequestMessage, HttpResponseMessage> factory)> Behaviours = | |
new List<(Predicate<HttpRequestMessage> predicate, Func<HttpRequestMessage, HttpResponseMessage> factory)>(); | |
public readonly IList<(HttpRequestMessage, HttpResponseMessage)> Log = new List<(HttpRequestMessage, HttpResponseMessage)>(); | |
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) |