aboutsummaryrefslogtreecommitdiff
path: root/src/routes/+page.svelte
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-12-31 18:31:12 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-12-31 18:31:12 +0000
commit4e4134f8b2c1611e7d40074af55dcef75476016f (patch)
treee3a93c923dccd4985b4d4de8832e054cb4ebdcf0 /src/routes/+page.svelte
downloadis-the-year-a-perfect-square-4e4134f8b2c1611e7d40074af55dcef75476016f.tar
is-the-year-a-perfect-square-4e4134f8b2c1611e7d40074af55dcef75476016f.tar.gz
is-the-year-a-perfect-square-4e4134f8b2c1611e7d40074af55dcef75476016f.zip
Initial commit
Diffstat (limited to 'src/routes/+page.svelte')
-rw-r--r--src/routes/+page.svelte47
1 files changed, 47 insertions, 0 deletions
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>