A space to discuss and keep up software development and manage your software career
An inclusive community for gaming enthusiasts
News and discussion of science and technology such as AI, VR, cryptocurrency, quantum computing, and more.
From composing and gigging to gear, hot music takes, and everything in between.
Discussing AI software development, and showing off what we're building.
Movie and TV enthusiasm, criticism and everything in-between.
A general discussion space for the Forem community. If it doesn't have a home elsewhere, it belongs here
Memes and software development shitposting
Web design, graphic design and everything in-between
A community of golfers and golfing enthusiasts
Your central hub for all things security. From ethical hacking and CTFs to GRC and career development, for beginners and pros alike
For engineers building software at scale. We discuss architecture, cloud-native, and SRE—the hard-won lessons you can't just Google
Discussing the core forem open source software project — features, bugs, performance, self-hosting.
A collaborative community for all things Crypto—from Bitcoin to protocol development and DeFi to NFTs and market analysis.
A place for parents to the share the joys, challenges, and wisdom that come from raising kids. We're here for them and for each other.
A community for makers, hobbyists, and professionals to discuss Arduino, Raspberry Pi, 3D printing, and much more.
Regex to the rescue!
function passwordcount() { let inputtext = document.querySelector('.puzzle-input').innerHTML; let pwrange = inputtext.split('-').map(v => parseInt(v, 10)); let pwcount = 0; //let consecutivesame = /(11|22|33|44|55|66|77|88|99|00)/; /*for part 1*/ let consecutivesame = /(([^1]|^)11([^1]|$)|([^2]|^)22([^2]|$)|([^3]|^)33([^3]|$)|([^4]|^)44([^4]|$)|([^5]|^)55([^5]|$)|([^6]|^)66([^6]|$)|([^7]|^)77([^7]|$)|([^8]|^)88([^8]|$)|([^9]|^)99([^9]|$)|([^0]|^)00([^0]|$))/; for(let i = pwrange[0]; i < pwrange[1]; i++) { let istr = i.toString(); let iparts = istr.split(''); let sortstr = iparts.sort().join(''); if(sortstr == istr && consecutivesame.test(istr)) { pwcount++; } } return pwcount; }
Just to make it clear: ([^1]|^)11([^1]|$) says:
([^1]|^)11([^1]|$)
([^1]
|
^)
11
$)
Essentially this searches for "11" surrounded by anything that isn't a 1. Then I repeated it for the other digits.
Wow, nice solution.
Interesting, I used the same regex for my part 1 too
Nice solution. I've not used rust, but I hear it's really fast!
Nice, although I wouldn't inflict that on my team-mates!
It is a bit of a monster.
I've being trying to think of a way to refine it, but then again I'm not likely to be asked to find numbers like that outside of AoC :D
Even I, someone who loves regexes so much that I made a regex that converted words to Pig Latin, find this hard to read!
It makes sense! I just worry that if I look away from it for too long it will have changed...
It’s still more readable than the regex that “matches a b c where a+b=c” (a,b,c being any rational number)
Wow. ._.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Regex to the rescue!
Just to make it clear:
([^1]|^)11([^1]|$)
says:([^1]
find anything other than 1|
or^)
the beginning of the string. The parentheses create a capture group that allows the use of|
to mean "or".11
find "11"([^1]
find anything other than 1|
or$)
the end of the string.Essentially this searches for "11" surrounded by anything that isn't a 1. Then I repeated it for the other digits.
Wow, nice solution.
Interesting, I used the same regex for my part 1 too
Nice solution. I've not used rust, but I hear it's really fast!
Nice, although I wouldn't inflict that on my team-mates!
It is a bit of a monster.
I've being trying to think of a way to refine it, but then again I'm not likely to be asked to find numbers like that outside of AoC :D
Even I, someone who loves regexes so much that I made a regex that converted words to Pig Latin, find this hard to read!
It makes sense! I just worry that if I look away from it for too long it will have changed...
It’s still more readable than the regex that “matches a b c where a+b=c” (a,b,c being any rational number)
Wow. ._.