[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
ITT: code a repeating digits detector
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 15
Thread images: 1
Lets see how much of a novice you are anon
>>
>>50770822
Don't even need to program that, though it's not the most elegant solution (if you guys have any regex tips, please lemme know)
grep -P -q '(1{2,}|2{2,}|3{2,}|4{2,}|5{2,}|6{2,}|7{2,}|8{2,}|9{2,}|0{2,})'.
>>
>>50770866
Just use the digit code instead of typing them all out.

eg. ^(\d)\1+$
>>
>>50770932
Woah, that's pretty damn cool. Managed to shorten it to grep -P -q '(\d)\1' to check for existence, or grep -P -o '(\d)\1{2,}' for outputting matches.
>>
int rptdig(int a){
int b=-1,c=0;
while(a){
if(b==a%10||b==-1){b=a%10; a/=10;++c;}
else break;
}
return c;
}

/thread
>>
>>50770822
int rptdig(int a){
if(!a)return 1;
int c=1;
for(int b=a%10;b==(a=a/10)%(10);++c);
return c;
}
>>
>>50771668
>>50771656
Doesn't handle cases where there are no repeating digits - and it doesn't work anyway.

You should at least do something like:
int derp(int a) {
if(!a) return -1;
for(int b=a%10;a;b=a%10) if(b==(a=a/10)%10) return a%10;
return -1;
}
>>
>>50771668
>s/==/!=/
Still not good, but at least it works now.
>>
>>50771857
Scratch that, you never set b after initialization, so it's still fucked.
>>
>>50770822
Can't do it. I don't belong here.
>>
>>50772064
It's just the OP's homework. He doesn't belong here either.
>>
>>50771857
>>50771834
>doesn't handle cases where there are no repeating digits

this post works and does that >>50771668
Is this what you were referring to?

It outputs the number of consecutive digits
if it is a single digit it puts out one
if its dubs it puts out two
trips? 3
quads? 4

There will never be an int case with less than one digit
>>
>>50772610
It doesn't, did you even try it?

You return 1 if a is 0, how does that even make sense?
>>
>>50770822
Do you want a script that highlights dubs or something?
>>
>>50774091
Yes it does.
It works. For all numbers barring infinity; you have at least one digit. If for some odd reason you decide to use infinity with this, then you could have it return infinite digits.

The code certainly compiles and produces a result.
Thread replies: 15
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.