How to achieve paiza rank D

Introduction

*** paiza How can I achieve Rank D ***? I explained the guideline.

Premise

Since the author is mainly learning Ruby, I will explain it in Ruby.

Run

For example, to enter a number of your choice and output it, write the following code.

x = gets.chomp.to_i
puts x

You need to rewrite gets a little to enter more than one number.


x = gets.split().map(&:to_i)
puts x

You can use the split method to get multiple input values as an array. mapYou can easily convert the contents of the array using methods. If the argument is &: to_i, all the input values can be obtained as numerical values.

Here, if there are two input values, the difference between the first input value and the second input value can be calculated as follows.


x = gets.split().map(&:to_i)
puts x[0] -x[1]

Since x is obtained as an array, you can use the operators between the elements of the array to calculate the difference between the input values.

If you can master the above things. *** paiza Rank D *** is just around the corner.

Recommended Posts

How to achieve paiza rank D
How to achieve paiza rank C (times method)
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
How to achieve file download with Feign
How to achieve file upload with Feign
How to deploy
List of methods used in PAIZA D rank
How to develop OpenSPIFe
How to call AmazonSQSAsync
How to use Map
How to use rbenv
How to use letter_opener_web
paiza Ruby What I did to become B rank
How to use with_option
How to use fields_for
How to use java.util.logging
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to install Docker
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to write dockerfile
How to uninstall Rails
How to install docker-machine
[How to use label]
How to make shaded-jar
How to write docker-compose
How to use identity
How to use hashes
How to write Mockito
How to create docker-compose
How to use JUnit 5
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to install ngrok
How to type backslash \
How to concatenate strings
[Spoilers] Long table eel shop (equivalent to paiza rank B)
How to delete BOM (UTF-8)
How to create an application
[Java] How to use Map
How to resolve Sprockets :: DoubleLinkError
[rails] How to post images
[AWS] How to check logs
How to resolve Git conflicts
How to lower java version
[Java] How to use Map
How to use Priority Queuing
How to uninstall Java 8 (Mac)
How to write good code
How to handle uploaded images
How to add ActionText function