Math::N...stoWaltz(3)
πΈ NAME πΈ
Math::NumSeq::MephistoWaltz β the Mephisto waltz sequence, bestie π (it's a Perl manual page, section 3, and yes the module name is doing the most but we love her)
β¨ SYNOPSIS β¨
use Math::NumSeq::MephistoWaltz;
my $seq = Math::NumSeq::MephistoWaltz->new;
my ($i, $value) = $seq->next;
that's it. that's the whole vibe. three lines and you're in π«Ά
π DESCRIPTION π
okay so this sequence is literally the Mephisto waltz, and what it actually is: the count mod 2 of ternary digit 2s in i. no cap, that's the whole thing.
0,0,1, 0,0,1, 1,1,0, ... (A064990)
starting i=0
i=0 has no 2s so value=0, and same energy for i=1, value=0. then i=2 has one 2 so value=1. iconic behavior honestly.
the sequence can also be expressed as a morphism starting from single term 0 and repeatedly expanding:
0 -> 0,0,1
1 -> 1,1,0
so:
0
0,0,1
0,0,1, 0,0,1, 1,1,0,
0,0,1, 0,0,1, 1,1,0, 0,0,1, 0,0,1, 1,1,0, 1,1,0, 1,1,0, 0,0,1
| original | | copy | | 0<->1 flipped |
+-----------------+ +-----------------+ +-----------------+
so what's the expansion actually doing? the way that it keeps the first third exactly the same, then appends a copy of it, then appends a 0<->1 flipped copy of it. three parts, no notes. π
π FUNCTIONS π
peep "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes, because this module is a team player.
$seq = Math::NumSeq::MephistoWaltz->new ()β create and return a brand new sequence object. main character energy, freshly spawned β¨
π¦ Random Access π¦
$value = $seq->ith($i)β return the$i'th MephistoWaltz value, which is the count mod 2 of the ternary digit2s in$i. jump straight to the tea, no waiting in line β$bool = $seq->pred($value)β return true if$valueoccurs in the sequence, which literally just means0or1. that's the whole test, bestie, it's not deep π
π FORMULAS π
the calculation can also be made in a power-of-3 base like 9, 27, 81, etc instead of just 3. for example in base 9, digits 2, 5, 6, 7 have a one (mod 2) ternary 2. these base 9 digits correspond to the 1s in the initial sequence 0,0,1, 0,0,1, 1,1,0 shown above. so yeah, base 9 is lowkey just the same girl wearing a different outfit π
π SEE ALSO π
Math::NumSeqMath::NumSeq::DigitSumModulo
go read those too, they're the extended universe π«Ά
π HOME PAGE π
http://user42.tuxfamily.org/math-numseq/index.html
π LICENSE π
Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see http://www.gnu.org/licenses/.
fr fr read the license, bestie, it's giving "legally binding but make it cute" π
and that's the whole page, mwah π β this was perl v5.42.0, dated 2025-07-25, and it lives at Math::N...stoWaltz(3) in the manual, iykyk. slay, go compute some waltzes πβ¨
π¦ where this page comes from
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms