C ( 561 492 Bytes)
Autor ist frmar. Er hat mir letzte Woche seine Antwort geschickt (er hat seinen Account noch nicht erstellt).
492 Bytes, aber etwas verschleierter:
#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");}
Vorherige Version mit 561 Bytes:
#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");}
Originalversion von frmar (623 Bytes):
#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");}
Zusammenstellung:
$ gcc -std=c99 -Wall print_as_led.c
Beispiele mit Standardanzahl, 0123456789
aber unterschiedlichen Größen:
$ ./a.out
_ _ _ _ _ _ _ _
| | | _| _||_||_ |_ ||_||_|
|_| ||_ _| | _||_| ||_| |
$ ./a.out 2
__ __ __ __ __ __ __ __
| | | | || || | || || |
| | | __| __||__||__ |__ ||__||__|
| | || | | || | || | |
|__| ||__ __| | __||__| ||__| |
$ ./a.out 3
___ ___ ___ ___ ___ ___ ___ ___
| | | | || || | || || |
| | | | || || | || || |
| | | ___| ___||___||___ |___ ||___||___|
| | || | | || | || | |
| | || | | || | || | |
|___| ||___ ___| | ___||___| ||___| |
Andere Beispiele:
$ ./a.out 1 42
_
|_| _|
||_
$ ./a.out 2 42
__
| | |
|__| __|
||
||__
$ ./a.out 3 42
___
| | |
| | |
|___| ___|
||
||
||___
Größere Größen:
$ ./a.out 4 42
____
| | |
| | |
| | |
|____| ____|
||
||
||
||____
$ ./a.out 5 42
_____
| | |
| | |
| | |
| | |
|_____| _____|
||
||
||
||
||_____