Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Dubs checking algos.

Name: Anonymous 2014-12-16 21:47

Post your dubs-checking algorithms. We have a lot spread out but it might be nice to collect all the good ones in a single thread. Revised version of an earlier one I wrote:

Number isDubs := method(
if(self toBase(11) asNumber mod(10) == 0,
Exception raise("checkem"); true,
false))

Name: Anonymous 2014-12-16 22:03

So Io doesn't even have immutable variables? How pathetic.

Name: Anonymous 2014-12-16 23:38

>>2
It does though.

Name: Anonymous 2014-12-17 14:28

try:
check_em()
except NoDubsException:
pass

Name: Anonymous 2014-12-20 16:41

dubs = (==0) . flip mod 11 . flip mod 100

Name: Anonymous 2014-12-20 18:41

uint check_dubs(uint n) {
return (n % 10) == ((n / 10) % 10);
}


Checked from my iPhone.

Name: Anonymous 2014-12-20 19:38

say 'dubs' if m/([0-9])\g1$/

Name: Anonymous 2014-12-22 7:10

``#include <stdio.h>

void main()
{
int i;
for(i =0;i<100;i++)
{
if(i%11)
{
printf("Singles\n");
}
else
{
printf("%d, Check 'em\n",i);
}
}
}``

i can never figure out code tags

Name: Anonymous 2014-12-22 20:02

Name: Anonymous 2014-12-22 21:23

>>6
dubs = liftM (==) (flip mod 10) (flip mod 10 . (/ 10))

Name: Anonymous 2014-12-22 23:34

>>9
12/22/14
Jesus, what kind of Mongol uses that date format?

Name: Anonymous 2014-12-22 23:43

>>11

Mongols, of course.

Name: Anonymous 2014-12-23 19:27

>>8
Learn to program. Your algorithm is broken.

Name: Anonymous 2014-12-24 9:09

>>13
Hi! You might have missed the joke; the algorithm in >>1 is broken too:
Io> 11 isDubs

Exception: checkem
---------
Exception raise Command Line 1
Number isDubs Command Line 1

Io> 311 isDubs
==> false
Io> 122 isDubs
==> false

Name: Anonymous 2014-12-24 10:03

Symta: int.is_dubs = $digits^is{X,&X}

Name: Anonymous 2014-12-28 14:30

This one is a pretty good one that covers all bases under 36

#include <stdio.h>
#include <stdlib.h>
#define MAX_BASE 36
#include <math.h>
const char *alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWYZ";
const char *names[] = {
NULL, NULL, "dubs", "trips",
"quads", "quints", "sexts",
"septs", "octs", "nons",
};

/* Actual dubs checking: four lines of code. */
int check(int num, int base) {
int count = 0, digit = num % base;
while (num % base == digit) {
count++; num /= base;
}
return count;
}
void print_(int num, int b) {
int n = 0;
do {
n++;
}while(num/=b);
int i = n;
for(; i > 2; i--) {
putchar(alphabet[num/(int)pow(b,i) % b]);
}
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <postnum>\n", argv[0]);
return 1;
}

int postnum = atoi(argv[1]), base, result;

if (postnum <= 0) {
fprintf(stderr, "Invalid post number: %s\n", argv[1]);
return 1;
}

for (base = 2; base < postnum && base < MAX_BASE; base++) {
result = check(postnum, base);
if (result < 2) continue;

if (result >= 10) {
printf("* %ds in base %d: ", result, base);
} else {
printf("* %s in base %d: ", names[result], base);
}

while (result--) {
putchar(alphabet[postnum % base]);
}
print_(postnum, base);
putchar('\n');
}

return(0);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List