Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Puzzle Regex: Letter Frequency Arithmetic Sequence

by tybalt89 (Monsignor)
on Oct 17, 2017 at 23:47 UTC ( [id://1201541]=note: print w/replies, xml ) Need Help??


in reply to Re: Puzzle Regex: Letter Frequency Arithmetic Sequence
in thread Puzzle Regex: Letter Frequency Arithmetic Sequence

A regex to find if a letter occurs exactly $n times.

Is this what you were looking for as a first step?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1201500 use strict; use warnings; my @words = glob '{i,x}' x 6; print "@words\n"; my $n = 1; # number of times a letter occurs in a word my @oneletter = grep /^(?| (?=.*?(.)(?!.*\1)) (?: (?:(?!\1).)* \1 ){$n} (?:(?!\1).)* | (?=.*(.)) (?: (?:(?!\1).)* \1 ){$n} (?:(?!\1).)* )$ /x, @words; print "\n@oneletter\n\n", scalar @oneletter, "\n";

Update: fails for some test cases

Replies are listed 'Best First'.
Re^3: Puzzle Regex: Letter Frequency Arithmetic Sequence
by QM (Parson) on Oct 19, 2017 at 13:17 UTC
    Can you share some interesting test cases?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found