initial commit
commit
77b32f9e2c
@ -0,0 +1,175 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Caches
|
||||
|
||||
.cache
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
@ -0,0 +1,24 @@
|
||||
# Shortest Sum of Squares
|
||||
|
||||
This is a simple web application that shows a precomputed list of the shortest sum of squares for a given number. The list is
|
||||
generated in Julia and then exported as a text file. The web application is built using Vite and SolidJS.
|
||||
|
||||
## Usage
|
||||
|
||||
### Setup
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
### Development
|
||||
|
||||
```bash
|
||||
bun dev
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
```bash
|
||||
bun run build
|
||||
```
|
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Shortest Sum of Squares</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="./src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,54 @@
|
||||
using Base
|
||||
using DataStructures
|
||||
|
||||
found = Dict{Int, Array{Int64}}()
|
||||
|
||||
function count_nz(seq)
|
||||
return length([i for i in seq if i > 0])
|
||||
end
|
||||
|
||||
for i1 in 0:32
|
||||
for i2 in i1:32
|
||||
for i3 in i2:32
|
||||
for i4 in i3:32
|
||||
s = i1 ^ 2 + i2 ^ 2 + i3 ^ 2 + i4 ^ 2
|
||||
|
||||
if s <= 1000
|
||||
seq = [ i1, i2, i3, i4 ]
|
||||
|
||||
# if !haskey(found, s)
|
||||
# found[s] = seq
|
||||
# end
|
||||
|
||||
if haskey(found, s)
|
||||
s_prev = found[s]
|
||||
|
||||
if count_nz(seq) < count_nz(s_prev)
|
||||
found[s] = seq
|
||||
end
|
||||
else
|
||||
found[s] = seq
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
found = sort(found)
|
||||
|
||||
delete!(found, 0)
|
||||
|
||||
# for i = 1:1000
|
||||
# if haskey(found, i)
|
||||
# print("x")
|
||||
# else
|
||||
# print("_")
|
||||
# end
|
||||
# end
|
||||
|
||||
for (sum, seq) in found
|
||||
println("$(join(["$(i)^2" for i in seq if i > 0], " + ")) = $(sum)")
|
||||
end
|
||||
|
||||
# println(length([k for (k, v) in found if length([i for i in v if i != 0]) == 4]))
|
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "shortest-sum-of-squares",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/katex": "^0.16.7",
|
||||
"solid-devtools": "^0.29.2",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.0.11",
|
||||
"vite-plugin-solid": "^2.8.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/geist-sans": "^5.0.3",
|
||||
"katex": "^0.16.10",
|
||||
"solid-js": "^1.8.11"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,94 @@
|
||||
import '@fontsource/geist-sans/latin.css'
|
||||
import 'katex/dist/katex.min.css'
|
||||
|
||||
import katex from 'katex'
|
||||
|
||||
import './styles.css'
|
||||
|
||||
import { For, Show, createEffect, createMemo, createResource, createSignal } from 'solid-js'
|
||||
import { render } from 'solid-js/web'
|
||||
|
||||
const LaTeX = ({ content }) => <span class="latex" ref={el => katex.render(content, el)} />
|
||||
|
||||
const generateScript = (value, expression) => {
|
||||
const vector = expression.split('+').map(part => part.split('^')[0].trim())
|
||||
|
||||
return `
|
||||
# cambia queste due righe con i valori corretti
|
||||
file="my-file.pdf"
|
||||
sides="two-sided-long-edge" # otherwise use two-sided-short-edge or one-sided
|
||||
|
||||
# stampa ${value} = ${expression} copie
|
||||
for sq in ${vector.join(' ')}; do
|
||||
lpr -P cdclf -# $sq -o media=a4 -o fit-to-page -o sides=$sides $file
|
||||
done` // <- this missing "\n" is intentional
|
||||
} // <- this missing "\n" is intentional
|
||||
|
||||
const ResultItem = ({ value, expression }) => {
|
||||
const handleClick = () => {
|
||||
navigator.clipboard.writeText(generateScript(value, expression))
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="result-item" title="Click to copy shell snippet" onClick={handleClick}>
|
||||
<LaTeX content={`${value} = ${expression}`} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const App = ({}) => {
|
||||
const [rawData] = createResource(() => fetch('/shortest-squares-v2.txt').then(res => res.text()))
|
||||
const dict = createMemo(() =>
|
||||
Object.fromEntries(
|
||||
(rawData() ?? '')
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.map(line => {
|
||||
const [expression, value] = line.split('=').map(part => part.trim())
|
||||
return [parseInt(value), expression]
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
createEffect(() => {
|
||||
console.log('dict', dict())
|
||||
})
|
||||
|
||||
const [text, setText] = createSignal('')
|
||||
|
||||
const results = createMemo(() => {
|
||||
const entries = Object.entries(dict())
|
||||
const query = text().trim()
|
||||
|
||||
if (query === '') return entries
|
||||
|
||||
if (!/^\d+$/.test(query)) return entries
|
||||
|
||||
return entries.filter(([value]) => value.toString().includes(query))
|
||||
})
|
||||
|
||||
const SHOW_COUNT = 8
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1>Shortest Sum of Squares</h1>
|
||||
<p>
|
||||
Click a sum of squares to copy the <code>lpr</code> shell command to print that number of copies
|
||||
</p>
|
||||
<input type="text" value={text()} onInput={e => setText(e.target.value)} />
|
||||
<div classList={{ 'results': true, 'has-more': results().length > SHOW_COUNT }}>
|
||||
<For each={results().slice(0, SHOW_COUNT)}>
|
||||
{([value, expression]) => <ResultItem value={value} expression={expression} />}
|
||||
</For>
|
||||
<Show when={results().length === 0}>
|
||||
<p>
|
||||
For now we pre-computed the shortest sums of squares up to 1000 as you shouldn't need to print more than
|
||||
that many copies of a document. Paper is a <em>precious resource</em> after all.
|
||||
</p>
|
||||
</Show>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(() => <App />, document.getElementById('app'))
|
@ -0,0 +1,169 @@
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
font-family: inherit;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 4rem 0;
|
||||
|
||||
font-family: 'Geist Sans', sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
|
||||
color: #333;
|
||||
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
padding: 1rem 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Components */
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4 {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
text-wrap: balance;
|
||||
text-align: center;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 18px;
|
||||
font-weight: 400;
|
||||
|
||||
max-width: 60ch;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
font-family: 'Fira Code', 'Menlo', monospace;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 95%;
|
||||
}
|
||||
|
||||
input[type='text'] {
|
||||
height: 2.5rem;
|
||||
|
||||
padding: 0 1rem;
|
||||
border: 1px solid #ddd;
|
||||
background: #fff;
|
||||
border-radius: 5rem;
|
||||
outline: none;
|
||||
|
||||
font-size: 18px;
|
||||
|
||||
text-align: center;
|
||||
|
||||
&:hover:not(:focus) {
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
}
|
||||
|
||||
.has-more {
|
||||
position: relative;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 5rem;
|
||||
|
||||
pointer-events: none;
|
||||
|
||||
z-index: 10;
|
||||
|
||||
background: linear-gradient(0deg, #ffffff, #ffffff00);
|
||||
}
|
||||
}
|
||||
|
||||
/* Structure */
|
||||
|
||||
#app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
align-items: center;
|
||||
|
||||
gap: 2rem;
|
||||
|
||||
max-width: 100%;
|
||||
|
||||
& > input {
|
||||
width: 100%;
|
||||
max-width: 30rem;
|
||||
|
||||
box-shadow: 0 0 15rem #00000018;
|
||||
}
|
||||
|
||||
.results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
user-select: none;
|
||||
|
||||
gap: 0.25rem;
|
||||
|
||||
text-align: center;
|
||||
|
||||
& > .result-item {
|
||||
cursor: pointer;
|
||||
|
||||
display: grid;
|
||||
place-content: center;
|
||||
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.5rem;
|
||||
|
||||
&:nth-child(1) {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
|
||||
&:hover {
|
||||
background: #f2f2f2;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
&:nth-child(1) {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
&:not(:nth-child(1)) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false,
|
||||
|
||||
// JSX
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "solid-js"
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import solidPlugin from 'vite-plugin-solid'
|
||||
// import devtools from 'solid-devtools/vite';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
// devtools(),
|
||||
solidPlugin(),
|
||||
],
|
||||
server: {
|
||||
port: 3000,
|
||||
},
|
||||
build: {
|
||||
target: 'esnext',
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue