I've read about it on linux.org.ru
On http://www.pycontest.net/ occurs a competition.
The goal is to code the shortest possible python module that converts decimal numbers to the seven-segment display format.
I wonder, who will win. And here is my own code, written in J, which I wrote outside the competition.
seg=:7 3$' _ |_| | _||_ | |'
loc=:10 3$(7&#.^:_1)6115893582106107964921726x
seven_seq=:(,"2)@:((1 0 2)&|:)@:{&seg@:{&loc@:(10&#.^:_1)
I guess, it can be shorter in 10 symbols if do not care much about the readability.
For example, if to form a line at once instead of collecting results for individual numbers then the last verb can be rewritten as follows:
seven_seq=:,"2@:{&seg@:(|:@:]{&loc)@:(10&#.^:_1)
No comments:
Post a Comment