sql filtering 2 or more - mysql

voorletters, naam, geslacht, boete
B Niewenburg V 25.00
B Niewenburg V 140.00
D Moerman V 35.00
D Moerman V 50.00
DD Cools V 75.00
DD Cools V 85.00
E Bakker, de M 30.00
E Bakker, de M 35.00
E Bakker, de M 90.00
E Bakker, de M 95.00
IP Baalen, van V 140.00
R Permentier M 100.00
And I have this as sql statement
SELECT VOORLETTERS, NAAM, GESLACHT, BEDRAG
FROM SPELER S
RIGHT JOIN BOETE B ON B.SPELERSNR = S.SPELERSNR
LEFT joiN BESTUURSLID BL ON BL.SPELERSNR = S.SPELERSNR
GROUP BY VOORLETTERS, NAAM, GESLACHT, BEDRAG
how can i make it that I only see people with 2 or more 'boete'?
so that I get this as an answer
voorletters, naam, geslacht, boete
B Niewenburg V 25.00
B Niewenburg V 140.00
D Moerman V 35.00
D Moerman V 50.00
DD Cools V 75.00
DD Cools V 85.00
E Bakker, de M 30.00
E Bakker, de M 35.00
E Bakker, de M 90.00
E Bakker, de M 95.00

use a subselect for get the people with two or more rows in speler
SELECT VOORLETTERS, NAAM, GESLACHT, BEDRAG
FROM SPELER S
RIGHT JOIN BOETE B ON B.SPELERSNR = S.SPELERSNR
LEFT joiN BESTUURSLID BL ON BL.SPELERSNR = S.SPELERSNR
where s.naam in (select naam from (select naam, count(*) from speler group by name ) )
GROUP BY VOORLETTERS, NAAM, GESLACHT, BEDRAG

Related

MYSQL - Select rows matching event code and imediate next row and calculate time date difference

So this is the table
ID Date Event
1547 2013-05-09 16:26:02 PA
1547 2013-05-15 13:59:23 TA
1547 2013-05-21 10:16:56 EA
1547 2013-05-21 10:17:27 PM
1547 2014-01-16 11:42:12 IH
1547 2014-01-16 11:42:13 RP
1547 2014-01-21 10:01:18 MP <-
1547 2014-12-05 14:32:21 RE <-
1547 2014-12-05 14:34:24 RE
1666 2013-05-29 11:26:38 PA
1666 2013-06-04 13:38:42 TA
1666 2013-06-05 14:16:13 EA
1666 2013-08-21 10:07:08 PR
1666 2013-08-21 10:38:51 TR
1666 2013-08-21 10:38:52 MP <-
1666 2013-10-07 16:26:46 PM <-
1666 2013-10-09 14:38:51 TM
1666 2013-10-09 14:38:52 EP
1666 2013-10-25 10:29:01 IH
1666 2013-12-13 08:52:41 IH
1666 2013-12-13 08:52:43 RP
1666 2014-01-21 09:55:10 MP <-
1666 2014-05-05 15:52:34 AB <-
1666 2014-05-07 14:55:58 RD
1692 2013-06-10 14:17:17 PA
1692 2013-06-10 14:17:53 TA
1692 2013-06-10 15:01:08 EA
1692 2013-08-21 10:04:39 PR
1692 2013-08-21 10:37:38 TR
1692 2013-08-21 10:37:39 ER
1692 2013-09-26 08:33:48 PM
1692 2013-09-26 16:32:46 TM
1692 2013-09-26 16:32:47 EP
1692 2013-10-11 09:21:26 IH
1692 2013-12-19 15:29:20 IV
1692 2013-12-19 15:29:21 RP
1692 2013-12-19 15:33:19 MP <-
1692 2014-01-21 11:05:46 FX <-
1692 2014-01-22 10:16:27 RE
I want to select the first 'MP'event for each ID, the IMMEDIATE next one and calculate the difference in days.
The result should be:
ID Date DaystoNextEVENT
1547 2014-01-21 10:01:18 318
1666 2013-08-21 10:38:52 47
1666 2014-01-21 09:55:10 104
1692 2013-12-19 15:33:19 33
I have tried to use limit but always had problems limiting the next row of the same ID with the source of the date in the match.
We can use a curser in a sub-query, using order by day desc we reverse the sort order which gives us the date of the next event. If it is the same ID we then return it in the query.
SET #quot='';
SET #id=0;
select
id,
day,
lag_day,
event,
case when id=lag_id then
datediff(lag_day,day) end
as days_to_next
from
(select
#id lag_id,
#id:=id id,
#quot lag_day,
#quot:=day day,
event
from
events
order by
id ,
day desc) e
where event ='MP'
order by
id,
day;
id | day | lag_day | event | days_to_next
---: | :------------------ | :------------------ | :---- | -----------:
1547 | 2014-01-21 10:01:18 | 2014-12-05 14:32:21 | MP | 318
1666 | 2013-08-21 10:38:52 | 2013-10-07 16:26:46 | MP | 47
1666 | 2014-01-21 09:55:10 | 2014-05-05 15:52:34 | MP | 104
1692 | 2013-12-19 15:33:19 | 2014-01-21 11:05:46 | MP | 33
db<>fiddle here
For version 8+:
SELECT id,
`date`,
DATEDIFF(LEAD(`date`) OVER (PARTITION BY id ORDER BY `date`), -- next date
`date` -- the date of MP
) DaystoNextEVENT
FROM table t1
WHERE event = 'MP'
AND NOT EXISTS ( SELECT NULL -- check that there is no MP earlier
FROM table t2
WHERE t1.id = t2.id
AND t1.`date` > t2.`date`
AND t2.event = 'MP' );
For version 5.x:
SELECT t1.id,
t1.`date`,
DATEDIFF(t2.`date`, t1.`date`) DaystoNextEVENT
FROM table t1 -- row with MP
JOIN table t2 ON t1.id = t2.id -- next row
AND t1.`date` < t2.`date`
WHERE t1.event = 'MP'
AND NOT EXISTS ( SELECT NULL -- check that there is no MP earlier
FROM table t3
WHERE t1.id = t3.id
AND t1.`date` > t3.`date`
AND t3.event = 'MP' )
AND NOT EXISTS ( SELECT NULL -- check that there is no a row
FROM table t4 -- between rows from tables t1 and t2
WHERE t1.id = t4.id
AND t1.`date` < t4.`date`
AND t4.`date` < t2.`date` );

mysql sum() and double result Using Multiple Joins

I have table tb_orders
id_order
lot
rekanan
no_order
pec
5555
1
GOZNAK
390
y
6666
1
KOMSCO
391
y
I have another table tb_pengambilans_detail
id
id_order
tanggal
jumlah
137
5555
2021-01-05 09:36:16
100000
136
6666
2021-01-05 09:35:57
100000
94
6666
2020-12-15 15:00:47
100000
138
5555
2021-01-05 09:37:51
100000
table tb_lini_pengambilans_detail
id
id_order
tanggal
deret5
38
6666
2020-12-08 09:26:36
30000
39
5555
2020-12-08 09:31:49
10000
40
6666
2020-12-14 07:55:36
80000
41
6666
2020-12-14 07:57:34
20000
table tb_produksi_cutpacks_detail
id
tanggal
id_order
hcts
unfit
30
2021-01-04 13:02:10
5555
5000
0
32
2021-01-04 14:10:05
5555
0
10000
34
2021-01-04 15:11:57
5555
0
2000
35
2021-01-04 15:14:10
6666
9000
0
table tb_lini_produksi_cutpacks_detail
id
tanggal
id_order
xbaik
xderet5
16
2021-01-04 14:52:38
5555
4000
1000
18
2021-01-04 14:53:21
6666
8000
0
19
2021-01-04 14:53:36
6666
0
2000
21
2021-01-04 14:57:41
5555
0
15000
I have done separately, all the results are correct and not double
SELECT a.rekanan,
SUM(COALESCE(b.jumlah,0)) AS `pengambilan`
FROM tb_orders a
LEFT JOIN tb_pengambilans_detail b USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan
Result
rekanan
pengambilan
GOZNAX
200000
KOMSCO
200000
SELECT a.rekanan,
SUM(COALESCE(c.unfit + c.hcts,0)) AS prod_hcts
FROM tb_orders a
LEFT JOIN tb_produksi_cutpacks_detail c USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan
Result
rekanan
prod_hcts
GOZNAX
17000
KOMSCO
9000
SELECT a.rekanan,
SUM(COALESCE(d.deret5 ,0)) AS `pengambilanlini`
FROM tb_orders a
LEFT JOIN tb_lini_pengambilans_detail d USING(id_order)
LEFT JOIN tb_lini_produksi_cutpacks_detail e USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan
Result
rekanan
pengambilanlini
GOZNAX
20000
KOMSCO
260000
And Last
SELECT a.rekanan,
SUM(COALESCE(e.xbaik + e.xderet5 ,0)) AS prod_hctslini
FROM tb_orders a
LEFT JOIN tb_lini_produksi_cutpacks_detail e USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan
result
rekanan
prod_hctslini
GOZNAX
20000
KOMSCO
10000
after I was sure about everything then I joined all the tables, and the results were all double ...
SELECT a.rekanan,
SUM(COALESCE(b.jumlah,0)) AS `pengambilan`,
SUM(COALESCE(c.unfit + c.hcts,0)) AS prod_hcts,
SUM(COALESCE(d.deret5 ,0)) AS `pengambilanlini`,
SUM(COALESCE(e.xbaik + e.xderet5 ,0)) AS prod_hctslini
FROM tb_orders a
LEFT JOIN tb_pengambilans_detail b USING(id_order)
LEFT JOIN tb_produksi_cutpacks_detail c USING(id_order)
LEFT JOIN tb_lini_pengambilans_detail d USING(id_order)
LEFT JOIN tb_lini_produksi_cutpacks_detail e USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan
Result
rekanan
pengambilan
prod_hcts
pengambilanlini
prod_hctslini
GOZNAX
1200000
68000
120000
120000
KOMSCO
1200000
108000
520000
60000
What is the solution so that the SQL result is not double ..
please tell me so that the problem can be resolved ..
Thank you very much
---- Actual single SQL solution is ---------------
SELECT a.rekanan,
SUM(COALESCE(b.jumlah,0)) AS `pengambilan`,
SUM(COALESCE(c.unfit + c.hcts,0)) AS prod_hcts,
SUM(COALESCE(d.deret5 ,0)) AS `pengambilanlini`,
SUM(COALESCE(e.xbaik + e.xderet5 ,0)) AS prod_hctslini
FROM tb_orders a
LEFT JOIN (select id_order ,SUM(jumlah) jumlah from tb_pengambilans_detail group by id_order) b USING(id_order)
LEFT JOIN (select id_order ,SUM(unfit) unfit ,SUM(hcts) hcts from tb_produksi_cutpacks_detail group by id_order) c USING(id_order)
LEFT JOIN (select id_order ,SUM(deret5) deret5 from tb_lini_pengambilans_detail group by id_order) d USING(id_order)
LEFT JOIN (select id_order ,SUM(xbaik) xbaik , sum(xderet5) xderet5 from tb_lini_produksi_cutpacks_detail group by id_order) e USING(id_order)
WHERE a.pec='y'
GROUP BY a.rekanan

How to select the last row of a table in sql?

I have columns from different tables which were joined by their common keys. What I want to do is to select the very last data of each rows with the same ev_k. Kindly refer to the table below.
3489 7666 LOND c i N 10/21/2013 09:30:29
3490 7666 LOND c c N 10/21/2013 09:30:29
3491 7666 LOND l i N 10/21/2013 09:30:29
3492 7666 LOND l d N 10/21/2013 09:30:29
3493 7666 LOND l c N 10/21/2013 09:32:52
3494 7666 LOND i i N 10/21/2013
3495 7666 LOND i d N 10/21/2013 09:32:52
3496 7666 LOND i p N 10/21/2013 09:51:20
2159 6367 LOND c i N 10/21/2013 10:25:00
2160 6367 LOND c c N 10/21/2013 10:25:00
2162 6367 LOND l d N 10/21/2013 10:25:00
2161 6367 LOND l i N 10/21/2013 10:25:00
2163 6367 LOND l p N 10/21/2013 10:25:08
3371 7463 LOND c i N 10/21/2013 11:07:23
3374 7463 LOND l d N 10/21/2013 11:07:24
3373 7463 LOND l i N 10/21/2013 11:07:24
3372 7463 LOND c c N 10/21/2013 11:07:24
3377 7463 LOND i d N 10/21/2013 11:07:32
3376 7463 LOND i i N 10/21/2013 11:07:32
3375 7463 LOND l c N 10/21/2013 11:07:32
3378 7463 LOND i c N 10/21/2013 11:07:41
3380 7463 LOND c2 c N 10/21/2013 11:07:42
3381 7463 LOND a1 i N 10/21/2013 11:07:42
3382 7463 LOND a1 d N 10/21/2013 11:07:42
3379 7463 LOND c2 i N 10/21/2013 11:07:42
3383 7463 LOND a1 c N 10/21/2013 11:07:51
3384 7463 LOND r i N 10/21/2013 11:07:51
3385 7463 LOND r c N 10/21/2013 11:07:52
3387 7463 LOND - c Y 10/21/2013 11:07:53
3386 7463 LOND - i N 10/21/2013 11:07:53
In the table provided, what I want to retrieve are the following rows:
3496 7666 LOND i p N 10/21/2013 09:51:20
2163 6367 LOND l p N 10/21/2013 10:25:08
3386 7463 LOND - i N 10/21/2013 11:07:53
The script used to get the data on the table was written below:
SELECT T1.KEY, T1.ev_k, T1.BRANCH, T2.THEIR_REF, T1.TYPE, T1.STATUS, T1.ISLASTSTEP, T1.FINISHDATE, T1.FINISHTIME
FROM STEPHIST T1, BASEEVENT T2, EXEMPL30 T3
WHERE T1.EVENT_KEY = T2.KEY97
AND T2.EXEMPLAR = T3.KEY97
ORDER BY THEIR_REF, FINISHTIME;
Thank you.
You should learn to use proper join syntax and to use table aliases that are abbreviations for the tables they refer to.
Then, you just need to calculate and join in the maximum time:
SELECT s.KEY, s.ev_k, s.BRANCH, b.THEIR_REF, s.TYPE, s.STATUS,
s.ISLASTSTEP, s.FINISHDATE, s.FINISHTIME
FROM STEPHIST s JOIN
BASEEVENT b
ON s.EVENT_KEY = b.KEY97 JOIN
EXEMPL30 e
ON b.EXEMPLAR = e.KEY97 JOIN
(SELECT s.ev_k, MAX(FINISHTIME) as maxft
FROM STEPHIST s
GROUP BY s.ev_k
) ss
ON s.ev_k = ss.ev_k AND s.finishtime = ss.msxft
ORDER BY Tb.HEIR_REF, s.FINISHTIME;

how to get two tables data based on column

We have two tables Table1 and table2. Table1 have A,B,C columns and Table2 have B,E,F columns.
Table1 Table2
A B C B E F
raja 21 HYD 21 AP 60000000
raju 21 VJY
ravi 21 BEG
We need is
A B C E F
raja 21 HYD AP 60000000
raju 21 VJY AP 60000000
ravi 21 BEG AP 60000000
so We tried like this
tx.executeSql('SELECT r.A as name,r.B as age,r.C as city,s.E as state,s.F as distance from table1 r Left JOIN table2 s on r.B=s.B',[],joinsuccess,errorCB);
function joinsuccess(tx,result){
var JOINLength = result.rows.length;
for (var i=0; i<JOINLength; i++){
console.log(result.rows.item(i).name);
console.log(result.rows.item(i).age);
console.log(result.rows.item(i).city);
console.log(result.rows.item(i).state);
console.log(result.rows.item(i).distance);
}
}
but it's we got only
ravi 21 BEG AP 60000000

Code Golf - Banner Generation

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
When thanking someone, you don't want to just send them an e-mail saying "Thanks!", you want to have something FLASHY:
Input: THANKS!!
Output:
TTT H H AAA N N K K SSS !!! !!!
T H H A A NNN K K S !!! !!!
T HHH AAA NNN KK SSS !!! !!!
T H H A A N N K K S
T H H A A N N K K SSS !!! !!!
Write a program to generate a banner. You only have to generate upper-case A-Z along with spaces and exclamation points (what is a banner without an exclamation point?). All characters are made up of a 3x5 grid of the same character (so the S is a 3x5 grid made of S). All output should be on one row (so no newlines). Here are all the letters you need:
Input: ABCDEFGHIJKL
Output:
AAA BBB CCC DD EEE FFF GGG H H III JJJ K K L
A A B B C D D E F G H H I J K K L
AAA BBB C D D EE FF G G HHH I J KK L
A A B B C D D E F G G H H I J J K K L
A A BBB CCC DD EEE F GGG H H III JJJ K K LLL
Input: MNOPQRSTUVWX
Output:
M M N N OOO PPP QQQ RR SSS TTT U U V V W W X X
MMM NNN O O P P Q Q R R S T U U V V W W X
M M NNN O O PPP Q Q RR SSS T U U V V WWW X
M M N N O O P QQQ R R S T U U V V WWW X
M M N N OOO P QQQ R R SSS T UUU V WWW X X
Input: YZ!
Output:
Y Y ZZZ !!!
Y Y Z !!!
YYY Z !!!
Y Z
YYY ZZZ !!!
The winner is the shortest source code, as counted by the number of bytes it takes to store the file in utf-8 encoding. Source code should read input from stdin, output to stdout. You can assume input will only contain [A-Z! ]. If you insult the user on incorrect input, you get a 10 character discount =P.
I was going to require these exact 28 characters, but to make it more interesting, you can choose how you want them to look - whatever makes your code shorter! To prove that your letters do look like normal letters, show the output of the last three runs.
Shortest codes so far, in characters (utf8 encoding if non-ASCII present):
133 J
205 Python
209 Ruby
313 Haskell
345 C89
382 F#
J, 133 135 79 83 84 88 characters (utf-8 encoding)
;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:
Usage:
;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:'ABCDEFGHIJKLMNOPQRSTUVWXYZ !'
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│AAA│BBB│CCC│DD │EEE│FFF│GGG│H H│III│JJJ│K K│L │M M│N N│OOO│PPP│QQQ│RR │SSS│TTT│U U│V V│W W│X X│Y Y│ZZZ│ │!!!│
│A A│B B│C │D D│E │F │G │H H│ I │ J│K K│L │MMM│NNN│O O│P P│Q Q│R R│S │ T │U U│V V│W W│ X │Y Y│ Z│ │!!!│
│AAA│BBB│C │D D│EE │FF │G G│HHH│ I │ J│KK │L │M M│NNN│O O│PPP│Q Q│RR │SSS│ T │U U│V V│WWW│ X │YYY│ Z │ │!!!│
│A A│B B│C │D D│E │F │G G│H H│ I │J J│K K│L │M M│N N│O O│P │QQQ│R R│ S│ T │U U│V V│WWW│ X │ Y│Z │ │ │
│A A│BBB│CCC│DD │EEE│F │GGG│H H│III│JJJ│K K│LLL│M M│N N│OOO│P │QQQ│R R│SSS│ T │UUU│ V │WWW│X X│YYY│ZZZ│ │!!!│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:'this is incorrect input.'
|index error
Explanation (NB. is comment in J):
;/ NB. String together along the third dimension...
5 3$"1 NB. ... reshape each line to 5x3...
(' ',.s) NB. ... a space before each letter of the input string...
{~"1 NB. ... indexed using...
#: NB. ... the (15 bit) binary representation of ...
3 u: NB. ... the integer representation of...
(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧') ... the unicode versions of these code points...
{~ NB. ...indexed using...
0>. NB. ...the max of 0 and...
64-~ NB. ...64 less than...
a.i. NB. the ascii indexes of s
s=: NB. Assign the input string to the variable s.
Python, 250 224 chars
s=raw_input()
for i in range(5):
for c in s:
print''.join((' ',c)[int('2zj93fqzj6hsh2bc8i2b1ycncj5yc2v9i0m16dz91gcizj18blbw6wt0p3qqh8svchwc5onna2808of',36)>>((ord(c)-65 if c>'#'else 26)*15+i*3+j)&1]for j in[0,1,2]),
print
Notes:
relies on 2.x print statement considerably;
supports spaces.
Running (I changed appearance of a few letters, for aestetic reasons only ;):
$ echo ABCDEFGHIJKL | python code-golf.py
AAA BBB CCC DD EEE FFF GGG H H III JJJ K K L
A A B B C D D E F G H H I J K K L
AAA BBB C D D EEE FFF G HHH I J KK L
A A B B C D D E F G G H H I J J K K L
A A BBB CCC DD EEE F GGG H H III JJJ K K LLL
$ echo MNOPQRSTUVWX | python code-golf.py
M M N N OOO PPP QQQ RR SSS TTT U U V V W W X X
MMM NNN O O P P Q Q R R S T U U V V W W X X
M M NNN O O PPP Q Q RR SSS T U U V V WWW X
M M N N O O P QQQ R R S T U U V V WWW X X
M M N N OOO P QQQ R R SSS T UUU V W W X X
$ echo YZ\! | python code-golf.py
Y Y ZZZ !!!
Y Y Z !!!
YYY Z !!!
Y Z
YYY ZZZ !!!
There are trailing spaces.
Figlet (0 chars)
wget -q 3.ly/gzkv;figlet -f b
Sample output:
% wget -q 3.ly/gzkv;figlet -f b ABCDEFGHIJKLMNOPQRS
A BB CC DD EEE FFF GG H H III JJ K K L M M NNN O PP Q RR SS
A A B B C D D E F G H H I J K K L MMM N N O O P P Q Q R R S
AAA BB C D D EE FF G G HHH I J KK L MMM N N O O PP Q Q RR S
A A B B C D D E F G G H H I J J K K L M M N N O O P QQ R R S
A A BB CC DD EEE F GG H H III J K K LLL M M N N O P Q R R SS
% wget -q 3.ly/gzkv;figlet -f b TUVWXYZ \!
TTT U U V V W W X X Y Y ZZZ !!!
T U U V V W W X X Y Y Z !!!
T U U V V WWW X Y Z !!!
T U U V V WWW X X Y Z
T UUU V W W X X Y ZZZ !!!
Python, 233 231 225 224 205 chars
Candidate for the shortest python solution here :-)
It is a two-liner - last line was broken in 3 for urrrr readability
s=raw_input()
for i in range(5):print' '.join(''.join((' ',c)[ord(
'W_E__U__QQ_QN_UQ_EA_Q]_D_Q_QYQ__D[_PP_B__F__Q__EG_Y__EZWU]A_A_P_OPO_\\_QNQWT_YUS'
[max(0,3*ord(c)-192-k)])>>i&1]for k in(2,1,0))for c in s)
ps. Thanks for comments, corrected issues and now using 7-bit ASCII only!
Test banner:
TTT H H EEE QQQ U U III CCC K K BBB RR OOO W W N N FFF OOO X X JJJ U U M M PPP SSS OOO V V EEE RR TTT H H EEE L AAA ZZZ Y Y DD OOO GGG !!!
T H H E Q Q U U I C K K B B R R O O W W NNN F O O X J U U MMM P P S O O V V E R R T H H E L A A Z Y Y D D O O G !!!
T HHH EE Q Q U U I C KK BBB RR O O WWW NNN FF O O X J U U M M PPP SSS O O V V EE RR T HHH EE L AAA Z YYY D D O O G G !!!
T H H E QQQ U U I C K K B B R R O O WWW N N F O O X J J U U M M P S O O V V E R R T H H E L A A Z Y D D O O G G
T H H EEE QQQ UUU III CCC K K BBB R R OOO WWW N N F OOO X X JJJ UUU M M P SSS OOO V EEE R R T H H EEE LLL A A ZZZ YYY DD OOO GGG !!!
Haskell, 313 316 320
import Data.Bits
import Data.Char
c&True=c
c&_=' '
a ' '='#'
a '!'='['
a c=c
q s=unlines[s>>= \c->take 3(drop(84*n+3*(ord(a c)-64))$map((c&).testBit(0xffdebaf79f6fbfde7bfe8062f6a979b69b55a4d368ebaf6aeefbe9717add3f8f2ab6a36dbf9b1524d368fedb6fefff69bfdffbff8::Integer))[0..])++" "|n<-[0..4]]
main=getLine>>=putStr.q
For the curious, the large number is the hex version of encoding in the following code. The number is simply used as a bitmap. I've had no success with further shortening the code by encoding the number to other bases even with non-standard character representations.
formats :: [String] -- order: [ A-Z!] <- that's a space in front of A
formats = [
" AAABBBCCCDD EEEFFFGGGH HIIIJJJK KL M MN NOOOPPPQQQRR SSSTTTU UV VW WX XY YZZZ!!!"
, " A AB BC D DE F G H H I JK KL MMMNNNO OP PQ QR RS T U UV VW W X Y Y Z!!!"
, " AAABBBC D DEE FF G GHHH I JKK L M MNNNO OPPPQ QRR SSS T U UV VWWW X YYY Z !!!"
, " A AB BC D DE F G GH H I J JK KL M MN NO OP QQQR R S T U UV VWWW X YZ "
, " A ABBBCCCDD EEEF GGGH HIIIJJJK KLLLM MN NOOOP QQQR RSSS T UUU V WWWX XYYYZZZ!!!"
]
charToBool :: Char -> Bool
charToBool ' ' = False
charToBool _ = True
boolToInteger :: Bool -> Integer
boolToInteger True = 1
boolToInteger _ = 0
encoding :: Integer
encoding = foldr f 0 $ zip [0..] $ map charToBool $ concat formats
where
f (pow, bool) z = z + ((2^pow) * boolToInteger bool)
Python 2.6, 251 - 243 - 227 characters
I tried a slightly different approach (bitpacking the parts the letters are made of) ...
handles uppercase letters, spaces, exclamation mark.
2 unnecessary linebreaks added here for readability (the for loop could be one line)
be sure to save this as UTF-8 with BOM!
As always, all comments and suggestions welcome! Contender for shortest Python solution (again a few characters behind at the moment)...
w=raw_input()
for l in range(5):print''.join("1111 11 11 1 1 "
[int(("%05d"%ord(u"<ϳϲࢬ禉ऐऒ࠾⬃ᅘᖆⰯ囌❿✛іϾь穏ࠂᅜ⭦⭪⫸㡩⬪㰼"
[max(0,ord(c)-64)]))[l])*3:][:3].replace("1",c)+" "for c in w)
C89, 345 characters
Newlines added for your sanity (they are not included in the character count and can/should be deleted):
char o[5][99];
d[]={0x2df7fbef,0x3927bb6b,0x396792cf,0x3da7dbed,0x3a4bfb27,0x2d76f249,0x2dbedbfd,0x3db793ef,0x3fb7daeb,0x3ce7a497,0x3db6ab6d,0x3ff6d495,0x3cf6f2a7,0x38ff8000};
c,i,j;
main(){memset(o,32,495);
while((c=getchar())>0){
for(j=0;j<15;j++)
o[j/3][i+j%3]=d[c-33?(c-65)/2:13]>>((c&1)*15+j)&1?c:32;i+=4;}
for(j=0;j<5;j++)printf("%.*s\n",i,o[j]);}
Ruby : 207 215 252 345 characters
i=gets.chomp;5.times{|t|p i.gsub(/./){|c|j=3*(c>?#?c.ord-64:0);(3*t..3*t+2).map{|d|"mini5mbmzjf2bqjmof3prl72i5pn138iuhylmkpi65i278kq3qjfaihyjb66787odp8ktiy5hwt78tmnb"[j..j+2].to_i(36)[d]==1?c:" "}.join+" "}}
F#, 382 chars
I compressed two letters from each row into an ascii-printable byte, and handled space and exclamation point specially.
let s,(!)=stdin.ReadLine(),printf"%s"
for n in 0..4 do
for c in s do if c=' '||n=3&&c='!'then !" "elif c='!'then !"!!! "else for x in 0..3 do printf"%c"(if(Array.collect(fun b->let B n=int b&&&n=0 in[|(B 64)||not(B 8);B 32;B 16;true;B 4;B 2;B 1;true|])"wvwuwTUwvwUUWUEDEiTwUUBURQwEfWidWWVrUrrUEDUmTUTuZUr\\WvtuwWUturruw"B).[n*104+(int c-int 'A')*4+x]then ' 'else c)
!"\n"
Sample I/O below:
HELLO WORLD!!!
H H EEE L L OOO W W OOO RR L DD !!! !!! !!!
H H E L L O O W W O O R R L D D !!! !!! !!!
HHH EE L L O O WWW O O RR L D D !!! !!! !!!
H H E L L O O WWW O O R R L D D
H H EEE LLL LLL OOO WWW OOO R R LLL DD !!! !!! !!!
ABCDEFGHIJKL
AAA BBB CCC DD EEE FFF GGG H H III JJJ K K L
A A B B C D D E F G H H I J K K L
AAA BBB C D D EE FF G G HHH I J KK L
A A B B C D D E F G G H H I J J K K L
A A BBB CCC DD EEE F GGG H H III JJJ K K LLL
MNOPQRSTUVWXYZ
M M N N OOO PPP QQQ RR SSS TTT U U V V W W X X Y Y ZZZ
MMM NNN O O P P Q Q R R S T U U V V W W X Y Y Z
M M NNN O O PPP Q Q RR SSS T U U V V WWW X YYY Z
M M N N O O P QQQ R R S T U U V V WWW X Y Z
M M N N OOO P QQQ R R SSS T UUU V WWW X X YYY ZZZ
Python, 340 characters
d=dict((i,[23535,31727,29263,15211,29391,4815,31567,23533,29847,31527,23277,29257,23421,23549,31599,5103,32623,23275,31183,9367,31597,11117,32749,21653,31213,29351][i-65])for i in range(65,91))
d[33]=29183
d[32]=0
s=raw_input()
for l in range(5):
p=""
for c in s:
for n in range(3):
if d[ord(c)]&2**(3*l+n):p+=c
else:p+=" "
p+=" "
print p
sample output
>>>
ABCDEFGHIJKLMNOPQRSTUVWXYZ !
aaa bbb ccc dd eee fff ggg h h iii jjj k k l m m n n ooo ppp qqq rr sss ttt u u v v w w x x y y zzz !!!
a a b b c d d e f g h h i j k k l mmm nnn o o p p q q r r s t u u v v w w x y y z !!!
aaa bbb c d d ee ff g g hhh i j kk l m m nnn o o ppp q q rr sss t u u v v www x yyy z !!!
a a b b c d d e f g g h h i j j k k l m m n n o o p qqq r r s t u u v v www x y z
a a bbb ccc dd eee f ggg h h iii jjj k k lll m m n n ooo p qqq r r sss t uuu v www x x yyy zzz !!!
>>>
not too great, but it was fun writing it
edit whoops, I made the input be lowercase. fixed now, saved me one character too :)
Delphi, 397 chars
Ok, with all the begin/end statements Delphi probably will never be shorter than any other languages, but I do see a challenge in getting it as short as possible.
vvar s:String;i,j,k:Word;const F:Array[65..92]of Word=($5BEA,$3AEB,$624E,$3B6B,$72CF,$12CF,$6B4E,$5BED,$7497,$2B26,$5AED,$7249,$5BFD,$5B6F,$2B6A,$12EB,$4D6A,$5AEB,$388E,$2497,$7B6D,$2B6D,$5FED,$5AAD,$24AD,$72A7,$2092,$0000);begin S:=ParamStr(1);for j:=0 to 4 do begin for k:=1 to Length(S)do begin for i := 0 to 2 do Write((' '+S[k])[1+(F[ord(S[k])]shr(i+j*3))and 1]);Write(' ');end;WriteLn;end;end.
The font is built up like this:
010 110 011 110 111 111 011 101 111 011 101 100 101 111 010 110 010 110 011 111 101 101 101 101 101 111 010 000
101 101 100 101 100 100 100 101 010 001 101 100 111 101 101 101 101 101 100 010 101 101 101 101 101 001 010 000
111 110 100 101 110 110 101 111 010 001 110 100 111 101 101 110 101 110 010 010 101 101 111 010 010 010 010 000
101 101 100 101 100 100 101 101 010 101 101 100 101 101 101 100 011 101 001 010 101 101 111 101 010 100 000 000
101 110 011 110 111 100 011 101 111 010 101 111 101 101 010 100 001 101 110 010 111 010 101 101 010 111 010 000
The characters in this 5x3 font take up 15 bits and are stored in word (UINT16) in this order:
00 01 02
03 04 05
06 07 08
09 10 11
12 13 14
Formatted code:
var
s:String;
i, j, k: Word;
const
F: Array [65 .. 92] of Word = (
$5BEA,$3AEB,$624E,$3B6B, $72CF,$12CF,$6B4E,$5BED,
$7497,$2B26,$5AED,$7249, $5BFD,$5B6F,$2B6A,$12EB,
$4D6A,$5AEB,$388E,$2497, $7B6D,$2B6D,$5FED,$5AAD,
$24AD,$72A7,$2092,$0000);
begin
S := ParamStr(1);
for j := 0 to 4 do
begin
for k := 1 to Length(S) do
begin
for i := 0 to 2 do
Write((' '+S[k])[1+(F[ord(S[k])]shr(i+j*3))and 1]);
Write(' ');
end;
WriteLn;
end;
end.
Python: 259 chars
Not the shortest, but considering it was my first Python script, I'm more than satisfied.
k=raw_input()
for i in range(5):print' '.join(''.join((' ',x)[int(z)]for z in bin(int(''.join('%02d'%(ord(q)-43)for q in'xwxvxabxwxbbdqbXWX#axbbUb_^qxXwd#kddcsbssqbXWvDabav7bs9+dwuvxdbuvssvxq')[i*28+'ABCDEFGHIJKLMNOPQRSTUVWXYZ! '.find(x)],8))[2:])for x in k)
Perl, 69 74 77 78 79 chars
$a=<>;s:(?{$z=substr$a,$-[0]/4,1})z|#:$z:g,print for`figlet -f3x5 $a`
Sample output:
% echo ABCDEFGHIJKLMNOPQRS | perl banner.pl
A BB CC DD EEE FFF GG H H III JJ K K L M M NNN O PP Q RR SS
A A B B C D D E F G H H I J K K L MMM N N O O P P Q Q R R S
AAA BB C D D EE FF G G HHH I J KK L MMM N N O O PP Q Q RR S
A A B B C D D E F G G H H I J J K K L M M N N O O P QQ R R S
A A BB CC DD EEE F GG H H III J K K LLL M M N N O P Q R R SS
% echo TUVWXYZ \! | perl banner.pl
TTT U U V V W W X X Y Y ZZZ !
T U U V V W W X X Y Y Z !
T U U V V WWW X Y Z !
T U U V V WWW X X Y Z
T UUU V W W X X Y ZZZ !
I assume you have figlet and this figlet font installed on your system. :)
C#, 239 231 229 chars (292 bytes)
I'm a bit late but this just looked like fun.
using C=System.Console;class P{static void Main(){var t=C.ReadLine();for(int
b=15,s;b>0;b-=3){foreach(var c in t)for(s=0;s++<4;)C.Write(s>3||c<33?' ':((
"翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧"[c<34?0:c-64])&1<<b-s)>0
?c:' ');C.WriteLine();}}}