Skip to content

Instantly share code, notes, and snippets.

(de readIn NIL
(in "/mnt/c/temp/day16.txt"
(make
(until (eof)
(let Parts
(filter
'prog
(mapcar 'pack (split (line) "," ":" " ")) )
(link
(make
# solution for tests on https://pastebin.com/BEdkvnHz
(de noRed (X) (not (match (list '@X ~(chop ":\"red\"") '@Y) X)))
(de parse (Input)
(let (Input (list (chop Input)) C NIL)
(recur NIL
(make
(while (and (setq C (pop Input)) (<> "}" C) (<> "]" C))
(if (or (= C "{") (= C "[")) (link (recurse)) (link C)) ) ) ) ) )
require'~addons/convert/json/json.ijs'
coclass'jtable'
coinsert'jhs'
HBS=: 0 : 0
'<link rel="stylesheet" href="~addons/ide/jhs/js/jquery/smoothness/jquery-ui.custom.css" />'
'<script src="~addons/ide/jhs/js/jquery/jquery-2.0.3.min.js"></script>'
'<script src="~addons/ide/jhs/js/jquery/jquery-ui.min.js"></script>'
'<script rel="stylesheet" href="~addons/ide/jhs/js/jquery/jquery-ui.css"></script>'
require 'convert/json'
input =: fread 'c:/joe/lang-lab/j/advent2015/day12.txt'
json=: dec_json input
traverse=: (".@":@(0&{))`($: each)@.(0 >~ L.)
smoutput pt1=: +/ ; S:0 (traverse json)
(>:^:(0='00000' -: 5&{.@genHash1))^:_ (0)
6!:2 'smoutput (>:^:(0=''00000'' -: 5&{.@genHash1))^:_ (0)'
254575
7.07309
genHash=: ([: gethash_jqtide_ "1 ('md5' ;"1 ([: (INPUT , ":&])"0 i.)))
isAllNumber=: ([: *./ 10&>) @: ('0123456789' i. ])
filter=: [: isAllNumber [ {. ]
doFilter=: (] #~ [ filter"1 ])
getAnswer=:([: ((0&{:: /:~ 1&{::)@:(0&{::) i.~ 1&{::) (] (1&{:: (([ ({."1;]) doFilter);]) genHash&(0&{::))))
getAnswer (1000000;5)
@joebo
joebo / jsharp
Last active August 29, 2015 14:24
public enum Type { Undefined, Int, String, Double};
public class A {
public Type Type;
public long Count;
public int Rank;
public long[] Shape;
public long[] ri;
public string[] rs;
public double[] rd;
public A(Type type, long n) {
import cp.
matrix_square_sub_total(M,M2) = M3 =>
M3 = new_array(M.length, M.length),
foreach(I in 1..M.length, J in 1..M.length)
M3[I,J] = sum([pow(M[I,K]-M2[J,K],2) : K in 1..M[1].length])
end.
% modeled after http://www.hakank.org/picat/assignment.pi
nearest(M1,M2) = Assignments =>
@joebo
joebo / knn.pi
Last active August 29, 2015 14:23
% translated from https://gist.github.com/jpjacobs/6190830a08b95b0bd984
import util.
% csv parsing code placeholder
% Arr={A:L in 1..length(Lines), Z=Lines[L], A={N: C in Z.split(","), N=parse_term(C)}}
matrix_square_sub_total(M) = M3 =>
M3 = new_array(M.length, M.length),
foreach(I in 1..M.length, J in 1..M.length)
M3[I,J] = sum([pow(M[I,K]-M[J,K],2) : K in 1..M[1].length])
@joebo
joebo / readwrite.pi
Created June 17, 2015 19:28
picat reading a file
% exmaple reading a file
import util.
main =>
writeTest,
readTest.
randBetween(Lower,Upper)=Num => Num=floor(frand()*(Upper-Lower+1)+Lower).
writeTest =>