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 reverse_bin (num): | |
reversed = 0 | |
while num != 0: | |
reversed = (reversed << 1) | (num & 1) | |
num >>= 1 | |
return reversed | |
if __name__ == "__main__": | |
print(reverse_bin(int(input()))) |
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
Array.prototype.forEach = function (fun) { | |
for (var i = 0; i < this.length; i++) { | |
fun(this[i]); | |
} | |
}; | |
Array.prototype.foldl = function (acc, fun) { | |
this.forEach(function (elem) { | |
acc = fun(elem, acc); | |
}); |
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 Data.Monoid ((<>)) | |
import Data.Maybe (fromMaybe) | |
makeXzzer :: Int -> String -> (Int -> Maybe String) | |
makeXzzer deviser msg = | |
\x -> if x `mod` deviser == 0 | |
then Just msg | |
else Nothing | |
fizzer :: Int -> Maybe 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
from copy import deepcopy | |
from random import shuffle | |
PARTIES = [ | |
"LNP", "ALP", "GRN", "ASP", "BKAP", | |
"ON", "WLP", "PAP", "FF", "CD" | |
] | |
# functions |
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.annotation.tailrec | |
object PascalsTriangle { | |
type Triangle = Map[(Int, Int), Int] | |
type TriangleResult = (Triangle, Int, Int) => Triangle | |
def generateTriangle(colMax: Int, rowMax: Int, generateResult: TriangleResult): Triangle = { | |
@tailrec | |
def recLoop(triangle: Triangle, colIt: Int, rowIt: Int): Triangle = |
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
fib :: (Eq a, Num a, Num b) => a -> b | |
fib n = impl n 1 0 | |
where | |
impl 0 _ b = b | |
impl n a b = impl (n - 1) (a + b) a |
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
;; original function from a while back | |
(define (max . lst) | |
(let ( | |
(x (car lst)) | |
(xs (cdr lst))) | |
(if (null? xs) | |
x | |
(let ((xs_max (apply max xs))) | |
(if (> x xs_max) | |
x |
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
data Tree a = Node a (Tree a) (Tree a) | Empty | |
tFilter :: (Ord a) => (a -> Bool) -> Tree a -> Tree a | |
tFilter f tree = impl f tree Empty | |
where | |
impl f Empty acc = acc | |
impl f (Node x l r) acc = | |
impl f l $ | |
impl f r $ |
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
package object example { | |
/** | |
* Tranverse a seqence of booleans (which it interprets as seqence of bits), | |
* and these booleans are transfromed into a binary value. Eg. | |
* | |
* scala> boolsToBin(List(true, true, false, true)) | |
* resXX: Int = 11 | |
*/ | |
def boolsToBin(bs: Seq[Boolean]): 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
# Copyright 2014 Angus Thomsen | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
OlderNewer