From 880017eb30874f107b0bdf8810a717fb9554a656 Mon Sep 17 00:00:00 2001 From: Yasuyuki Fujikawa Date: Wed, 6 Dec 2017 12:34:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=8F=E3=81=A6=E3=81=84=E3=81=84=E3=82=82?= =?UTF-8?q?=E3=81=AE=E3=82=92=20.gitignore=20=E3=81=AB=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0d5033 --- /dev/null +++ b/.gitignore @@ -0,0 +1,115 @@ +# Created by https://www.gitignore.io/api/ruby,rubymine+all + +### Ruby ### +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +### RubyMine+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Ruby plugin and RubyMine +/.rakeTasks + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### RubyMine+all Patch ### +# Ignores the whole idea folder +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# End of https://www.gitignore.io/api/ruby,rubymine+all \ No newline at end of file From a6a3db4b62eaa6a270091262e16226619b284997 Mon Sep 17 00:00:00 2001 From: Yasuyuki Fujikawa Date: Wed, 6 Dec 2017 12:38:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E5=87=A6=E7=90=86=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E3=81=A8=E3=82=AF=E3=83=A9=E3=82=B9=E5=90=8D=E3=81=8C=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/{transport.rb => transpose.rb} | 2 +- test/transport_test.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename lib/{transport.rb => transpose.rb} (91%) diff --git a/lib/transport.rb b/lib/transpose.rb similarity index 91% rename from lib/transport.rb rename to lib/transpose.rb index d930638..38b5ae4 100644 --- a/lib/transport.rb +++ b/lib/transpose.rb @@ -1,4 +1,4 @@ -def transport(source) +def transpose(source) array = source.split("\n").map {|s| s.split(" ")} rows_count = array.first.count diff --git a/test/transport_test.rb b/test/transport_test.rb index 64126c8..f1a3e7a 100644 --- a/test/transport_test.rb +++ b/test/transport_test.rb @@ -1,14 +1,14 @@ require 'minitest/autorun' -require './lib/transport' +require './lib/transpose' -class TransportTest < MiniTest::Test - def test_transport +class TransposeTest < MiniTest::Test + def test_transpose input = "1 2 3\n4 5 6\n7 8 9" output = "1 4 7\n2 5 8\n3 6 9" - assert_equal output, transport(input) + assert_equal output, transpose(input) input = "1 2 3\n4 5 6\n7 8 9\n10 11 12" output = "1 4 7 10\n2 5 8 11\n3 6 9 12" - assert_equal output, transport(input) + assert_equal output, transpose(input) end end \ No newline at end of file From ac99c9a176706d4d2feaaf2bb690cb0743978dea Mon Sep 17 00:00:00 2001 From: Yasuyuki Fujikawa Date: Wed, 6 Dec 2017 12:43:12 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=81=AB2=E3=81=A4=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=8C=E6=9B=B8=E3=81=8B=E3=82=8C?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81=E5=88=86?= =?UTF-8?q?=E5=89=B2=E3=81=97=E3=81=A6=E3=82=8F=E3=81=8B=E3=82=8A=E3=82=84?= =?UTF-8?q?=E3=81=99=E3=81=8F=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/transport_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/transport_test.rb b/test/transport_test.rb index f1a3e7a..21e7c0d 100644 --- a/test/transport_test.rb +++ b/test/transport_test.rb @@ -2,11 +2,13 @@ require './lib/transpose' class TransposeTest < MiniTest::Test - def test_transpose + def test_transpose_3x3 input = "1 2 3\n4 5 6\n7 8 9" output = "1 4 7\n2 5 8\n3 6 9" assert_equal output, transpose(input) + end + def test_transpose_4x4 input = "1 2 3\n4 5 6\n7 8 9\n10 11 12" output = "1 4 7 10\n2 5 8 11\n3 6 9 12" assert_equal output, transpose(input) From 8a1f36dd16849d72acbf7a256add2150e3e02f12 Mon Sep 17 00:00:00 2001 From: Yasuyuki Fujikawa Date: Wed, 6 Dec 2017 12:48:31 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Array=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AB?= =?UTF-8?q?=E5=90=8C=E6=A7=98=E3=81=AE=E5=87=A6=E7=90=86=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=81=A3=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81=E7=BD=AE?= =?UTF-8?q?=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/transpose.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/transpose.rb b/lib/transpose.rb index 38b5ae4..bca90c0 100644 --- a/lib/transpose.rb +++ b/lib/transpose.rb @@ -1,11 +1,5 @@ def transpose(source) array = source.split("\n").map {|s| s.split(" ")} - rows_count = array.first.count - - transported_array = [] - 0.upto(rows_count - 1) do |i| - transported_array << array.map {|a| a[i]} - end - + transported_array = array.transpose transported_array.map {|s| s.join(" ")}.join("\n") end \ No newline at end of file