13
This is Hole-1 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.
Given a list of numbers, produce a horizontal bar chart of #
characters for how many numbers fit into each of ten equal-sized groups. For example, if the data ranges from 0-100, the ranges will be 0–9.9, 10–19.9, …, 90–100. (Formally, [0,10), [10,20), …, [90,100].). You may assume that there will be at least two numbers and that not all numbers will be the same.
Examples:
[1,0,0,0,0,0,0,0,0,0]
gives:
#########
#
[0,1,2,3,4,5,6,7,8,9]
gives:
#
#
#
#
#
#
#
#
#
#
[0,1,2,3,4,5,6,7,8,9,10]
gives:
#
#
#
#
#
#
#
#
#
##
[0,1,2,3,4,5,6,7,8,9,10,11]
gives:
##
#
#
#
#
#
#
#
#
##
[0,-0.5,-1,-1.5,-2,-2.5,-3,-3.5,-4,-4.5,0.5,0,-0.5,-1,-1.5,-2,-2.5,-3,-3.5,-4,1,0.5,0,-0.5,-1,-1.5,-2,-2.5,-3,-3.5,1.5,1,0.5,0,-0.5,-1,-1.5,-2,-2.5,-3,2,1.5,1,0.5,0,-0.5,-1,-1.5,-2,-2.5,2.5,2,1.5,1,0.5,0,-0.5,-1,-1.5,-2,3,2.5,2,1.5,1,0.5,0,-0.5,-1,-1.5,3.5,3,2.5,2,1.5,1,0.5,0,-0.5,-1,4,3.5,3,2.5,2,1.5,1,0.5,0,-0.5,4.5,4,3.5,3,2.5,2,1.5,1,0.5,0]
gives:
###
#######
###########
###############
#########
###################
###############
###########
#######
###
[9014,9082,9077,9068,8866,8710,9049,8364,8867,9015,9064,9023,9024,8804,8805,8800,8744,8743,8714,9076,8593,8595,9075,9675,8968,8970,8711,8728,8834,8835,8745,8746,8869,8868,9073,9074,9042,9035,9033,9021,8854,9055,9017,9045,9038,9067,9066,8801,8802,9496,9488,9484,9492,9532,9472,9500,9508,9524,9516,9474,8739,9079,8900,8592,8594,9053,9109,9054,9059]
gives:
#
####
#########
############
######
#########################
###########
#
[0,8,10,13,32,12,6,7,27,9,37,39,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,1,2,175,46,48,49,50,51,52,53,54,55,56,57,3,165,36,163,162,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,4,5,253,183,127,193,194,195,199,200,202,203,204,205,206,207,208,210,211,212,213,217,218,219,221,254,227,236,240,242,245,123,125,168,192,196,197,198,201,209,214,216,220,223,224,225,226,228,229,230,231,232,233,234,235,237,238,239,241,91,47,92,60,61,62,45,43,247,215,63,126,42,40,124,59,44,33,243,244,246,248,34,35,30,38,180,64,249,250,251,94,252,96,182,58,191,161,41,93,31,160,167]
gives:
#############
######################
##########################
#########################
#########################
#
########
################
########################
##########################
3So, the final group is a tiny bit larger? Like in the first example, it would be
[0.9,1]
(and not[0.9,1)
)? – Felix Palmen – 2017-10-17T08:37:18.003@FelixPalmen Kind of. It is only larger by an infinitely small amount. – Adám – 2017-10-17T08:48:55.580
Ok, important thing to know was that it's indeed the last group that should include both endpoints, thanks – Felix Palmen – 2017-10-17T08:51:03.077
@FelixPalmen Ah, I see that that wasn't entirely clear in the OP. I'll edit it in. – Adám – 2017-10-17T09:00:20.120
Are we allowed to return a list of strings instead (list of lines)? – Mr. Xcoder – 2017-10-17T09:50:11.387
@Mr.Xcoder Sure. – Adám – 2017-10-17T09:52:27.680
Are we allowed to use
-
signs instead of#
s? – Neil – 2017-10-17T09:56:39.253@Neil No, hashes it is. – Adám – 2017-10-17T09:57:13.277
I don't understand example 1. Why 9 #s on first row. Why the last row is not empty. – edc65 – 2017-10-17T12:23:36.060
@edc65 The overall range is from
[0,1]
, and 9 of the entries in the supplied list are0
, so there are nine hashes in the first ([0,0.1)
) row, and one1
hash in the last ([0.9,1.0]
) row. – AdmBorkBork – 2017-10-17T12:37:12.870@AdmBorkBork ok got it thx – edc65 – 2017-10-17T13:40:25.837
I suggest adding test case
[0,1,2,3,4,5,6,7,8,9,10]
– user202729 – 2017-10-18T10:17:10.283@user202729 Done. – Adám – 2017-10-18T10:44:46.023
1@Adám Should it be reverse instead? The top row is
[0,1)
containing only0
while the bottom row is[9,10]
contains both9
and10
. – user202729 – 2017-10-18T10:56:13.887@user202729 You're right. I guess the Octave solution is wrong then! – Adám – 2017-10-18T10:59:01.670
@user202729 I should add
[0,1,2,3,4,5,6,7,8,9,10,11]
too. – Adám – 2017-10-18T10:59:55.360You should have tortured Jelly by making the character be
⌸
. – Zacharý – 2017-10-20T22:29:25.473@Zacharý Would have been torture for everyone; afaik no 256 char char set has it. – Adám – 2017-10-21T21:04:24.720
I'm referring to languages that wouldn't be able to handle it at all. – Zacharý – 2017-10-21T21:15:17.277
@Zacharý I think Jelly can do Unicode. – Adám – 2017-10-21T21:27:55.193
I don't think so: https://tio.run/##y0rNyan8//9Rw5xHPTseNcz9/x8A
– Zacharý – 2017-10-21T21:32:27.417@Zacharý https://chat.stackexchange.com/transcript/message/40684322#40684322
– Adám – 2017-10-21T21:40:22.953