From 4e4134f8b2c1611e7d40074af55dcef75476016f Mon Sep 17 00:00:00 2001
From: Arjun Satarkar <me@arjunsatarkar.net>
Date: Wed, 1 Jan 2025 00:01:12 +0530
Subject: Initial commit

---
 src/routes/+page.svelte | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 src/routes/+page.svelte

(limited to 'src/routes/+page.svelte')

diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
new file mode 100644
index 0000000..3519725
--- /dev/null
+++ b/src/routes/+page.svelte
@@ -0,0 +1,47 @@
+<script lang="ts">
+    import { DateTime } from "luxon";
+
+    const getCurrentYear = () => DateTime.now().year;
+    const getRelative = (year) =>
+        DateTime.local(year).toRelative({ locale: "en" });
+
+    let year = $state(getCurrentYear());
+    let sqrt = $derived(year ** 0.5);
+    let isPerfectSquare = $derived(Number.isInteger(sqrt));
+    let lastSqrt = $derived(isPerfectSquare ? sqrt - 1 : Math.floor(sqrt));
+    let nextSqrt = $derived(isPerfectSquare ? sqrt + 1 : Math.ceil(sqrt));
+    let last = $derived(lastSqrt ** 2);
+    let next = $derived(nextSqrt ** 2);
+    let nextRelative = $state(getRelative(next));
+
+    setInterval(() => {
+        year = getCurrentYear();
+        nextRelative = getRelative(next);
+    }, 500);
+</script>
+
+<div id="container">
+    {#if isPerfectSquare}
+        <div id="answer">Yes.</div>
+        <strong>{sqrt}</strong><sup>2</sup> = {year}.
+    {:else}
+        <div id="answer">No.</div>
+    {/if}
+    The last was
+    <ruby>{last}<rp> (</rp><rt>{lastSqrt}<sup>2</sup></rt><rp>)</rp></ruby>, and
+    the next is
+    <ruby>{next}<rp> (</rp><rt>{nextSqrt}<sup>2</sup></rt><rp>)</rp></ruby>, {nextRelative}!
+</div>
+
+<style>
+    #container {
+        text-align: center;
+        font-size: 2rem;
+    }
+    #answer {
+        font-size: 5em;
+        margin: 0;
+        font-weight: bold;
+        font-family: sans-serif;
+    }
+</style>
-- 
cgit v1.2.3-57-g22cb

