previndexinfo

code guessing, round #105, stage 2 (guessing)

started at ; stage 2 since . guess by

specification

need to go to bed let's get this over with. decompose a numberoid. submissions may be written in any language.

you can break numbers, or things like numbers such as matrices, into other numbers. like when you factor an integer, which is a kind of decomposition into prime factors. or breaking an integer into sums of powers (301.5 = 3⋅10² + 0⋅10¹ + 1⋅10⁰ + 5⋅10⁻¹). what makes it decomposition is that at the end you get an equality, and you can compute the original number from the decomposition. I feel like the point is normally to represent the value in terms of a simpler, smaller set, like how you decompose all integers into only primes, or all numbers into only powers of a given base. I guess that's the point behind this problem.

anything invertible is permitted, though, so you could submit an identity function for all I care. that doesn't really feel like decomposition, though. it feels like you left it just as composed as it was... so maybe it's not in the spirit of things.

your challenge, given a number or whatever you want really, is to decompose it such that the original value can be reconstructed from the result. as any language is allowed, there is no fixed API.

it's 40 minutes past my bedtime man never procrastinate

players

  1. GNU Radio Shows
  2. IFcoltransG
  3. kimapr
  4. Moja
  5. Olivia
  6. undefined

entries

you can download all the entries

entry #1

comments 0

post a comment


2fb529da80d8824754289922893b7058d02cabd5585bb95f53e61b1efac41f24.py Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from hashlib import sha256 as sha

def sha256(n):
    return int(sha(n.to_bytes(256,"big")).hexdigest(),base=16)

def compute_mapping(k, base):
    result=[-1]*base
    i=1

    while -1 in result:
        k=sha256(k)
        result[k%base]=i
        i+=1

    return result

def decompose(num, base, k):
    sign, num=(1, num) if num>=0 else (-1, -num)

    mapping=compute_mapping(k, base)

    digits=[]
    while num:
        digits.append(mapping[num%base])
        num//=base

    return sign, digits

def format_decomp(sign, digits, base, k):
    terms=[f"(sha256^{d}({k}) mod {base})⋅{base}^{i}" for i,d in enumerate(digits)]
    res="\n\t\t+ ".join(terms[::-1])

    if sign==-1:
        res=f"-({res})"

    return res

base=4096
k=746

num=int(input("Enter number: "))

sign, digits=decompose(num, base, k)

print(num, "=", format_decomp(sign, digits, base, k))

entry #2

comments 0

post a comment


awruff.py Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# puppydog does group decomposition!
r'''
 #############    ,------------------------.
#  __~~~~~__  #   | i wruff group theory ! |
# \_ O   O _/ #  <_________________________/
#   \  '  /   #
#    =====    #
 ##/~%~%~%~\##                                   '''
(source): "https://www.tumblr.com/shiftythrifting/\
823683395572858880/goodwill-grand-junction-colorado"

# =============== How To Use! ===============
# 1. Input the name of a finite group, such as
#    "C15" for the cyclic group of order 15.
# 2. Wait a little while for the number to get
#    decomposed by the puppydog.
# 3. Watch as the precise decomposition gets
#    printed to your terminal!
# ===========================================

def entry():
    numberoid = parse(input("Group please: "))
    print("Here you go!", classify_group(numberoid), "=", end=" ", flush=True)
    for Q, ext in decompose(numberoid):
        print(Q + ext, end="", flush=True)
    print(__doc__)

# puppydog says: here's the main algorithm! it's pretty pawsome!
def decompose(G):
    while True:
        try:
            Hs = G.unique_proper_subgroups()
            N = max(filter(G.is_normal, Hs), key=lambda H: H.order)
            Q = G / N
            yield classify_group(Q), classify_extension(N, G, Q)
            G = N
        except ValueError:
            yield classify_group(G), ""
            break

# puppydog says: this only supports cyclic groups for now :3
def parse(s):
    if s.startswith("C"):
        import sys
        sys.path.append([p for p in sys.path if p.endswith("site-packages")][0] + "/src")
        from finite_algebras import generate_cyclic_group
        return generate_cyclic_group(int(s[1:]))

# puppydog says: this only supports cyclic groups for now :3
def classify_group(G):
    if G.is_cyclic():
        return f"C{G.order}"

# puppydog says: this only supports direct products for now :3
def classify_extension(N, G, Q):
    Q = Q.copy_algebra([e[1:] for e in Q.elements])
    # puppydog reminds you of the schur-zassenhaus theorem
    from math import gcd
    if gcd(N.order, Q.order) == 1:
        if G.is_normal(Q):
            return "×"
        else:
            return "⋊"
    elif set(N.elements) <= set(G.center()):
        return "×ᶜ"
    # puppydog doesn't know how solve the extension problem :(
    return "?"

# puppydog is excited to play with you !
entry()

# puppydog says good bye... i love you <3
requirements.txt ASCII text
1
2
3
numpy
scipy
git+https://github.com/alreich/abstract_algebra.git

entry #3

comments 0

post a comment


factor.factor ASCII text
1
2
3
4
USING: io math.parser math.primes.factors prettyprint ;
IN: factor
: main ( -- ) readln string>number factors . ;
MAIN: main

entry #4

comments 0

post a comment


Soko.cs Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Linq;
using System.Collections.Generic;

namespace IloNanpa.Soko
{
    public class Soko
    {
        const byte Ala = 0;
        const byte Wan = 1;
        const byte Tu = Wan + Wan;
        const byte Luka = Tu + Tu + Wan;
        const byte Mute = Luka + Luka + Luka + Luka;
        const byte Ale = Mute + Mute + Mute + Mute + Mute;

        /**
         * soko kasi li ko pakala e ma la, ilo ni li soko e nanpa tawa toki pona
         */
        public static void Main(string[] pana)
        {
            Console.WriteLine("o pana e nanpa:");
            ulong nanpa;
            string linja = Console.ReadLine();
            // toki tawa jan kepeken
            Console.WriteLine("kili ona li ni:");
            if (ulong.TryParse(linja, out nanpa))
            {
                List<byte> kulupu = OSokoENanpaKepekenNasinNanpaPona(nanpa);
                Console.Write(string.Join(" ", kulupu.Select(n => Nanpa.NanpaTawaSitelen(n))));
                if (kulupu.SequenceEqual(new byte[] {5, 2, 1})) // o kute a e kalama pi jan Usawi
                    Console.Write(" 💃");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine(OKasiTawaNanpaTanSitelen(linja));
            }
        }

        /// <lili>
        ///   o ante e nanpa tawa sitelen kepeken nasin pu pona
        /// </lili>
        /// <poka>
        ///   ni li toki pona sama pu.
        ///
        ///   pana ona li sitelen ala li nanpa tawa sitelen.
        /// </poka>
        /// <pana nimi="nanpa">ni li nanpa li wan anu tu anu mute anu ala</pana>
        /// <kili>kulupu nanpa li nanpa e ijo la kulupu li jo e nanpa</kili>
        static List<byte> OSokoPuENanpa(ulong nanpa)
        {
            List<byte> kulupu = new List<byte>();
            // tenpo open la mi kama lili e nanpa lon tenpo sike
            // mi kepeken nanpa sitelen ale
            // te "wile nanpa en wan li ale" to li sama toki pona a a a
            while (nanpa + 1 > Ale)
            {
                nanpa -= Ale;
                kulupu.Add(Ale);
            }
            while (nanpa + 1 > Mute)
            {
                nanpa -= Mute;
                kulupu.Add(Mute);
            }
            while (nanpa + 1 > Luka)
            {
                nanpa -= Luka;
                kulupu.Add(Luka);
            }
            while (nanpa + 1 > Tu)
            {
                nanpa -= Tu;
                kulupu.Add(Tu);
            }
            while (nanpa + 1 > Wan)
            {
                nanpa -= Wan;
                kulupu.Add(Wan);
            }
            // tenpo pini la mi lukin e ni: nanpa li lon ala lon
            if (Ala >= kulupu.Count)
            {
                return new List<byte> { Ala };
            }
            return kulupu;
        }

        /// <lili>
        ///   o ante e nanpa tawa sitelen kepeken nasin pi nasin nanpa pona
        /// </lili>
        /// <poka>
        ///   nasin ni li kepeken nimi ale la nanpa open li mute ale e nanpa pini.
        ///
        ///   pana ona li sitelen ala li nanpa tawa sitelen.
        /// </poka>
        /// <pana nimi="nanpa">ni li nanpa li wan anu tu anu mute anu ala</pana>
        /// <kili>kulupu nanpa li nanpa e ijo la kulupu ni li jo e nanpa</kili>
        static List<byte> OSokoENanpaKepekenNasinNanpaPona(ulong nanpa)
        {
            // ni la nanpa li mute: nanpa pi nimi ale li lili, nanpa ni li suli
            ulong nanpaMute = nanpa / Ale;
            if (nanpaMute > Ala)
            {
                List<byte> tuLili;
                byte nanpaLili = (byte)(nanpa % Ale);
                // nimi "kipisi" anu nimi "%" li pona ala tawa mi
                // taso, nimi "tu" li pana e sona pi nasin nanpa, sona li tu ante a!
                if (Ala >= nanpaLili)
                    tuLili = new List<byte>();
                else
                    tuLili = OSokoPuENanpa(nanpaLili);
                List<byte> tuSuli = OSokoENanpaKepekenNasinNanpaPona(nanpaMute);
                tuSuli.Add(Ale);
                tuSuli.AddRange(tuLili);
                return tuSuli;
            }
            return OSokoPuENanpa(nanpa);
        }

        /// <lili>
        ///   o ante e sitelen tawa nanpa kepeken nasin nanpa pona
        /// </lili>
        /// <poka>
        ///   kasi li kama sitelen lipu li kepeken ma la, kasi li nasin soko ala
        /// </poka>
        /// <pana nimi="ona">ni li sitelen. kon li insa li sama sona tan sitelen la sitelen ni li kon sama nanpa lon</pana>
        /// <kili>nanpa li tan sitelen ona</kili>
        static ulong OKasiTawaNanpaTanSitelen(string ona)
        {
            ulong aleWan = Ala;
            byte nanpaTan = Ale;
            foreach (string sitelen in ona.Trim().Split((char[])null))
            {
                if (string.IsNullOrEmpty(sitelen)) continue;
                string sitelenPona = sitelen.ToLower();
                if (sitelenPona.Any(sitelenLili => sitelenLili is not ((>= 'a') and (<= 'z')))) continue;
                byte nanpa = Nanpa.SitelenTawaNanpa(sitelenPona);
                if (nanpa == Ale && nanpaTan < Ale)
                {
                    aleWan *= Ale;
                }
                else
                {
                    aleWan += nanpa;
                    nanpaTan = nanpa;
                }
            }
            return aleWan;
        }

        /**
         * ilo ni li ante e nanpa e sitelen
         */
        class Nanpa
        {
            internal static string NanpaTawaSitelen(byte nanpa) => nanpa switch
                {
                    Ala => "ala",
                    Wan => "wan",
                    Tu => "tu",
                    Luka => "luka",
                    Mute => "mute",
                    Ale => "ale",
                    _ => throw new ArgumentOutOfRangeException("nanpa", nanpa, $"nanpa {nanpa} li ken ala sitelen la, mi li alasa ala e ni"),
                };

            internal static byte SitelenTawaNanpa(string sitelen) => sitelen switch
                {
                    "ala" => Ala,
                    "wan" => Wan,
                    "tu" => Tu,
                    "luka" => Luka,
                    "mute" => Mute,
                    "ale" => Ale,
                    "ali" => Ale, // toki ante
                    _ => throw new ArgumentOutOfRangeException("sitelen", sitelen, $"mi alasa ala e sitelen nanpa ala ni: {sitelen}"),
                };
        }
    }
}

entry #5

comments 0

post a comment


compose ASCII text
1
2
3
4
die() { printf -- "$1" >&2; exit 1; }
[ "$#" -eq 2 ] || die 'Usage: compose SRC DEST\n'
[ "$2" = '-' ] && set -- "$1" /dev/stdout
cat "$1"/* > "$2"
decompose ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
die() { printf -- "$1" >&2; exit 1; }
[ "$#" -eq 2 ] || die 'Usage: decompose SRC DEST\n'
[ "$1" = '-' ] && set -- /dev/stdin "$2"
{ exec <"$1"; } 2>/dev/null || die 'source file spoiled\n'
{ mkdir -p "$2"; } 2>/dev/null
{ cd "$2"; } 2>/dev/null || die 'destination directory dissonance\n'
ls | read x && die 'destination directory full\n'
od -vAn -bw1 | (seq 1 65536 | while read i; do
  i=$(printf '%.3x' $i)
  [ "${#i}" -eq 3 ] || { rm *; die 'too big for me >.<\n'; };
  read v <&67
  if [ -z "$v" ]; then break; fi
  printf -- '\'"$v" > $i
done) 67<&0

entry #6

comments 0

post a comment


primerer.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from functools import cache

LIMIT = 20000 # <- keep low (just don't ask for the decomposition of a big number and you'll be fine :3)
OP = 3 # <- raise this to make it funnier
# ^ the bigger the less interesting

@cache
def hyperop(n: int, a: int, b: int) -> int:
    """i stole this but idk where"""
    if n == 0:
        return b + 1
    if n == 1:
        return a + b
    if n == 2:
        return a * b
    if n == 3:
        return a ** b
    result: int = 1
    for _ in range(b):
        result = hyperop(n-1, a, result)
        if result > LIMIT: # if it's too big we need to discard it asap
            return LIMIT + 1
    return result

primerer: list[int] = []
no: dict[int, list[list[int]]] = {}

def check(v: int = 1, chain: list[int] | None = None):
    """it's a bit slow but it works"""
    if chain is None:
        chain = [v]
    for n in primerer:
        # print(f"{n} {'*' * (OP - 1)} {v}")
        t = hyperop(OP, n, v)
        new_chain = [n] + chain
        if t <= LIMIT:
            if t in no:
                if new_chain not in no[t]:
                    no[t].append(new_chain)
                    print("Duplicate!!")
                    print(f"{v=} {n=} {t=} {chain=} {no[t]=}")
            else:
                no[t] = [new_chain]
            check(t, new_chain)
        else:
            break # primerer is sorted, no need to raise it to even greater powers if it already fails
    
for i in range(2, LIMIT + 1):
    if i % 100 == 0:
        print(i)
    if i not in no:
        primerer.append(i)
        if hyperop(OP, 2, i) <= LIMIT or hyperop(OP, i, 2) <= LIMIT: # HYPEROPTIMIZER2000
            check()

def decompose(x):
    assert x <= LIMIT
    if x in no:
        return no[x][0]
    if x in primerer:
        return [x, 1]
    raise KeyError("?")

def recompose(x: list[int], y: int = 1):
    if not x:
        return y
    return recompose(x[:-1], x[-1] ** y)

# Usage: decompose(<your number>) gives a list, recompose(<list>) gives your number back
# keep your number below LIMIT
# Example: decompose(1331) >>> [11, 3, 1] ; recompose([11, 3, 1]) >>> 1331
# Since 11 ** 3 ** 1 = 1331

# list(filter(lambda x: x not in primerer, range(LIMIT))) is fun