惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
腾讯CDC
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
L
LangChain Blog
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
IT之家
IT之家
A
About on SuperTechFans
H
Help Net Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Weekly Challenge: Vowels and numbers
Simon Green · 2026-05-19 · via DEV Community

Simon Green

Weekly Challenge 374

Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding.

Challenge, My solutions

Task 1: Count Vowel

Task

You are given a string.

Write a script to return all possible vowel substrings in the given string. A vowel substring is a substring that only consists of vowels and has all five vowels present in it.

My solution

It seems many Team PWC users sent Mohammad "so many emails" when the examples did not match the expected output. As I follow TDD when completing the challenges, I also picked this up.

For this task, I have two loops to generate all possible substrings. The variable start goes from 0 to 5 less than the length of the string. This is because a valid answer needs to have at least five letters. The variable end goes from start + 5 to the length of the string.

I then check if the substr contains each vowel and does not contain any non-vowels. If it does, I add it to the solution list.

def count_vowel(input_string: str) -> list[str]:
    l = len(input_string)
    vowels = ["a", "e", "i", "o", "u"]
    solution = []

    for start in range(l - 4):
        for end in range(start+5, l+1):
            substr = input_string[start:end]
            if (
                all(v in substr for v in vowels) and
                not any(c not in vowels for c in substr)
            ):
                solution.append(substr)

    return solution

Enter fullscreen mode Exit fullscreen mode

The Perl logic uses a variable length instead of end to reflect how the substr function works.

use List::Util 'any';

sub main ($input_string) {
    my $l        = length($input_string);
    my @vowels   = (qw/a e i o u/);
    my @solution = ();

    foreach my $start ( 0 .. $l - 4 ) {
        foreach my $length ( 5 .. $l - $start ) {
            my $substr = substr( $input_string, $start, $length );

            if ( $substr !~ /^[aeiou]+$/ ) {
                next;
            }

            if ( any { index( $substr, $_ ) == -1 } @vowels ) {
                next;
            }

            push @solution, $substr;
        }
    }

    say "(" . join( ", ", map { qq{"$_"} } @solution ) . ")";
}

Enter fullscreen mode Exit fullscreen mode

Examples

The order in the output differs from the examples.

$ ./ch-1.py aeiou
("aeiou")

$ ./ch-1.py aaeeeiioouu
("aaeeeiioou", "aaeeeiioouu", "aeeeiioou", "aeeeiioouu")

$ ./ch-1.py aeiouuaxaeiou
("aeiou", "aeiouu", "aeiouua", "eiouua", "aeiou")

$ ./ch-1.py uaeiou
("uaeio", "uaeiou", "aeiou")

$ ./ch-1.py aeioaeioa
()

Enter fullscreen mode Exit fullscreen mode

Task 2: Largest Same-digits Number

Task

You are given a string containing 0-9 digits only.

Write a script to return the largest number with all digits the same in the given string.

My solution

I always look at the examples to fill in answers that aren't mentioned in the task description. One thing I wasn't sure if the numbers had to be consecutive or not. In this instance, the examples don't help answer that question. I made the decision that they didn't need to be.

My first thought was to sort by the frequency of the numbers and the number if it had the same frequency. But this would work with numbers like 100 (where 0 appears most often).

The solution I came up with was to count the frequency of each number using the Counter function. I then loop through the dict (hash in Perl) to find the highest number.

from collections import Counter
import re

def largest_number(input_string) -> int:
    if not re.search(r'^\d+$', input_string):
        raise ValueError("String should only contain numbers")

    largest_number = 0
    freq = Counter(input_string)

    for digit, count in freq.items():
        number = int(digit * count)
        if number > largest_number:
            largest_number = number

    return largest_number

Enter fullscreen mode Exit fullscreen mode

The Perl solution follows the same logic.

Examples

$ ./ch-2.py 6777133339
3333

$ ./ch-2.py 1200034
4

$ ./ch-2.py 44221155
55

$ ./ch-2.py 88888
88888

$ ./ch-2.py 11122233
222

Enter fullscreen mode Exit fullscreen mode