Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6720

Re: ACM online judgement for Ruby

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: ACM online judgement for Ruby
Date 2013-01-12 18:29 +0100
Message-ID <aldkraFqh4uU1@mid.individual.net> (permalink)
References <5bf55a92-91ef-46ac-96de-f49e57f2dec4@googlegroups.com> <ddd3b360-c28a-4963-a7fa-154f11d66060@googlegroups.com>

Show all headers | View raw


On 01/09/2013 05:14 AM, Liber wrote:
> i get the solution!
>
> problems here:
>
> https://www.spoj.com/problems/ADDREV/
>
> my ruby code here:
>
> ######
>
> N = gets
>
> while( (data=gets) !=nil )
>
> 	arr = data.split(' ')
> 	result = arr[0].reverse.to_i + arr[1].reverse.to_i
> 	puts result.to_s.reverse.to_i
> 	
> end
>
> ######

You do not honor the first number.  But I like your idea to get rid of 
leading zeros by converting to int!  I'd probably do

Integer(gets).times do
   a, b = gets.scan(/\d+/).map(&:reverse).map(&:to_i)
   puts (a+b).to_s.reverse.to_i
end

Cheers

	robert

Back to comp.lang.ruby | Previous | NextPrevious in thread | Find similar


Thread

ACM online judgement for Ruby Liber <gjl87910lq@gmail.com> - 2013-01-04 22:04 -0800
  Re: ACM online judgement for Ruby Liber <gjl87910lq@gmail.com> - 2013-01-08 20:14 -0800
    Re: ACM online judgement for Ruby Robert Klemme <shortcutter@googlemail.com> - 2013-01-12 18:29 +0100

csiph-web