"""
Precise snippet builder. For each snippet:
1. Write the command
2. Check exact len and diff count
3. Adjust by adding/removing easy or difficult chars
"""
SHIFTED = set('~!@#$%^&*()_+{}|:"<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ')
REACH = set('0123456789[]=-`')
RARE = set('\\|`~^')
DIFFICULT = SHIFTED | REACH | RARE

def info(s):
    dc = sum(1 for c in s if c in DIFFICULT)
    L = len(s)
    pct = round(dc / L * 100, 1)
    return L, dc, pct

def show(s, target_len, target_pct):
    L, dc, pct = info(s)
    lo, hi = target_len - 5, target_len + 5
    len_ok = lo <= L <= hi
    pct_ok = abs(pct - target_pct) <= 1.5
    ok = len_ok and pct_ok
    # How many diff chars needed at this length
    need_min = (target_pct - 1.5) * L / 100
    need_max = (target_pct + 1.5) * L / 100
    status = "OK" if ok else "FAIL"
    print(f"  [{status}] len={L} diff={dc} pct={pct}% need_diff=[{need_min:.1f}-{need_max:.1f}] at this len")
    if not ok:
        ideal_diff = round(target_pct * target_len / 100)
        print(f"    Adjust: target_len={lo}-{hi} (delta={target_len-L}), need ~{ideal_diff} diff (delta={ideal_diff-dc})")
    return ok

# I'll build snippets one by one, checking each.
# Key: I need to know EXACTLY which chars are difficult.
# Let me list common difficult chars in commands:
# Always diff: | - 0 1 2 3 4 5 6 7 8 9 A-Z * > < $ { } ( ) [ ] = _ + ! @ # % ^ & " : ? ~ ` \
# Always easy: a-z space . / , ; '

# Strategy for adding difficulty:
# - Change "echo 'done'" to "echo 'DONE'" adds 4 diff chars
# - Add digit to path: "/tmp/scan1.log" adds 1 diff
# - Use | pipe: adds 1 diff
# - Use - flag: adds 1 diff
# - Use $var: $ is diff
# - Use 2>/dev/null: 2 and > are 2 diff chars
# - Use numbers in echo messages: "found 30 files" adds 2 diff (3,0)

# For subtracting difficulty:
# - Replace uppercase with lowercase
# - Remove numbers
# - Remove pipes (combine commands differently)

all_snippets = {}

# ════════════════════════════════════════════════════════
# NOVICE: 115-125 chars, ~12 diff in ~120 (10%)
# ════════════════════════════════════════════════════════
# At len=120, need 10-14 diff chars for 8.5-11.5%
# Target: exactly 12 diff chars

print("=== NOVICE ===")
novice = []

# s1: pipes=4, hyphens=2, digits=4, uppercase=2 = 12 diff, pad to 120
# "cat /var/log/auth.log | grep -rn 'port 22' | sort | tail -30 | tee ..."
# |=1 -=1 |=1 |=1 -=1 3=1 0=1 |=1 = 8... plus 'port 22' has 2,2 = 2 more = 10
# Hmm, let me count char by char
s = "cat /var/log/auth.log | grep -rn 'port 22' | sort | tail -30 | tee /tmp/ssh.scan.log; echo 'filtered login entries saved'"
# c(e) a(e) t(e) (e) /(e) v(e) a(e) r(e) /(e) l(e) o(e) g(e) /(e) a(e) u(e) t(e) h(e) .(e) l(e) o(e) g(e) (e) |(d) (e) ...
# Let me just list the difficult ones: |, -, -, 2, 2, |, |, -, 3, 0, |
# That's | | | | - - - 2 2 3 0 = 11 diff
# Need 1 more. Change 'saved' to something... or add a digit.
# "echo 'filtered 30 login entries saved'" -> adds 3,0 but we already have 30 in tail -30
# Current len=121, diff should be recounted
L, dc, pct = info(s)
print(f"  s1 raw: len={L} diff={dc} pct={pct}%")

# This is getting tedious. Let me write a more automated approach.
# I'll write each snippet, check it, and adjust in a loop.

# Actually, the best approach: write a snippet, check it, then:
# - If need more diff chars: change some easy text to include diff chars
# - If need fewer diff chars: change some diff chars to easy ones
# - If need more length: add easy words
# - If need less length: remove easy words

# Let me just carefully craft 10 for each tier and check them all at once.

# NOVICE approach: use basic pipelines with exactly the right number of
# pipes, hyphens, and digits.

# For ~12 diff in ~120:
# Template: cmd | cmd | cmd | cmd; echo 'message'
# 3-4 pipes = 3-4 diff
# 2-3 flags with hyphens = 2-3 diff
# 3-4 digits = 3-4 diff
# 1-2 uppercase = 1-2 diff
# Total: ~12

# Let me create a function that counts precisely
def count_diff(s):
    chars = []
    for c in s:
        if c in DIFFICULT:
            chars.append(c)
    return len(chars), chars

# I'll write snippets and iteratively fix them.
# Format: (snippet, adjustments_needed)

novice_candidates = [
    "cat /var/log/auth.log | grep -rn 'port 22' | sort | tail -30 | tee /tmp/ssh.scan.log; echo 'filtered login entries saved'",
    "find /etc -name '*.conf' | sort | head -15 | tee /tmp/config.list.log; echo 'found all 15 config files stored on this host'",
    "ps aux | grep -v 'root' | sort -rn | head -10 | tee /tmp/user.proc.scan.list.log; echo 'process scan is complete here'",
    "ls -la /var/log/nginx | grep '.log' | sort -k5 | head -10 | tee /tmp/biggest.sorted.log; echo 'top log files pulled for scan'",
    "who | sort | head -10; last -n 20 | grep -v 'reboot' | tee /tmp/session.user.history.log; echo 'session history saved now'",
    "cat /tmp/port.list | sort | uniq | grep '80' | head -15 | tee /tmp/http.port.filtered.log; echo 'port filter complete on host'",
    "find /home -name '*.sh' | sort | head -20 | tee /tmp/scripts.found.log; echo 'found 20 shell scripts stored in home directories'",
    "du -sh /var/log/*.log | sort -rn | head -10 | tee /tmp/disk.hog.report.log; echo 'top ten largest log files found on host'",
    "ss -tlnp | grep -i 'listen' | sort -k4 | tee /tmp/listening.services.scan.log; echo 'found all services on this local host'",
    "grep -rn 'error' /var/log/syslog | sort | tail -30 | tee /tmp/syslog.error.report.log; echo 'all error entries scan finished'",
]

for i, s in enumerate(novice_candidates):
    dc, chars = count_diff(s)
    L = len(s)
    pct = round(dc/L*100, 1)
    target_diff = round(0.10 * L)
    delta = target_diff - dc
    print(f"  {i+1}. len={L} diff={dc} pct={pct}% need~{target_diff} delta={delta} chars={''.join(chars)}")

print()
print("I need to add more difficult characters to most novice snippets.")
print("Key adjustments:")
print("- Add uppercase to echo messages (e.g., 'DONE' instead of 'done')")
print("- Add more digits")
print("- Use 2>/dev/null which adds 2 diff chars (2 and >)")
