commit baab18ac420fa9a456772be7a09bbfdc08888edd Author: setop Date: Tue Jan 3 17:21:03 2023 +0100 all days in one day, using sqlite mainly and a bit of awk diff --git a/d1.awk b/d1.awk new file mode 100644 index 0000000..ff02721 --- /dev/null +++ b/d1.awk @@ -0,0 +1,22 @@ +function toT9(s){ + F = "abcdefghijklmnopqrstuvwxyz" + T = "22233344455566677778889999" + split(tolower(s),S,""); + r = "" + for (i=1;i<=length(S);i++) { + j = index(F,S[i]) + r = r substr(T,j,1) + } + return r +} +{ + split($1,N," ") + lastname = N[length(N)] + t9 = toT9(lastname) + phone = $2 + gsub("[-]","",phone) +} +t9 == phone + +# sqlite3 noahs.sqlite 'select name, phone from customers' | awk -F\| -f d1.awk + diff --git a/d2.sql b/d2.sql new file mode 100644 index 0000000..40ceaba --- /dev/null +++ b/d2.sql @@ -0,0 +1,7 @@ +select *, substr(c.name,1,1) f, SUBSTR(c.name, INSTR(c.name, ' ')+1,1) l from orders as o +left join orders_items as oi on (oi.orderid = o.orderid) +left join customers as c on (o.customerid = c.customerid) +where oi.sku in (select sku from products where desc like '%bagel%') +and f == 'J' +and l == 'D'; +-- call them all ! diff --git a/d3.sql b/d3.sql new file mode 100644 index 0000000..a39e64a --- /dev/null +++ b/d3.sql @@ -0,0 +1,7 @@ +select * from customers WHERE +((birthdate >= '1946-03-21' and birthdate <= '1946-04-19') +or (birthdate >= '1958-03-21' and birthdate <= '1958-04-19') +or (birthdate >= '1970-03-21' and birthdate <= '1970-04-19') +or (birthdate >= '1982-03-21' and birthdate <= '1982-04-19') +or (birthdate >= '1994-03-21' and birthdate <= '1994-04-19')) +and citystatezip = 'South Ozone Park, NY 11420'; \ No newline at end of file diff --git a/d4.sql b/d4.sql new file mode 100644 index 0000000..6929b14 --- /dev/null +++ b/d4.sql @@ -0,0 +1,14 @@ +select count(orderid) c, name, phone from ( + select *, + SUBSTR(o.ordered, INSTR(o.ordered, ' ')+1) d, + SUBSTR(o.shipped, INSTR(o.shipped, ' ')+1) s + from orders as o + left join customers as c on (o.customerid = c.customerid) + where d >= '04:00:00' + and d <= '05:00:00' + and s >= '04:00:00' + and s <= '05:00:00' +) +group by name, phone +order by c desc +-- pick the first one diff --git a/d5.sql b/d5.sql new file mode 100644 index 0000000..32cac59 --- /dev/null +++ b/d5.sql @@ -0,0 +1,7 @@ +select *, substr(c.name,1,1) f, SUBSTR(c.name, INSTR(c.name, ' ')+1,1) l from orders as o +left join orders_items as oi on (oi.orderid = o.orderid) +left join customers as c on (o.customerid = c.customerid) +where oi.sku in (select sku from products where desc like '%cat food%') +and citystatezip like 'Queens Village%' +order by phone; +-- there is only one woman! diff --git a/d6.sql b/d6.sql new file mode 100644 index 0000000..b716927 --- /dev/null +++ b/d6.sql @@ -0,0 +1,10 @@ +-- had to fix column type for order_items/orderid from txt to int, else, was damned too slow +with sales as (select * from orders_items as oi +left join products as p on (oi.sku = p.sku) +where oi.unit_price < p.wholesale_cost) +select c.*, count(o.customerid) c from sales as s +left join orders as o on (o.orderid = s.orderid) +left join customers as c on (c.customerid = o.customerid) +group by o.customerid +order by c desc +-- pick first one diff --git a/d7.sql b/d7.sql new file mode 100644 index 0000000..a1f9805 --- /dev/null +++ b/d7.sql @@ -0,0 +1,24 @@ +with clue as (select + substr(ordered,1,INSTR(ordered,' ')-1) date, + substr(desc,1,INSTR(desc,'(')-2) title, + substr(desc,INSTR(desc,'(')+1, length(desc)-INSTR(desc,'(')-1) color +from orders_items as oi +left join orders as o on (o.orderid = oi.orderid) +left join products as p on (p.sku = oi.sku) +where o.customerid = 8342 +and title != '') +select *, + substr(ordered,1,INSTR(ordered,' ')-1) zdate, + substr(desc,1,INSTR(desc,'(')-2) ztitle, + substr(desc,INSTR(desc,'(')+1, length(desc)-INSTR(desc,'(')-1) zcolor +from orders_items as oi +left join orders as o on (o.orderid = oi.orderid) +left join customers as c on (c.customerid = o.customerid) +left join products as p on (p.sku = oi.sku) +left join clue as cl on (cl.title = ztitle + and cl.color != zcolor + and cl.date = zdate +) +where o.customerid != 8342 +and title is not null +; diff --git a/d8.sql b/d8.sql new file mode 100644 index 0000000..04517cc --- /dev/null +++ b/d8.sql @@ -0,0 +1,9 @@ +select count(*) c , phone +from orders_items as oi +left join orders as o on (o.orderid = oi.orderid) +left join customers as c on (c.customerid = o.customerid) +left join products as p on (p.sku = oi.sku) +where p.desc like 'Noah%' +group by o.customerid, c.phone +order by c desc limit 12 +-- pick first one diff --git a/noahs.sql.zst b/noahs.sql.zst new file mode 100644 index 0000000..be65997 Binary files /dev/null and b/noahs.sql.zst differ diff --git a/stats.txt b/stats.txt new file mode 100644 index 0000000..2a21ea1 --- /dev/null +++ b/stats.txt @@ -0,0 +1,10 @@ +Puzzle Solve Time # Attempts +0 5 minutes 2 +1 32 minutes 1 +2 25 minutes 16 +3 13 minutes 1 +4 13 minutes 1 +5 5 minutes 1 +6 83 minutes 1 +7 2 hours 20 +8 8 minutes 1