braingym/projecteuler/1/nix.ipynb

205 lines
3.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bff727d0-70bf-42cf-a12c-ee5823037315",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
":l <nixpkgs>\n",
"Added 18073 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": {
"tags": []
},
"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": {
"tags": []
},
"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": 4,
"id": "754560b4-01c3-401c-a9ab-14fe56a9a80c",
"metadata": {
"tags": []
},
"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": 5,
"id": "1bbc464a-bedc-4742-ae1d-d06039df53f5",
"metadata": {
"tags": []
},
"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": 6,
"id": "5a08e129-b2fe-43b5-a22f-bb6a0e69adb6",
"metadata": {
"tags": []
},
"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": 8,
"id": "1dcaf52d-5526-4755-9454-d79238b9454f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"main = sum filtered\n",
"\n"
]
}
],
"source": [
"main = sum filtered"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "49a4669c-047f-4b14-9d9a-a0d9feb4bef9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"main\n",
"\u001b[36;1m233168\u001b[0m\n",
"\n"
]
}
],
"source": [
"main"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "nix-Nix kernel",
"language": "Nix",
"name": "nix-nix"
},
"language_info": {
"file_extension": ".nix",
"mimetype": "text/nix",
"name": "nix"
}
},
"nbformat": 4,
"nbformat_minor": 5
}