Skip to content

Instantly share code, notes, and snippets.

View vgaltes's full-sized avatar

Vicenç García Altés vgaltes

View GitHub Profile

Keybase proof

I hereby claim:

  • I am vgaltes on github.
  • I am vgaltes (https://keybase.io/vgaltes) on keybase.
  • I have a public key ASAPTaxcwqiW74MGAi-OV8kV_Kln6zvJ58UPLpgS4kjk1wo

To claim this, I am signing this object:

@vgaltes
vgaltes / Circle.fs
Created October 30, 2016 10:18
Circle implementation in F#
type Circle = {x: double;y: double;radius: double} with
member this.Area = Math.PI * this.radius
let mc = {x = 2.0; y = 3.0; radius = 5.0}
printfn "area: %f" mc.Area
printfn "x: %f" mc.x
printfn "y: %f" mc.y
let noMoreThanOneThousand characterFrom playerTo distance amount =
match playerTo with
| Thing t -> None
| Character c ->
if amount < 1000 - c.Health then Some (amount)
else Some (1000 - c.Health)
let sameFactionNotAllowed characterFrom playerTo distance amount =
match playerTo with
| Thing _ -> Some(amount)
let applyDamage damage player =
match player with
| Thing t -> Player.Thing {t with Health = t.Health - damage}
| Character c -> Player.Character {c with Health = c.Health - damage}
let applyHeal healing player =
match player with
| Thing t -> Player.Thing {t with Health = t.Health + healing}
| Character c -> Player.Character {c with Health = c.Health + healing}
let interactWith characterFrom playerTo action distance =
let calculateDamage characterFrom playerTo action distance =
match action with
| Attack amount ->
match playerTo with
| Character c ->
let damage = calculateHealthDifference amount attackRules characterFrom c distance
let damage' = applyEnvironmentalRules damage environmentalAttackRules characterFrom distance
applyLimitRules damage' attackLimitRules c.Health
| Thing t ->
type Character = {Name:string; Health : int; Level: int; Type: FighterType; Factions: string list}
type Thing = {Name: string; Health: int}
type Player =
| Character of Character
| Thing of Thing
let rec applyRules value rules characterFrom playerTo distance =
match rules with
| [] -> value
| x::xs ->
let result = x characterFrom playerTo distance value
match result with
| None -> 0
| Some v -> applyRules v xs characterFrom playerTo distance
let interactWith characterFrom characterTo action distance =
@vgaltes
vgaltes / gitStatistics.fsx
Created December 19, 2015 17:33
Number of revisions
let numberOfRevisions =
totalCommits
|> Array.collect(fun c -> c.Files)
|> Array.groupBy(fun f -> f.FileName)
|> Array.map ( fun c -> fst c, (snd c).Length)
|> Array.sortByDescending ( fun c -> snd c)
-------------------------------------------------------
val numberOfRevisions : (string * int) [] =
[|("src/SFA.Apprenticeships.Web.Candidate/SFA.Apprenticeships.Web"+[17 chars],
@vgaltes
vgaltes / gitStatistics.fsx
Last active December 19, 2015 17:28
Number of real authors
let consolidateNames name =
match name with
|authorName when mapAuthors.ContainsKey name -> (mapAuthors.TryFind name).Value
|authorName -> authorName
let numberOfAuthors =
totalCommits
|> Array.groupBy(fun c -> c.CommitInfo.Author)
|> Array.map(fun a -> consolidateNames (fst a))
|> Array.distinct
@vgaltes
vgaltes / gitStatistics.fsx
Created December 19, 2015 17:23
Map of author's names
let mapAuthors =
Map.empty
.Add("Janusz Kali Kaliszczak", "Janusz 'Kali' Kaliszczak")
.Add("iterative-it", "David Winchurch")
.Add("charge-valtech", "Henry Charge")
.Add("SandeepYadav", "Sandeep Yadav")
.Add("sandeep-sfa", "Sandeep Yadav")
.Add("kristerbone", "Krister Bone")
.Add("Vicen├º Garc├¡a Alt├®s", "Vicenc Garcia-Altes")
.Add("vgaltes", "Vicenc Garcia-Altes")