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 csv | |
import sys | |
from typing import Dict, List | |
ACTION_MAPPING = { | |
"sell": "SELL", | |
"buy": "BUY", | |
"stock plan activity": "BUY", | |
"reinvest shares": "BUY", | |
"stock split": "SPLIT", |
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 sys | |
from typing import Dict, List | |
from datetime import datetime | |
import requests | |
from xml.etree import ElementTree | |
BASE_HMRC_URL = 'http://www.hmrc.gov.uk/softwaredevelopers/rates/' #exrates-monthly-0123.XML | |
def main(): |
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 customToString(x: Int): String = { | |
val digits: Array[Char] = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') | |
def recur(base: Int, digit: Int, accu: List[Char]): List[Char] = { | |
val newAcc = digits(digit) :: accu | |
if (base == 0) newAcc | |
else recur(base / 10, base % 10, newAcc) | |
} | |
val absX = math.abs(x) | |
val toCharList = recur(absX / 10, absX % 10, List.empty) | |
if (x < 0) ('-' :: toCharList).mkString |
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
/** | |
* A question I normally ask in Scala interviews, this is not a tail-recursive implementation | |
*/ | |
object Permutations { | |
def permutations(s: String): List[String] = { | |
def merge(ins: String, c: Char): Seq[String] = | |
for (i <- 0 to ins.length) yield | |
ins.substring(0, i) + c + ins.substring(i, ins.length) |