Skip to main content
deleted 2 characters in body
Source Link
tmartin
  • 4k
  • 15
  • 16

q/k, 490 471469

M:mod;T:trim;R:read0;S:set;s:" "
f:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"J"$R 0;*9*"i"$R 0]]}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T's\:x}
k)g:{$[&/0=C:K'c:1_J:s\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit<#f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#s\:1_x)}
k)n:0;while[~n>#o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define macros)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program and strips out unnecessary characters

q)f
"99999999"
"999 99"
"9999999999 9999999999 9999999999 99 99 9 9 999 999"
"99999999999 9999999999"
""
""
""
""
""
"999"
"99999999"
"999 999 9"
" 99999 999"
" 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f list of strings, with n as the iterator. The goto function will update n as necessary.

q/k, 490 471

M:mod;T:trim;R:read0;S:set;s:" "
f:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"J"$R 0;*9*"i"$R 0]]}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T's\:x}
k)g:{$[&/0=C:K'c:1_J:s\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#s\:1_x)}
k)n:0;while[~n>#o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define macros)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program and strips out unnecessary characters

q)f
"99999999"
"999 99"
"9999999999 9999999999 9999999999 99 99 9 9 999 999"
"99999999999 9999999999"
""
""
""
""
""
"999"
"99999999"
"999 999 9"
" 99999 999"
" 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f list of strings, with n as the iterator. The goto function will update n as necessary.

q/k, 490 469

M:mod;T:trim;R:read0;S:set;s:" "
f:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"J"$R 0;*9*"i"$R 0]]}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T's\:x}
k)g:{$[&/0=C:K'c:1_J:s\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<#f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#s\:1_x)}
k)n:0;while[~n>#o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define macros)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program and strips out unnecessary characters

q)f
"99999999"
"999 99"
"9999999999 9999999999 9999999999 99 99 9 9 999 999"
"99999999999 9999999999"
""
""
""
""
""
"999"
"99999999"
"999 999 9"
" 99999 999"
" 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f list of strings, with n as the iterator. The goto function will update n as necessary.

deleted 193 characters in body
Source Link
tmartin
  • 4k
  • 15
  • 16

q/k, 490490 471

M:mod;T:trim;R:read0;S:setset;s:" "
f:((!)(#)a)!a:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"I"$Rx;2];9*"J"$R 0;*9*"i"$R 0]];0]]}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T'" "\T's\:x;x}
k)g:{$[&/0=C:K'c:1_J:" "\s\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#(s:" ")\#s\:1_x)}
k)n:0;while[~n>*|!o0;while[~n>#o:(r')f;(o n)f n;n+:1]
\\

This could probably be golfed some more but I really don't have the inclination.

f reads the file passed into the program,strips and strips out unnecessary characters and creates a dictionary which maps the line number to the line

q)f
0 | "99999999"
1 | "999 99"
2 | "9999999999 9999999999 9999999999 99 99 9 9 999 999"
3 | "99999999999 9999999999"
4 | ""
5 | ""
6 | ""
7 | ""
8 | ""
9 | "999"
10| "99999999"
11| "999 999 9"
12| " 99999 999"
13| " 9 99999999999 9999999999"

And then finally, I just iterate through the f dictionarylist of strings, with n as the iterator. The goto function will update n as necessary.

q/k, 490

M:mod;T:trim;R:read0;S:set
f:((!)(#)a)!a:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"I"$R 0;*9*"i"$R 0]];}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T'" "\:x;}
k)g:{$[&/0=C:K'c:1_J:" "\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#(s:" ")\:1_x)}
k)n:0;while[~n>*|!o:(r')f;(o n)f n;n+:1]
\\

This could probably be golfed some more but I really don't have the inclination.

f reads the file passed into the program,strips out unnecessary characters and creates a dictionary which maps the line number to the line

q)f
0 | "99999999"
1 | "999 99"
2 | "9999999999 9999999999 9999999999 99 99 9 9 999 999"
3 | "99999999999 9999999999"
4 | ""
5 | ""
6 | ""
7 | ""
8 | ""
9 | "999"
10| "99999999"
11| "999 999 9"
12| " 99999 999"
13| " 9 99999999999 9999999999"

And then finally, I just iterate through the f dictionary, with n as the iterator. The goto function will update n as necessary.

q/k, 490 471

M:mod;T:trim;R:read0;S:set;s:" "
f:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"J"$R 0;*9*"i"$R 0]]}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T's\:x}
k)g:{$[&/0=C:K'c:1_J:s\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#s\:1_x)}
k)n:0;while[~n>#o:(r')f;(o n)f n;n+:1]
\\

f reads the file passed into the program and strips out unnecessary characters

q)f
"99999999"
"999 99"
"9999999999 9999999999 9999999999 99 99 9 9 999 999"
"99999999999 9999999999"
""
""
""
""
""
"999"
"99999999"
"999 999 9"
" 99999 999"
" 9 99999999999 9999999999"

And then finally, I just iterate through the f list of strings, with n as the iterator. The goto function will update n as necessary.

added 7 characters in body
Source Link
tmartin
  • 4k
  • 15
  • 16

q/k, 490

M:mod;T:trim;R:read0;S:set
f:((!)(#)a)!a:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"I"$R 0;*9*"i"$R 0]];}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T'" "\:x;}
k)g:{$[&/0=C:K'c:1_J:" "\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#(s:" ")\:1_x)}
k)n:0;while[~n>*|!o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

This could probably be golfed some more but I really don't have the inclination.

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define macros)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program,strips out unnecessary characters and creates a dictionary which maps the line number to the line

q)f
0 | "99999999"
1 | "999 99"
2 | "9999999999 9999999999 9999999999 99 99 9 9 999 999"
3 | "99999999999 9999999999"
4 | ""
5 | ""
6 | ""
7 | ""
8 | ""
9 | "999"
10| "99999999"
11| "999 999 9"
12| " 99999 999"
13| " 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f dictionary, with n as the iterator. The goto function will update n as necessary.

q/k, 490

M:mod;T:trim;R:read0;S:set
f:((!)(#)a)!a:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"I"$R 0;*9*"i"$R 0]];}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T'" "\:x;}
k)g:{$[&/0=C:K'c:1_J:" "\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#(s:" ")\:1_x)}
k)n:0;while[~n>*|!o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

This could probably be golfed some more but I really don't have the inclination.

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program,strips out unnecessary characters and creates a dictionary which maps the line number to the line

q)f
0 | "99999999"
1 | "999 99"
2 | "9999999999 9999999999 9999999999 99 99 9 9 999 999"
3 | "99999999999 9999999999"
4 | ""
5 | ""
6 | ""
7 | ""
8 | ""
9 | "999"
10| "99999999"
11| "999 999 9"
12| " 99999 999"
13| " 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f dictionary, with n as the iterator. The goto function will update n as necessary.

q/k, 490

M:mod;T:trim;R:read0;S:set
f:((!)(#)a)!a:(rtrim')(f:R -1!`$.z.x 0)inter\:"9 \n"
k)m:{@[x;&M[!#x;2];-:]}
b:{}
k)p:{1@$$[1=M[#x;2];(K x)%9;"c"$M[(K x)%9;128]];}
k)i:{S[(`$T x);$[1=M[#T x;2];9*"I"$R 0;*9*"i"$R 0]];}
k)K:{$[#!:a:`$x;.:a;"I"$x]}
k)v:{(S).(`$*:;+/m@K'1_)@\:T'" "\:x;}
k)g:{$[&/0=C:K'c:1_J:" "\:T x;n::-1+K@*J;|/~0=C;;(d<0)|(d:*C)<*|!f;exit 0]}
k)r:{`b`p`i`v`g@*&(&/x=s;q&1=c;(e~s)&1=C;(q:e~"9")&1<c:#s\:x;((e:*x)~s)&1<C:#(s:" ")\:1_x)}
k)n:0;while[~n>*|!o:(r')f;(o n)f n;n+:1]
\\

.

$ q 99.q countdown.txt -q
G11G10G9G8G7G6G5G4G3G2G1G

This could probably be golfed some more but I really don't have the inclination.

The script is a mixture of q and k, so first up I define a few q keywords that I want to use multiple times in k functions. (basically #define macros)

M:mod;T:trim;R:read0;S:set

f reads the file passed into the program,strips out unnecessary characters and creates a dictionary which maps the line number to the line

q)f
0 | "99999999"
1 | "999 99"
2 | "9999999999 9999999999 9999999999 99 99 9 9 999 999"
3 | "99999999999 9999999999"
4 | ""
5 | ""
6 | ""
7 | ""
8 | ""
9 | "999"
10| "99999999"
11| "999 999 9"
12| " 99999 999"
13| " 9 99999999999 9999999999"

m takes a list/vector and multiples the odd indices by -1

q)m 1 2 3 4 5
1 -2 3 -4 5

b is just an empty function, used for the no-op lines

p is the print function.

K is a function that examines a variable. If the variable exists, it returns it, otherwise it just returns the literal.

//999 not defined, so just return 999
q)K "999"
999
//Set 999 to 9
q)v "999 9"
//K now returns 9
q)K "999"
9

v is the assignment function.

g is the goto function.

r takes a string and decides which operation needs to be applied.

And then finally, I just iterate through the f dictionary, with n as the iterator. The goto function will update n as necessary.

added 1472 characters in body
Source Link
tmartin
  • 4k
  • 15
  • 16
Loading
Source Link
tmartin
  • 4k
  • 15
  • 16
Loading