Find the highest score(CODEEVAL)

配列の行列変換後、それぞれの最大値を求める問題。
RubyならArray#transpose/zip を使えば楽勝ですね。

CHALLENGE DESCRIPTION:

You decided to hold a banquet in honor of the World Art Day, where you invited all designers and artists that you know. During the banquet, you decided to find out which art movement and style the ordinary people like most of all, and whose works can get the highest score. To find the answer, you decided to hold an exhibition, where viewers will be able to evaluate each painting and vote for or against it. Each artist should create one work per each art movement. After the exhibition, the participants calculated votes that they received for each painting and inserted them in the table. But, they could not determine which movement has won and whose work received the highest score, so they asked you to help. You need to determine and print the highest score of each category in the table.

INPUT SAMPLE:

The first argument is a path to a file. Each line includes a test case with a table. Table rows are separated by pipes ‘|’. All table rows contain scores for each category, so all lines are of an equal length.

72 64 150 | 100 18 33 | 13 250 -6
10 25 -30 44 | 5 16 70 8 | 13 1 31 12
100 6 300 20 10 | 5 200 6 9 500 | 1 10 3 400 143

OUTPUT SAMPLE:

100 250 150
13 25 70 44
100 200 300 400 500

CONSTRAINTS:

  1. All lines in a test case are of an equal length.
  2. The number of participants can be from 2 to 10 people.
  3. The number of categories can be from 4 to 20.
  4. The number of points for one picture can be from -1000 to 1000.
  5. The number of test cases is 40.

My Code

#!/usr/bin/env ruby -w

def heighest_scores(rows)
  rows.transpose.map(&:max)
end

ARGF.each_line do |line|
  rows = line.chomp.split("|").map { |row| row.split.map(&:to_i) }
  puts heighest_scores(rows).join(" ")
end

Override emmet snippets on Atom Editor

emmet 便利ですよね。
snippets や shift + cmd + ' でhtmlタグ除去とか、ctrl + d で outward 選択などはよく使います。
snippetsで1つ修正したい箇所があったので調べて見ました。

やりたいこと

! or html:5 で以下のようなsnippetsが展開されるのですが、 lang=“en” のところが余分だなと以前から思っていました。
(ちなみに lang は環境によって変わります)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>

</body>
</html>

調べてみる

Atom Package Settings

設定画面の最下部にリンクがありました。
Customization
extensionsフォルダにsnippets.jsonを用意すればいいなど色々と書いてあります。
 
他にも以前から気になっていた tabstop の index が 0 始まりのものについての補足がありました。
0始まりはtextmate時代の名残のようで(tabstopが終わった後のキャレット位置を指定できる機能?)、現在は1から始めるのが望ましいと書いています。

ちなみにextensionsフォルダ(設定ファイルの場所)は default: ~/emmet ですが、以下のように変更可能です。
f:id:rochefort:20170411231723p:plain

書き方

default はどうやら以下にあるようなので、それを元に変更して見ました。
.atom/packages/emmet/node_modules/emmet/lib/snippets.json

{
    "html": {
        "abbreviations": {
        "!": "!!!+doc",
        "html:5":   "!!!+doc"
        }
    }
}

今回修正すべきは、snippets ではなく abbreviations でした。

Clean up the words(CODEEVAL)

英数字以外を抽出する問題。簡単。

CHALLENGE DESCRIPTION:

You have a list of words. Letters of these words are mixed with extra symbols, so it is hard to define the beginning and end of each word. Write a program that will clean up the words from extra numbers and symbols.

INPUT SAMPLE:

The first argument is a path to a file. Each line includes a test case with a list of words: letters are both lowercase and uppercase, and are mixed with extra symbols.

(--9Hello----World...--)
Can 0$9 ---you~
13What213are;11you-123+138doing7

OUTPUT SAMPLE:

hello world
can you
what are you doing

CONSTRAINTS:

  1. Print the words separated by spaces in lowercase letters.
  2. The length of a test case together with extra symbols can be in a range from 10 to 100 symbols.
  3. The number of test cases is 40.

My Code

#!/usr/bin/env ruby -w
def clenup(words)
  words.gsub(/[^A-Za-z]/, " ").downcase.split.join(" ")
end

ARGF.each_line do |line|
  puts clenup(line.chomp)
end