[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Extra juicy! | Home]

ITT: code a repeating digits detector

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

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 posts: 15
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]
Please support this website by donating Bitcoins to 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
If a post contains copyrighted or illegal content, please click on that post's [Report] button and fill out a post removal request
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.
This is a 4chan archive - all of the content originated from that site. This means that 4Archive shows an archive of their content. If you need information for a Poster - contact them.