Skip to content

Instantly share code, notes, and snippets.

View asonge's full-sized avatar

Alexander Songe asonge

View GitHub Profile
@asonge
asonge / 6.js
Created December 6, 2021 20:46
function part1(input, days) {
let gens = [0,0,0,0,0,0,0,0,0]
input.split(',').forEach((x) => gens[x]++)
let zeroes = 0;
for(let d=0;d<days;d++) {
[zeroes, ...gens] = gens;
gens.push(zeroes)
gens[6] += zeroes
}
console.log(gens.reduce((a,b) => a+b))
L=require('fs').readFileSync(0,{encoding:'utf8'}).split("\n");B=L[0].length;a=[0,1].map(v=>{n=L.map(l=>parseInt(l,2));for(b=B-1;b>=0&&n.length>1;b--){c=[0,0];n.map(n=>c[n>>b&1]++);n=n.filter(n=>(n>>b&1)==v^(c[0]>c[1]))}return n[0];});console.log(a[0]*a[1])
a=b=0;require('fs').readFileSync(0,{encoding:'utf8'}).replace(/^(.).*(\d+)$/gm,(_,v,d)=>{a+=d*(v=='f'),b+=v=='d'?+d:v=='u'?-d:0});console.log(a*b)
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"
// To use a separate vendor.js bundle, specify two files path
// http://brunch.io/docs/config#-files-
// joinTo: {
// "js/app.js": /^js/,
defmodule InvertImage do
@magic_reduction_number 20000
@mask :binary.copy(<<255>>, @magic_reduction_number)
def invert(binary), do: do_exor(binary, [])
defp do_exor("", acc), do: acc
defp do_exor(data, acc) when byte_size(data) < @magic_reduction_number,
do: [acc | :crypto.exor(data, :binary.copy(<<255>>, byte_size(data)))]
# This file is in the public domain, so clarified as of
# 2009-05-17 by Arthur David Olson.
# also includes Central America and the Caribbean
# This file is by no means authoritative; if you think you know better,
# go ahead and edit the file (and please send any changes to
# tz@iana.org for general use in the future). For more, please see
# the file CONTRIBUTING in the tz distribution.
def add_attr(event_attr, person_attrs) do
new_attr_value = [%Person.AttributeValue{
:timestamp => event_attr.timestamp,
:confidence => event_attr.confidence,
:value => event_attr.value
}]
curr_attr = Map.get(person_attrs, event_attr.field)
if (curr_attr === nil) do #the person doesn't have that attr
# add_new(person_attrs, )
new_attr_source = %{
str = SSHEx.stream connection, 'ping -c 5 www.google.com'
Enum.reduce(str, {:ok, :running}, fn
_, {:error, reason} -> {:error, reason
{:stdout,row}, {:ok, :running} ->
IO.puts row
{:ok, :running}
{:stderr,row}, {:ok, :running} ->
IO.puts row
{:ok, :running}
@asonge
asonge / test.ex
Created July 30, 2017 23:48 — forked from pikeas/test.ex
defmodule Test.Sup do
use Supervisor
def start_link(opts), do: Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
def init([]) do
children = [
# Supervisor.Spec.worker(Test.Server, [[]]),
Test.Server
]
@asonge
asonge / extract_hrl.exs
Created July 13, 2017 15:21
Make you hrl
{:ok, trees} = :code.lib_dir(:public_key)
|> Path.join("include/OTP-PUB-KEY.hrl")
|> :epp_dodger.parse_file()
constants = trees
|> Enum.map(&:erl_syntax_lib.strip_comments/1)
|> Enum.reject(&match?({:record, _},:erl_syntax_lib.analyze_attribute(&1)))
|> Enum.map(fn {:tree, :attribute, {:attr, _, _, :none}, {:attribute, {:atom, _, :define}, [{:atom,_,_}=a,b]}} ->
{:erl_syntax.concrete(a), :erl_syntax.concrete(b)};
_ -> nil
end)