This file contains hidden or 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 com.company; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
class Comparison { | |
// NOT TESTED!!! | |
static Set<String> diff(String aa, String bb) { |
This file contains hidden or 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
object pascal { | |
private def get(rows: List[Long], index: Int): Long = { | |
if (index < 0 || index >= rows.length) 0L | |
else rows(index) | |
} | |
private def row(prev: List[Long] = List()): List[Long] = { | |
if (prev.isEmpty) List(1) |
This file contains hidden or 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
object Main extends App { | |
val lst1 = List(1, 2, 3, 4).toStream | |
val lst2 = List('A', 'B', 'C', 'D', 'E', 'F').toStream | |
lst1 zip lst2 foreach { case (a, b) => println(s"pair: ($a, $b)") } | |
} |
This file contains hidden or 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 com.company; | |
import java.util.Arrays; | |
import java.util.Iterator; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
public class Main { | |
private static int consume(int a, int b) { | |
return a + b; |
This file contains hidden or 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
function permute(xs) { | |
function p(xs, prefix) { | |
if (!xs.length) return prefix; | |
else { | |
let results = []; | |
for (let i = 0; i < xs.length; i++) { | |
let rem = xs.slice(0, i) + xs.slice(i+1); | |
results = results.concat(p(rem, prefix + xs[i])); | |
} | |
return results; |
This file contains hidden or 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
object main extends App { | |
def perm[T](xs: List[T]): Seq[List[T]] = { | |
val len = xs.size | |
if (len < 2) List(xs) | |
else | |
(0 until len).flatMap { i => | |
val (head, tail) = (xs(i), xs.take(i) ++ xs.drop(i + 1)) | |
perm(tail).foldLeft(List[List[T]]())((r, p) => (head :: p) :: r) | |
} | |
} |
This file contains hidden or 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 permute(s): | |
if len(s) < 2: | |
yield s | |
else: | |
for i in range(len(s)): | |
head, tail = s[i], s[:i] + s[i+1:] | |
for p in permute(tail): | |
yield [head] + p | |
This file contains hidden or 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
function perm(str) { | |
return _perm(str, "").toString().split(','); | |
} | |
function _perm(str, acc) { | |
if (str.length === 0) return acc; | |
else { | |
return str.split('').map((c, i) => { | |
let s = str.substr(0, i) + str.substr(i+1); | |
return _perm(s, acc + str[i]); |
This file contains hidden or 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
function isUnique(word) { | |
// polyfill for Set() | |
let set = chars => { | |
return chars.reduce((b, a) => { | |
if (!b.includes(a)) b.push(a); | |
return b; | |
}, []); | |
}; | |
let sortedWord = word.split(''); | |
let charSet = set(sortedWord); |
This file contains hidden or 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
/* | |
* Implement an algorithm to determine if a string has all unique | |
* characters. What if you cannot use additional data structures? | |
*/ | |
#define CATCH_CONFIG_MAIN | |
#include "catch.hpp" | |
#include <iostream> | |
using namespace std; |