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 …

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…