Skip to content

Instantly share code, notes, and snippets.

View tariknz's full-sized avatar

Tarik Alani tariknz

  • New Zealand
  • 23:03 (UTC +12:00)
  • LinkedIn in/tariknz
View GitHub Profile
/**
* Script to calculate the iRating gain/loss for a driver based on their current position
**/
// Sample data
const drivers: Driver[] = [
{ idx: 0, rating: 2502, position: 1, didNotStart: false },
{ idx: 1, rating: 1202, position: 2, didNotStart: false },
{ idx: 2, rating: 1585, position: 3, didNotStart: false },
{ idx: 3, rating: 1409, position: 4, didNotStart: false },
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace AdminService.Middleware
{
public class WebSocketsMiddleware
{
private readonly RequestDelegate _next;
let serial = 5719
let calcPower x y serial =
let rackId = x + 10;
let powerLevel = ((rackId * y) + serial) * rackId;
let strPower = string powerLevel
if strPower.Length < 3 then 0 else
strPower
|> Seq.item (strPower.Length - 3)
open System.IO
open System.Text.RegularExpressions
let input = File.ReadLines("2018-day-10.txt")
type Star = { position: int * int; velocity: int * int }
let regexPattern = "^position=<[\s]*(\-?[\d]+),[\s]*(\-?[\d]+)> velocity=<[\s]*(\-?[\d]+),[\s]*(\-?[\d]+)>$"
let parser line =
let groups = Regex.Match(line, regexPattern).Groups
open System.IO
open System.Text.RegularExpressions
open System
let input = File.ReadLines("2018-day-7.txt")
let regexPattern = "^Step (\w) must be finished before step (\w) can begin\.$"
let parser line =
let groups = Regex.Match(line, regexPattern).Groups
let captures = List.tail [ for g in groups -> g.Value ]
(captures.[0], captures.[1])
open System.IO
open System
let input = File.ReadLines("2018-day-6.txt")
type PlaceDistance = { id: int; distance: int; location: int * int }
let coords =
input
|> Seq.map (fun i -> i.Split(','))
open System.IO
open System
let input = File.ReadLines("2018-day-5.txt")
let rec polymerExploder input: string =
let polymerSome =
input
|> Seq.toArray
|> Seq.pairwise
open System.IO
open System
open System.Text.RegularExpressions
let input = File.ReadLines("day-4.txt")
type ActionType =
| Sleep
| Awake
| Begin
open System.IO
open System.Text.RegularExpressions
type Claim = { id: string; pos: int * int; size: int * int}
let (|Regex|_|) pattern input = // snippet to make a regex function and return capturing groups
let m = Regex.Match(input, pattern)
if m.Success then Some(List.tail [ for g in m.Groups -> g.Value ])
else None
open System.IO
open System
let input = File.ReadLines("day-2.txt")
// part 1
let countTwosAndThrees line =
line
|> Seq.countBy id
|> Seq.map snd // only take counts (second param), letter not important