Marcus Andrews

 The Nineteenth Byte

The Nineteenth Byte: General discussion for codegolf.stackexc...
Nov 28, 2017 22:22
Try [1, 2, 3, 4, 5]
Nov 28, 2017 22:22
@Poke doesn't work with odd-length
Nov 28, 2017 22:14
same as every-other-letter from left to right and then the same wrapping around to the left (accounts for both even and odd)
Nov 28, 2017 22:14
shorter way to do this either in python or ruby? (s is a string):

print((s+s[::-1])[::2])
Nov 28, 2017 15:31
nvm found shorter ways
Nov 28, 2017 15:27
for a single hex sent in through stdin?
Nov 28, 2017 15:27
any way to do this without read n?
Nov 28, 2017 15:27
```
read n
echo $((0x$n))
```
Nov 28, 2017 15:24
Or a bash method perhaps
Nov 28, 2017 15:19
Is there a shorter way to convert hex to decimal in ruby than p gets.to_i(16)?
Nov 28, 2017 15:06
impressive!
Nov 28, 2017 14:52
my best is

n,r=gets.split.map &:to_i
puts n.times.map{|i|i*r}*" "
Nov 28, 2017 14:52
also reading in the input
Nov 28, 2017 14:51
output would need to be same line
Nov 28, 2017 14:40
Shorter way in Ruby (<54 bytes, my best) to print n terms of an arithmetic sequence starting from 0 with common term r?


Input
6 2
Output
0 2 4 6 8 10

Input
4 0
Output
0 0 0 0
Nov 28, 2017 00:07
Would there happen to be a shorter way to do a,b=gets.split.map(&:to_i) in Ruby?
Nov 27, 2017 22:28
from what I can tell tr doesn't allow any reverse range workarounds without adding more chars anyway
Nov 27, 2017 22:26
does that work with my tr code?
Nov 27, 2017 22:25
e.g. if I am doing tr 01234 98765 I can do tr 0-4 98765 but it doesn't like tr 0-4 9-5 because the 9-5 is in reverse order
Nov 27, 2017 22:25
Hm is there a shorter way in bash to do a reverse range?
Nov 27, 2017 22:15
thanks Conor
Nov 27, 2017 22:15
ah perfect!
Nov 27, 2017 22:14
Hm or a shorter way to read in a sorted string in ruby other than gets.split("").sort ?
Nov 27, 2017 21:56
Given a line of space-separated integers, is there a short ruby method for finding the product of that list?
Nov 23, 2017 17:33
19
Nov 23, 2017 17:20
(at 28 currently)
Nov 23, 2017 17:17
Shortest way to count letters in a sentence using Ruby?
Nov 20, 2017 14:45
I guess you have to join straight from the map rather than each
Nov 20, 2017 14:45
(nvm I had to do puts gets.split.map{|k|s[k.to_i-1]}*"" but curious why the previous one didn't work)
Nov 20, 2017 14:39
(for a line of indices such as "5 3 1 4" etc)
Nov 20, 2017 14:39
is this not the right way to print out a join of chars from a string s by indices?

puts gets.split.map(&:to_i).each{|i|s[i-1]}*""
Nov 20, 2017 01:24
two lines: integer m, and then a line of space-separated integers -- is there a shorter way in ruby?
Nov 20, 2017 01:24
m=gets.to_i
p gets.split.map{|x|x.to_i%m}.sum
Nov 18, 2017 03:46
if g=="M", output 5/6 times w. If "F", 6/5 times w. Otherwise "UNKNOWN"
Nov 18, 2017 03:46
this is as far as I got
Nov 18, 2017 03:46
Is there a shorter way in Ruby to do the following?

g=gets.chop
w=gets.to_i
puts g==?M?w*5/6:g==?F?w*6/5:"UNKNOWN"
Nov 17, 2017 21:26
if just for one pair then
p gets.split.map{|x|x.to_i.to_s(2).to_i}.sum
Nov 17, 2017 21:23
61
gets.to_i.times{p gets.split.map{|x|x.to_i.to_s(2).to_i}.sum}
Nov 17, 2017 21:21
I tried to put the to_s(2).to_i stuff in the map but it doesn't like it
Nov 17, 2017 21:20
is my approach
Nov 17, 2017 21:20
gets.to_i.times{a,b=gets.split.map(&:to_i);p a.to_s(2).to_i+b.to_s(2).to_i}
Nov 17, 2017 21:20
then loop and print over each pair
Nov 17, 2017 21:20
you read in n, the number of pairs
Nov 17, 2017 21:20
I forgot to mention that it's over a list
Nov 17, 2017 21:13
i'm at 75 char ruby atm
Nov 17, 2017 21:13
any shorter way to do this one in python or ruby?

take in two numbers (one line, space-delimieted), convert to binary, and add them as if they were decimal.

input: 13 89
output: 1012102
Nov 17, 2017 18:38
has to be case insensitive
Nov 17, 2017 18:35
46 ruby
Nov 17, 2017 18:27
my current best: print(*(sum(l.lower()in"aeiou"for l in w)for w in input().split()))
Nov 17, 2017 18:27
(in either python or ruby?)