[PYTHON] Golf on Slack

I made a golf course in Slack I hope you play

codegolf_view.png

Background / motivation

――Originally, @fmy held it on an in-house communication tool. ――Hundreds of engineers silently held a ranking update battle, and everyone was desperate to forget their duties in the offense and defense over 1 byte. ――It was easily replaced by Slack API, so I published it. -I also tried to advertise in Node Gakuen 25th period

way to participate

In Google form, just enter the email address (used in Slack) and you will receive invi from Slack in a few minutes.

how to play

--If you log in to slack, you will enter the general channel, but since general is the place where you want to publish the ranking, first click the bot ** x-code golf ** and connect DIRECT MESSAGE (DM). --General Be careful not to throw the code in the room! You can see it from everyone! ――Questions and chats in the general room are also welcome! --HELP will be displayed automatically when you connect DM ――You can see HELP as many times as you like by hitting help or bot. It reacts with various character strings, so give it a try. -If you are using node-slack-sdk, you can do it with RTM_EVENTS.IM_CREATED.

codegolf_help.png

--You can see a list of available languages and their versions by typing v or version.

codegolf_version.png

--You can see the question sentence of Q1 by typing q 1, and you can see the question sentence of Q2 by typing q 2.

codegolf_q.png

--When solving Question 1 with python, write the question number + language as 1 python, start a new line, and post the beginning and end of the answer in three single quotes. --Slack will quote you if you put it in three single quotes (there is no syntax highlighting) --I'm hooking 3 single quotes with a bot regular expression. Ignore line breaks (line breaks in the answer are counted in 1 byte) - https://github.com/slack-codegolf/platform/blob/master/index.js#L171 --By the way, you can press Ctrl + Enter to start a new line in the input field. --Tested on the server side and will notify you with success or failure or bytes

codegolf_answer.png

--If you reduce the number of bytes to the top 5 or less, the ranking will be updated in the general room (∗ ´꒳`) and you can do it. ――If you solve all the problems, you will be subject to the overall ranking of the language. ――You can check the ranking by problem or language at any time. Look at the bot HELP.

Feature

--The code to post is not published or retained --Only ranking and number of bytes are displayed on general channel ――It doesn't matter what kind of solution you use, such as a scientific solution. ――After showing the overwhelming result (∗ ´꒳`) Dowa will be addictive ――The management can't say "Announce the code of the top ranking person" without permission. ――To be exact, the result of strace remains in heroku's log at present, but since it is a free plan and free add-on, the retention period is only 7 days.

Prohibited matter

--The act of cating the answer --Controlled by authority --The act of sending an answer over the network --Network interruption

ifconfig $(ifconfig | fgrep encap:Ethernet | awk '{print $1}') down

--Forbid external commands in all languages except bash --Child ps monitoring using strace

strace -f -e execve $COMMAND < ${INPUT}/$file

――But the current situation is ... -System Configuration --Due to restrictions that you can't use docker commands in the app while saying "docker can be used!" Or sudo is not possible on heroku (ry) ――If the number of people increases, I will borrow a server and do it properly. I also want to make it Mastodon

Codegolf Tips Nodejs ex ascii

Output the following character string.

!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

With JavaScript

63 Byte

j=''
for(i=33;i<127;)j+=String.fromCharCode(i++)
console.log(j)

Node Core API

Buffer is convenient

51 Byte (can be reduced to 43 Byte)

console.log(Buffer.alloc(94,33).map((v,i)=>v+i)+"")

stdin

You can write as below

//If you specify the character code, string
s=require('fs').readFileSync('/dev/stdin','UTF8');

//Buffer if no character code is specified
b=require('fs').readFileSync('/dev/stdin');

//Argument can be fd, buffer can be map processed
require('fs').readFileSync(0).map(v=>{});

//You can receive it at event(b is Buffer)
process.stdin.on('data',b=>{});

Python

I referred to the following article. There are many other effective methods, so read the official DOC as well.

-Python golf technique collection (from Stack Exchange translation) --Qiita

Recommended Posts

Golf on Slack
Lunch invitation bot on Slack
Slack notification of weather information on OpenWhisk