読者です 読者をやめる 読者になる 読者になる

codeeval

Simple or trump(CodeEval)

簡易版大富豪の実装。 Scoreが80%ぐらいで、何かの考慮漏れがありそうなんだけど、よくわからないので一旦諦め。 CHALLENGE DESCRIPTION: First playing cards were invented in Eastern Asia and then spread all over the world taking different forms an…

Not so clever(CodeEval)

Bubble Sort のような(よりも効率の悪い)ソートアルゴリズムを実装する問題。 CHALLENGE DESCRIPTION: Imagine that you have to arrange items in a certain order: pencils from black to white in a color palette, photographs by the date taken, ban…

Football(CodeEval)

「チーム毎のメンバーが所属する国のリスト」を「国別のチーム一覧」に変換する問題。 日本語にすると一見複雑で、途中で何やってるかわからなくなる。 nested な配列生成が少し汚い。injectにしてもあまり変わらない。 メソッド分割をすれば良いのかもしれ…

Real Fake(CodeEval)

Credit Card のcheck tool。 実際のものではなく、架空のもの。グループごとに1, 3 番目の数字を倍にして、足し上げた結果10で割り切れれば本物と判定する。 CHALLENGE DESCRIPTION: The police caught a swindler with a big pile of credit cards. Some of…

Testing(CodeEval)

文字列の差を求める問題。 CHALLENGE DESCRIPTION: In many teams, there is a person who tests a project, finds bugs and errors, and prioritizes them. Now, you have the unique opportunity to try yourself as a tester and test a product. Here, y…

Black Card(CodeEval)

ババ抜きのような海賊ゲーム。 CHALLENGE DESCRIPTION: You must have heard about pirates, their customs, pirates code, and the “black spot”. If a pirate is presented with a “black spot”, he is officially pronounced guilty, meaning he will soo…

Trick or Treat(CodeEval)

一定ルールで数値計算して平均値を求める問題。 CHALLENGE DESCRIPTION: Everyone knows what Halloween is and how children love it. Children in costumes travel from house to house asking for treats with a phrase “Trick or treat”. After that, th…

Time to eat(CODEEVAL)

猫の餌やり時間を逆順でソートする問題。 凝っているのは問題文だけで、実装はつまらない。 CHALLENGE DESCRIPTION: It’s amazing how fast time flies by and we don’t even realize it. As we are getting older, time seems to move so much faster than …

CHARDONNAY OR CABERNET (CODEEVAL)

だんだん問題文が物語風になってきました。 文字列の中に文字列の断片が含まれるかどうかを探索する問題。 当初正規表現で書きましたが、どうもscoreが100にならないので 1文字ずつ探索しては置換する方法で実装。 CHALLENGE DESCRIPTION: Your good friend …

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…

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…

Strings and arrows(CODEEVAL)

文字列に含まれる全てのパターンをカウントする問題。 count_all_pattern がごちゃっとしてしまっている。もう少し良い方法がありそう。 CHALLENGE DESCRIPTION: You have a string composed of the following symbols: ‘>’, ‘<’, and ‘-’. Your task is to …

Stepwise Word(CODEEVAL)

最大文字数の単語を抽出し、段階的に表示させる問題。 inject を with_index と組み合わせて利用できるというのを知れたのが収穫。 CHALLENGE DESCRIPTION: Print the longest word in a stepwise manner. INPUT SAMPLE: The first argument is a path to a …

String Mask(CODEEVAL)

単語内の指定された文字だけ大文字に変更する問題。 CHALLENGE DESCRIPTION: You’ve got a binary code which has to be buried among words in order to unconsciously pass the cipher. Create a program that would cover the word with a binary mask. I…

Swap Numbers(CODEEVAL)

文中の文字列の前後を入れ替える問題。今回はつまらない。 CHALLENGE DESCRIPTION: Write a program that, given a sentence where each word has a single digit positive integer as a prefix and suffix, swaps the numbers while retaining the word in …

Compare Points(CODEEVAL)

2つの座標から方角を求める問題。 CHALLENGE DESCRIPTION: Bob’s hiking club is lost in the mountains on the way to a scenic overlook. Fortunately, Bob has a GPS device, so that he can see the coordinates where the group is currently at. The G…

minimum_distance(CODEEVAL)

配列の距離の和の最小値を求める問題。 CHALLENGE DESCRIPTION: Alice is looking for a sorority to join for her first year at Acme University. There is a street consisting entirely of sorority houses near the university, and some of her high s…

Max Range Sum(CODEEVAL)

配列から連続したN個を取り出し、合計数の最大値を算出する問題。 最初のinjectの引数を無しで書いてしまったため、10分ほど悩んでしまいました。 injectあるあるについて補足。 CHALLENGE DESCRIPTION: Bob is developing a new strategy to get rich in th…

Details(CODEEVAL)

問題の意味がとても分かりにくいのですが、matrixを作成し左側をx、右側をyが陣取り、 yがいくつ左に動くとxと衝突するかというのを求める問題のようです。 問題が悪い気がします。 CHALLENGE DESCRIPTION: There are two details on a M*N checkered field.…

Knight Moves(CODEEVAL)

チェスのナイトの移動位置を求める問題。 横がa-h、縦が1-8。これらの変換をしつつ、以下の数式を満たすパターンを求める。 # 現在位置を(x, y)、次の移動候補を(a,b)とした場合 |a| + |b| = 3 1 <= x + a <= 8 1 <= y + b <= 8 CHALLENGE DESCRIPTION: In c…

Matrix Rotation (CODEEVAL)

行列回転の問題。今回は面白かったです。 CHALLENGE DESCRIPTION: You are given a 2D N×N matrix. Each element of the matrix is a letter: from ‘a’ to ‘z’. Your task is to rotate the matrix 90° clockwise: a b c g d a d e f => h e b g h i i f c I…

Prefix Expressions(CODEEVAL)

ポーランド記法の問題。 何度かtryしましたが、scoreが100にならないです(85-95)。なんかケース漏れがありそうだけど、どういうケースでNGになっているのかcodeeval上ではわからないのが残念。 些細なミスのような気がしますが、一旦諦めました。 CHALLENGE …

SLANG FLAVOR(CODEEVAL)

句読点を変換する問題。 1個飛ばしで変換させるのが面倒。 CHALLENGE DESCRIPTION: Long serious texts are boring. Write a program that will make texts more informal: replace every other end punctuation mark (period ‘.’, exclamation mark ‘!’, or…

STRING PERMUTATIONS(CODEEVAL)

文字列の組み合わせをアルファベト順で並び替える問題。 今回も組み込みメソッドで対応。 instance method Array#permutation (Ruby 2.4.0) Codeevalとかやると、かゆいところに手が届くrubyは非常に良いと実感できます。 (本来的にはこれを素で実装しろと…

WITHOUT REPETITIONS(CODEEVAL)

すごく久しぶりにcodeevalやって見た。 繰り返し文字列を削除する問題。 愚直にできなくはないのですが、なんか便利メソッドないかと調べて見たら そのものズバリの instance method String#squeeze (Ruby 2.4.0) というものがありました。 CHALLENGE DESCRI…

BIG DIGITS(CodeEval)

hatenaでは見にくいか。 CHALLENGE DESCRIPTION: In this challenge you're presented with a situation in which you need to output big symbols on devices which only support ASCII characters and single, fixed-width fonts. To do this you're going…

DELTA TIME(CodeEval)

CHALLENGE DESCRIPTION: You are given the pairs of time values. The values are in the HH:MM:SS format with leading zeros. Your task is to find out the time difference between the pairs. INPUT SAMPLE: 14:01:57 12:47:11 13:09:42 22:16:15 08:0…

Roller Coaster(CodeEval)

CHALLENGE DESCRIPTION: You are given a text. Your job is to write a program to set the case of text characters based on the following: First letter of the line should be upper case. Next letter should be lower case. Next letter should be u…

READ MORE(CodeEval)

すごい久しぶりにcodeeval。 CHALLENGE DESCRIPTION: You are given a text. Write a program which outputs its lines according to the following rules: 1. If line length is ≤ 55 characters, print it without any changes. 2. If the line length is …

RACING CHARS(CodeEval)

CHALLENGE DESCRIPTION: In this challenge you will be given a file where each line is a section of a race track with obstructions, gates and checkpoints. The goal is to find a way of passing this track, using the following rules: Each secti…

THE MAJOR ELEMENT(CodeEval)

CHALLENGE DESCRIPTION: The major element in a sequence with the length of L is the element which appears in a sequence more than L/2 times. The challenge is to find that element in a sequence. INPUT SAMPLE: Your program should accept as it…

SPLIT THE NUMBER(CodeEval)

CHALLENGE DESCRIPTION: You are given a number N and a pattern. The pattern consists of lowercase latin letters and one operation "+" or "-". The challenge is to split the number and evaluate it according to this pattern e.g. 1232 ab+cd -> …

COMPRESSED SEQUENCE(CodeEval)

美しくない。 CHALLENGE DESCRIPTION: Assume that someone dictates you a sequence of numbers and you need to write it down. For brevity, he dictates it as follows: first says the number of consecutive identical numbers and then says the numb…

ROAD TRIP(CodeEval)

CHALLENGE DESCRIPTION: You've decided to make a road trip across the country in a straight line. You have chosen the direction you'd like to travel and made a list of cities in that direction that have gas stations to stop at and fill up y…

HIDDEN DIGITS(CodeEval)

CHALLENGE DESCRIPTION: In this challenge you're given a random string containing hidden and visible digits. The digits are hidden behind lower case latin letters as follows: 0 is behind 'a', 1 is behind ' b ' etc., 9 is behind 'j'. Any oth…

MORSE CODE(CodeEval)

CHALLENGE DESCRIPTION: You have received a text encoded with Morse code and want to decode it. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following: .- ...- ..--- .-- .... .. .…

MIXED CONTENT(CodeEval)

CHALLENGE DESCRIPTION: You have a string of words and digits divided by comma. Write a program which separates words with digits. You shouldn't change the order elements. INPUT SAMPLE: Your program should accept as its first argument a pat…

MULTIPLY LISTS(CodeEval)

CHALLENGE DESCRIPTION: You have 2 lists of positive integers. Write a program which multiplies corresponding elements in these lists. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the…

SWAP ELEMENTS(CodeEval)

CHALLENGE DESCRIPTION: You are given a list of numbers which is supplemented with positions that have to be swapped. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following 1 2 3 …

LONGEST WORD(CodeEval)

CHALLENGE DESCRIPTION: In this challenge you need to find the longest word in a sentence. If the sentence has more than one word of the same length you should pick the first one. INPUT SAMPLE: Your program should accept as its first argume…

SHORTEST REPETITION(CodeEval)

CHALLENGE DESCRIPTION: Write a program to determine the shortest repetition in a string. A string is said to have period p if it can be formed by concatenating one or more repetitions of another string of length p. For example, the string …

ROMAN NUMERALS(CodeEval)

CHALLENGE DESCRIPTION: Many persons are familiar with the Roman numerals for relatively small numbers. The symbols I (capital i), V, X, L, C, D, and M represent the decimal values 1, 5, 10, 50, 100, 500 and 1000 respectively. To represent …

WORD TO DIGIT(CodeEval)

CHALLENGE DESCRIPTION: Having a string representation of a set of numbers you need to print this numbers. All numbers are separated by semicolon. There are up to 20 numbers in one line. The numbers are "zero" to "nine" INPUT SAMPLE: Your p…

LOWEST UNIQUE NUMBER(CodeEval)

CHALLENGE DESCRIPTION: here is a game where each player picks a number from 1 to 9, writes it on a paper and gives to a guide. A player wins if his number is the lowest unique. We may have 10-20 players in our game. INPUT SAMPLE: Your prog…

JSON MENU IDS(CodeEval)

CHALLENGE DESCRIPTION: You have JSON string which describes a menu. Calculate the SUM of IDs of all "items" in the case a "label" exists for an item. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Inpu…

EVEN NUMBERS(CodeEval)

CHALLENGE DESCRIPTION: Write a program which checks input numbers and determines whether a number is even or not. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following 701 4123 …

CALCULATE DISTANCE(CodeEval)

CHALLENGE DESCRIPTION: You have coordinates of 2 points and need to find the distance between them. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following (25, 4) (1, -6) (47, 43…

FIND A WRITER(CodeEval)

西村京太郎先生は海外でも有名なんですね。 CHALLENGE DESCRIPTION: You have a set of rows with names of famous writers encoded inside. Each row is divided into 2 parts by pipe char (|). The first part has a writer's name. The second part is a…

SWAP CASE(CodeEval)

CHALLENGE DESCRIPTION: Write a program which swaps letters' case in a sentence. All non-letter characters should remain the same. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the fol…

CAPITALIZE WORDS(CodeEval)

CHALLENGE DESCRIPTION: Write a program which capitalizes the first letter of each word in a sentence. INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following Hello world javaScrip…