ひるあんどんブログ

色々なことに手を出してみるブログ

ubuntu14.04 32bit にAndroidStudioの環境構築する。

来月Android携帯に乗り換え予定なので、面白そうだからAndroidアプリ作ってみようかと思いました。

と、いうわけでAndroid Studioの環境構築です。

OS: Ubuntu14.04(LTS) 32bit


①:Android StudiolinuxバージョンをDLしてきてインスコする。これはエラーも対して出ないので割愛。


②:出てきたエラーに対処する。

32bitは時代遅れなので、色々とエラーが出ます。自分が出たエラーは以下の2つ。


1.エミュレーター立ち上げようとしたら、そもそも立ち上がらない。

ADB in Android Studio (Ubuntu) ERROR : Unable to detect adb version, adb output: /home/hamid/Android/Sdk/platform-tools/adb: 1: /home/hamid/Android/Sdk/platform-tools/adb: Syntax error: ")" unexpected

というエラーが出る。

以下の方法を参考にして解決
askubuntu.com



2.エミュレーターが32bitに対応していないらしくて、エラーが出る。
ANDROID_EMULATOR_FORCE_32BIT=true

とすれば解決するはずなんだが、なぜかずっとエラー吐くので仕方ないからシェルスクリプトから起動時に設定してやることに。

#!/bin/bash
#
#set export ANDROID_EMULATOR_FORCE_32BIT=true

export ANDROID_EMULATOR_FORCE_32BIT=true
$HOME/android-studio/bin/studio.sh


これでとりあえずAndroidStudioが動くようになった。

めでたい。

春休み中に読んだ本と、やったゲームメモ

数学小説 確固たる曖昧さ

数学小説 確固たる曖昧さ

ペトロス伯父と「ゴールドバッハの予想」 (ハヤカワ・ノヴェルズ)

ペトロス伯父と「ゴールドバッハの予想」 (ハヤカワ・ノヴェルズ)

神は数学者か?: 万能な数学について

神は数学者か?: 万能な数学について

絶深海のソラリス (MF文庫J)

絶深海のソラリス (MF文庫J)

ゲームはほとんどsteam 一部エロゲと同人ゲー

steamでは、portal1&2と、タロスの原理(現在プレイ中)、final exam,The fall,

エロゲはsense off

同人ゲーはworld end economica(1~3) をプレイした。

今日は医師免許の申請と、お世話になった先生方への挨拶をしてきました。

あとやるべきことで残っているのは健康診断書の作成と寺社仏閣へのお礼参りくらいです。


もうすぐ研修がはじまるので、それまでの残り少ない時間をゆっくりしたいと思います。
研修病院はもともと行きたい病院ではなかったのですが、それも今となっては良い選択だったような気がしています。


とりあえず明日からなにしよう。診断書作成のために病院行くけど、他になにかすることあったっけ。あぁ、新しい銀行口座開くんだった。

医師国家試験合格しました

無事110回 医師国家試験合格しました。

登録に必要な書類は揃っているので、週明けに提出してきます。


お世話になった先生への挨拶、部屋の整理、買い出し等は今週中に済ませてしまいたいと思います。


研修先が市内なので引っ越しの必要がないだけかなり楽です。

Letter Queue

In computer science, a queue is a particular kind of data type in which the entities in the collection are kept in order and the principal operations on the collection are the addition of entities to the rear terminal position (enqueue or push), and removal of entities from the front terminal position (dequeue or pop). This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed.

We will emulate the queue process with Python. You are given a sequence of commands:

  • "PUSH X" -- enqueue X, where X is a letter in uppercase.
  • "POP" -- dequeue the front position. if the queue is empty, then do nothing.

The queue can only contain letters.

You should process all commands and assemble letters which remain in the queue in one word from the front to the rear of the queue.

Let's look at an example, here’s the sequence of commands:
["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]
Command Queue Note
PUSH A A Added "A" in the empty queue
POP Removed "A"
POP The queue is empty already
PUSH Z Z
PUSH D ZD
PUSH O ZDO
POP DO
PUSH T DOT The result

Input: A sequence of commands as a list of strings.

Output: The queue remaining as a string.

Example:

letter_queue(["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]) == "DOT"

letter_queue(["POP", "POP"]) == ""

letter_queue(["PUSH H", "PUSH I"]) == "HI"

letter_queue([]) == ""



How it is used: Queues provide services in computer science, transportation, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.

Precondition:
0 ≤ len(commands) ≤ 30;
all(re.match("\APUSH [A-Z]\Z", c) or re.match("\APOP\Z", c) for c in commands)

def letter_queue(commands):
    result = []
    for command in commands:
        if command.startswith("PUSH"):
            result.append(command[-1])
        elif command == "POP" and len(result) != 0:
            result.pop(0)
        
    return "".join(result)
        
        
    

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert letter_queue(["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]) == "DOT", "dot example"
    assert letter_queue(["POP", "POP"]) == "", "Pop, Pop, empty"
    assert letter_queue(["PUSH H", "PUSH I"]) == "HI", "Hi!"
    assert letter_queue([]) == "", "Nothing"

以前同じような課題を解いたので、それと同様にといた。

前回は与えられた文字列(例えば"PUSH A")をstr.split() でわけてから判別していた。

以前の一位の人のコードでstartswithという便利な関数があることを知ったので、今回はそれを使って解いてみた。



pythonはpop()関数で、リストのどこからpopするかを指定することができる。今回はpop(0)で添字0つまり、先頭の要素をpopした。

popは要素がないのに、呼ばれた場合にはエラーを返すのでリストが空でないことは確かめなくてはならないというところで、一回つまづいた。

はやめにエラーだしてくれるのはpythonのいいところな気がします。

さすが、委員長キャラですわ…。

しかし、なぜjoinはstr.join(シーケンス)

ではなく、(シーケンス).join(str) なんだろう。なんか、スッキリしないなぁ…。


一位の人は



def letter_queue(commands):

    import collections

    queue = collections.deque()

    for command in commands:

        if command.startswith("PUSH"):

            queue.append(command[-1])

        elif queue:

            queue.popleft()            

    return "".join(queue)

pythonでキューを実装しようとしたら、collections.dequeを用いると良いみたいです。

Xs and Os Referee

Xs and Osとしても知られているTic-Tac-Toe(訳注:三目並べ)は二人のプレイヤー(XとO)が3x3のマスの空きマスに交代で書き込むゲームです。 水平、垂直、対角線の列(NW-SEとNE-SW)に自分のマークを3つ並べるのに成功したプレイヤーがゲームに勝ちます。

しかし我々はこのゲームをプレイしません。 あなたはこのゲームの結果の審判になってください。 ゲームの結果を与えられて、ゲームが勝利または引き分けで終わったのかと同時に誰が勝利者だったかを判定しなければいけません。 Xのプレイヤーが勝ったときは"X"を返し、Oのプレイヤーが勝ったときは"O"を返し、ゲームが引き分けのときは"D"を返すことを確実にしてください。

x-o-referee

ゲームの結果は文字列のリストとして表現されます、ここで"X"と"O"はプレイヤーのマークで"."は空きのマスです。

入力: あるゲームの結果、文字列のリスト (unicode)

出力: "X", "O" または "D"、文字列

例:

checkio([

"X.O",

"XX.",

"XOO"]) == "X"

checkio([

"OO.",

"XOX",

"XOX"]) == "O"

checkio([

"OOX",

"XXO",

"OXX"]) == "D"

どのように使われるか: このタスクのコンセプトは、データ型を繰り返すときにあなたの役に立つでしょう。 結果をチェックする方法を知ることをあなたに可能にすることで、ゲームのアルゴリズムにも使うことができます。

def checkio(game_result):
    for row in game_result:
        if row[0] == row[1] == row[2] and row[0] != ".":
            return row[0]
        
    if game_result[0][0] == game_result[1][0] == game_result[2][0] and game_result[0][0] != ".":
        return game_result[0][0]
    
    if game_result[0][1] == game_result[1][1] == game_result[2][1] and game_result[0][1] != ".":
        return game_result[0][1]
    
    if game_result[0][2] == game_result[1][2] == game_result[2][2] and game_result[0][2] != ".":
        return game_result[0][2]
        
    if game_result[0][0] == game_result[1][1] == game_result[2][2] and game_result[0][0] != ".":
        return game_result[0][0]
    
    if game_result[0][2] == game_result[1][1] == game_result[2][0] and game_result[0][2] != ".":
        return game_result[0][2]
    
    return "D"

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert checkio([
        "X.O",
        "XX.",
        "XOO"]) == "X", "Xs wins"
    assert checkio([
        "OO.",
        "XOX",
        "XOX"]) == "O", "Os wins"
    assert checkio([
        "OOX",
        "XXO",
        "OXX"]) == "D", "Draw"
    assert checkio([
        "O.X",
        "XX.",
        "XOO"]) == "X", "Xs wins again"
||< 

動きます。動くけど、あまりにも無駄が多すぎる。読んだら何してるか一瞬でわかるという意味では良いコードなのかもしれないけどね…。

さて、一位のコード

>|python|


def checkio(result):

    rows = result

    cols = map(''.join, zip(*rows))

    diags = map(''.join, zip(*[(r[i], r[2 - i]) for i, r in enumerate(rows)]))

    lines = rows + list(cols) + list(diags)

<200b>

    return 'X' if ('XXX' in lines) else 'O' if ('OOO' in lines) else 'D'

mapはシーケンスのすべての要素を関数の引数として実行し、その実行結果から新しいlistを作成する。

zipとenumerateは
forループで便利な zip, enumerate関数 » Python Snippets
ということらしい。

二重になっているリストを扱うときに便利な関数らしい。