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
componentWillUpdate() { | |
this.scrollY = window.scrollY; | |
} | |
componentDidUpdate() { | |
if (this.scrollY) { | |
window.scroll(0, this.scrollY); | |
} | |
} |
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 countOccurrences (s: String): String = s span (x => x == s.head) match { | |
case ("", "") => "" | |
case (fw, rest) => fw.length.toString + fw.head ++ countOccurrences(rest) | |
} | |
countOccurrences("") // "" | |
countOccurrences("aaa") // "3a" | |
countOccurrences("aaabbb") // "3a3b" | |
countOccurrences("aaabbbccchhhhhhddddhhhheee") // "3a3b3c6h4d4h3e" |
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 qualified Data.Char as Char | |
countOccurrences :: String -> String | |
countOccurrences "" = "" | |
countOccurrences s = let (fw, rest) = span (\x -> x == head s) s in (Char.intToDigit $ length $ fw) : (head s) : (countOccurrences rest) | |
countOccurrences "aaaaabbbbccccccaaaaaaa" | |
-- "5a4b6c7a" |
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
# python 3 | |
def span(string, char): | |
i = 0 | |
while i < len(string) and string[i] == char: | |
i += 1 | |
return string[0:i], string[i:] | |
def count_occurrences(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
def solution(arr): | |
""" | |
Take a list of days and return optimal solution for transport fees where | |
Tickets are: day (2), weekly (7) and monthly (25) tickets | |
And month is bounded to 30 days, first day is 1 | |
:param arr: list of days | |
:type arr: list | |
:return: transport month fees | |
:type: int |
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
module Main exposing (..) | |
import Html exposing (Html) | |
import Html.App | |
import Widget | |
-- MODEL | |
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
from math import log | |
from matplotlib import pyplot as plt | |
import numpy as np | |
def fn_a(n): | |
return 64*n*log(n) | |
def fn_b(n): | |
return 8*n*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
def cities_by_distance(arr): | |
result = [None for _ in arr] | |
temp = [0 for _ in range(len(arr) - 1)] | |
for i, _ in enumerate(arr): | |
origin = i | |
pos = i | |
hop = 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
/** | |
* Created by vincentdupont on 26/8/16. | |
*/ | |
import util.Random | |
object InsertionSort extends App { | |
def sortImp(a: Array[Int]) : Array[Int] = { | |
var key, i : Int = 0 | |
for (j <- 1 until a.length) { |
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
-- give all the ways of giving the change of an amount of money based on a list of coins | |
countChange :: Int -> [Int] -> Int | |
countChange money coins | |
| money < 0 = 0 | |
| money == 0 = 1 | |
| coins == [] = 0 | |
| otherwise = countChange (money - (head coins)) coins + countChange money (tail coins) | |
-- countChange 10 [1, 5] == 3 |
OlderNewer