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 solve_tsp_dynamic(points): | |
#calc all lengths | |
all_distances = [[length(x,y) for y in points] for x in points] | |
#initial value - just distance from 0 to every other point + keep the track of edges | |
A = {(frozenset([0, idx+1]), idx+1): (dist, [0,idx+1]) for idx,dist in enumerate(all_distances[0][1:])} | |
cnt = len(points) | |
for m in range(2, cnt): | |
B = {} | |
for S in [frozenset(C) | {0} for C in itertools.combinations(range(1, cnt), m)]: | |
for j in S - {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
/* | |
* robotNav.js | |
* | |
* The green key is located in a slightly more | |
* complicated room. You'll need to get the robot | |
* past these obstacles. | |
*/ | |
function startLevel(map) { | |
// Hint: you can press R or 5 to "rest" and not move the |
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
/* | |
* robotMaze.js | |
* | |
* The blue key is inside a labyrinth, and extracting | |
* it will not be easy. | |
* | |
* It's a good thing that you're a AI expert, or | |
* we would have to leave empty-handed. | |
*/ |
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
/************************** | |
* exceptionalCrossing.js * | |
************************** | |
* | |
* Sorry, old friend, but I'm afraid I can't share | |
* co-authorship on this paper. You've done a very | |
* good job getting this Algorithm for me. The bit | |
* with the keys was especially clever! I wouldn't | |
* have thought of it myself. But then, of course, | |
* that's why you were here in the first place. |
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
% Contains | |
cont([], _):- write(false). | |
cont([E|_], E) :- write(true). | |
cont([_|T], E) :- cont(T, E). | |
:- cont([1,2,3], 2). | |
:- nl. | |
% Appearance counter |
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
% Contains | |
cont([], _, Result):- Result is 0. | |
cont([E|_], E, Result) :- Result is 1. | |
cont([_|T], E, Result) :- cont(T, E, Result). | |
:- cont([1,2,3], 3, R), write(R), nl. | |
% Appearance counter | |
cnt(_, [], Sum, Sum). |
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
sasiad(a, b). | |
sasiad(b, c). | |
sasiad(b, i). | |
sasiad(c, d). | |
sasiad(d, c). | |
sasiad(d, e). | |
sasiad(e, f). | |
sasiad(f, g). | |
sasiad(g, i). | |
sasiad(g, h). |
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
### Keybase proof | |
I hereby claim: | |
* I am majk-p on github. | |
* I am majkp (https://keybase.io/majkp) on keybase. | |
* I have a public key whose fingerprint is 62A0 98DA 2951 259A 39D7 3357 69BF E94A 74B8 A92C | |
To claim this, I am signing this object: |
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
//> using scala "2" | |
case class UnsafeOrderLine(product: String, quantity: Int) | |
object UnsafeOrderLine { | |
def safeApply(product: String, quantity: Int): UnsafeOrderLine = { | |
if (product.isEmpty()) | |
throw new RuntimeException("Product is empty") | |
else if (quantity <= 0) | |
throw new RuntimeException("Quantity lower than 1") | |
else |
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
//> using scala "2" | |
//> using lib "eu.timepit::refined:0.10.1" | |
import eu.timepit.refined.auto._ | |
import eu.timepit.refined.types.string._ | |
import eu.timepit.refined.types.numeric._ | |
case class OrderLine(product: NonEmptyString, quantity: PosInt) | |
OrderLine("100", 10) |
OlderNewer