/*
FileAttachments:
  ./cendree_DivMod_count_1024_256_digits.csv: ./cendree_DivMod_count_1024_256_digits.csv
  ./cendree_QuotRem_count_1024_256_digits.csv: ./cendree_QuotRem_count_1024_256_digits.csv
*/

// Import expansions from file.
// Odd numbers are injected by replacing the first entry of each row with "1"
asIntegers = (x) => {
  let xs = x.split("\n").map((y) => y.split(",").map((z) => +z))
  return [...xs, ...(xs.map((ys) => ys.with(0, 1)))]
};

adicExpansionsDivMod = FileAttachment(
  "./cendree_DivMod_count_1024_256_digits.csv"
).text().then(asIntegers);
adicExpansionsQuotRem = FileAttachment(
  "./cendree_QuotRem_count_1024_256_digits.csv"
).text().then(asIntegers);

import { expansions as oldExpansions } with { base as base } from "../../../../interactive/p-adics/showAdic.ojs";

expansionsOrAdics = baseSelector == "b-adic"
  ? oldExpansions
  : baseSelector == "κ-adic, balanced"
    ? adicExpansionsDivMod
    : baseSelector == "κ-adic, binary"
      ? adicExpansionsQuotRem
      : d3.range(adicExpansionsQuotRem.length / 10).map(() => d3.range(15).map(() => +(Math.random() > 0.5)))

import { plot } with {
  expansionsOrAdics as expansions,
  embedBase as embedBase,
  geometric as geometric,
} from "../../../../interactive/p-adics/showAdic.ojs";

viewof baseSelector = Inputs.radio([
  "b-adic",
  "κ-adic, balanced",
  "κ-adic, binary",
  "Random Binary",
], {
  value: "b-adic",
  label: "Expansions",
});

viewof base = Inputs.range([2, 5], {
  value: 2,
  step: 1,
  label: "Base of expansions (b)",
  disabled: baseSelector != "b-adic",
});

viewof embedBase = Inputs.range([2, 5], {
  value: 2,
  step: 0.1,
  label: "Embedding base (p)",
});

viewof geometric = Inputs.range([0.005, 0.995], {
  value: 0.9,
  step: 0.005,
  label: "Geometric ratio (c)",
});

plot
