braingym/projecteuler/1/.ipynb_checkpoints/nix-checkpoint.ipynb

170 lines
3.1 KiB
Text
Raw Normal View History

2022-09-08 17:50:24 +03:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bff727d0-70bf-42cf-a12c-ee5823037315",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
":l <nixpkgs>\n",
"Added 17051 variables.\u001b[0m\n",
"\n"
]
}
],
"source": [
":l <nixpkgs>"
]
},
{
"cell_type": "markdown",
"id": "1de5854d-a1dd-4c88-bad5-571c0e4dab8e",
"metadata": {},
"source": [
"# fake rem because nix doesn't support this operation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8773113c-494f-45d8-a8c1-4f1ac8b60266",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rem = a: b:\n",
" let\n",
" x = builtins.div a b;\n",
" cx = builtins.ceil x;\n",
" in x == cx\n",
"\n"
]
}
],
"source": [
"rem = a: b:\n",
" let\n",
" x = builtins.div a b;\n",
" cx = builtins.ceil x;\n",
" in x == cx"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "25c08a9f-b2ef-451a-9791-f0fd75cf6f00",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"predicate = x: (rem x 3.) || (rem x 5.)\n",
"\n"
]
}
],
"source": [
"predicate = x: (rem x 3.) || (rem x 5.)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "754560b4-01c3-401c-a9ab-14fe56a9a80c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"input = lib.range 1 999\n",
"\n"
]
}
],
"source": [
"input = lib.range 1 999"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "1bbc464a-bedc-4742-ae1d-d06039df53f5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"filtered = lib.filter predicate input\n",
"\n"
]
}
],
"source": [
"filtered = lib.filter predicate input"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5a08e129-b2fe-43b5-a22f-bb6a0e69adb6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sum = list: lib.foldr builtins.add 0 list\n",
"\n"
]
}
],
"source": [
"sum = list: lib.foldr builtins.add 0 list"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1dcaf52d-5526-4755-9454-d79238b9454f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sum filtered\n",
"\u001b[36;1m233168\u001b[0m\n",
"\n"
]
}
],
"source": [
"sum filtered"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Nix - nix",
"language": "Nix",
"name": "inix_nix"
},
"language_info": {
"file_extension": ".nix",
"mimetype": "text/nix",
"name": "nix"
}
},
"nbformat": 4,
"nbformat_minor": 5
}