C ( 561 492 octets)
L'auteur est frmar. Il m'a envoyé sa réponse la semaine dernière (il n'a pas encore créé son compte).
492 octets mais un peu plus obscurci:
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#define C(x) ((_[*n-'0'])>>s)&m&x
#define P putchar
unsigned _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,char*n,unsigned m,int s)
{for(;isdigit(*n);++n){P(C(1)?'|':' ');
for(int i=0;i<a;++i)P(C(4)?'_':' ');
P(C(2)?'|':' ');}
P('\n');}
void l(int a,char*b){p(a,b,7,0);int i=1;
for(;i<a;++i)p(a,b,3,3);p(a,b,7,3);i=1;
for(;i<a;++i)p(a,b,3,6);p(a,b,7,6);}
int main(int c,char**v){l(c>1?atoi(v[1]):1,c>2?v[2]:"0123456789");}
Version précédente utilisant 561 octets:
#include<stdio.h>
#include<ctype.h>
#define C(x) ((((*n-'0')[_])>>s)&m&x)
const unsigned _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,const char*n,unsigned m,int s)
{
for(;isdigit(*n);++n) {
putchar(C(1)?'|':' ');
const char c=C(4)?'_':' ';
for(int i=0;i<a;++i) putchar(c);
putchar(C(2)?'|':' ');
}
putchar('\n');
}
void l(int a,const char*b)
{
p(a,b,7,0);
for(int i=1;i<a;++i)p(a,b,3,3);p(a,b,7,3);
for(int i=1;i<a;++i)p(a,b,3,6);p(a,b,7,6);
}
#include<stdlib.h>
int main(int c,char**v){l(c>1?atoi(v[1]):1,c>2?v[2]:"0123456789");}
Version originale de frmar (623 octets):
#include<stdio.h>
#include<ctype.h>
const unsigned int _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,const char*n,unsigned int m,int s)
{
for(;isdigit(*n);++n) {
#define C(x) ((((*n-'0')[_])>>s)&m&x)
putchar(C(1)?'|':' ');
const char c=C(4)?'_':' ';
for(int i=0;i<a;++i) putchar(c);
putchar(C(2)?'|':' ');
}
putchar('\n');
}
void print_as_led(int a,const char*b)
{
p(a,b,7,0);
for(int i=1;i<a;++i)p(a,b,3,3);p(a,b,7,3);
for(int i=1;i<a;++i)p(a,b,3,6);p(a,b,7,6);
}
#include<stdlib.h>
int main(int argc,char**argv){print_as_led(argc>1?atoi(argv[1]):1,argc>2?argv[2]:"0123456789");}
Compilation:
$ gcc -std=c99 -Wall print_as_led.c
Exemples utilisant un 0123456789
numéro par défaut mais des tailles différentes:
$ ./a.out
_ _ _ _ _ _ _ _
| | | _| _||_||_ |_ ||_||_|
|_| ||_ _| | _||_| ||_| |
$ ./a.out 2
__ __ __ __ __ __ __ __
| | | | || || | || || |
| | | __| __||__||__ |__ ||__||__|
| | || | | || | || | |
|__| ||__ __| | __||__| ||__| |
$ ./a.out 3
___ ___ ___ ___ ___ ___ ___ ___
| | | | || || | || || |
| | | | || || | || || |
| | | ___| ___||___||___ |___ ||___||___|
| | || | | || | || | |
| | || | | || | || | |
|___| ||___ ___| | ___||___| ||___| |
Autres exemples:
$ ./a.out 1 42
_
|_| _|
||_
$ ./a.out 2 42
__
| | |
|__| __|
||
||__
$ ./a.out 3 42
___
| | |
| | |
|___| ___|
||
||
||___
Grandes tailles:
$ ./a.out 4 42
____
| | |
| | |
| | |
|____| ____|
||
||
||
||____
$ ./a.out 5 42
_____
| | |
| | |
| | |
| | |
|_____| _____|
||
||
||
||
||_____