Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

The holeyest base

+3
−0

Given a positive integer as input, indicate which base from 2 to 16 gives the most holes in the representation of the input in that base.

The digits used are 0123456789ABCDEF. Note that these include upper case letters (the number of holes would be different for lower case letters).

Different fonts have different numbers of holes per character, so the number of holes per digit is as follows for this challenge (in the format digit : number of holes):

0 : 1
1 : 0
2 : 0
3 : 0
4 : 1
5 : 0
6 : 1
7 : 0
8 : 2
9 : 1
A : 1
B : 2
C : 0
D : 1
E : 0
F : 0

Input

  • A positive integer

Output

  • A single integer from 2 to 16
  • The output indicates which base gives the representation with the most holes (being the sum of the number of holes in each digit when represented in that base)
  • For the purposes of counting holes:
    • Each representation will have no leading zeroes
    • The base indicator characters used by some languages, such as a leading 0b or 0x are not included in the counting
  • If more than one base has the highest number of holes, any such base is a valid output, but you must only output one of them

Example

For input 123 the representation in each of the bases from 2 to 16, and the associated number of holes, is as follows (in the format base : representation : holes):

2 : 1111011 : 0 + 0 + 0 + 0 + 1 + 0 + 0 = 1
3 : 11120 : 0 + 0 + 0 + 0 + 1 = 1
4 : 1323 : 0 + 0 + 0 + 0 = 0
5 : 443 : 1 + 1 + 0 = 2
6 : 323 : 0 + 0 + 0 = 0
7 : 234 : 0 + 0 + 1 = 1
8 : 173 : 0 + 0 + 0 = 0
9 : 146 : 0 + 1 + 1 = 2
10 : 123 : 0 + 0 + 0 = 0
11 : 102 : 0 + 1 + 0 = 1
12 : A3 : 1 + 0 = 1
13 : 96 : 1 + 1 = 2
14 : 8B : 2 + 2 = 4
15 : 83 : 2 + 0 = 2
16 : 7B : 0 + 2 = 2

The highest number of holes is 4, and this only occurs when the base is 14. So the only valid output is 14.

Test cases

Test cases with only 1 valid output

These test cases are in the format input : output.

2 : 2
3 : 3
4 : 2
7 : 7
8 : 2
10 : 2
12 : 2
16 : 2
17 : 2
18 : 2
20 : 2
24 : 2
27 : 3
32 : 2
33 : 2
34 : 2
35 : 2
36 : 2
37 : 2
38 : 2
40 : 2
41 : 2
42 : 2
48 : 2
49 : 2
50 : 2
51 : 2
54 : 3
59 : 12
60 : 13
61 : 13
62 : 9
63 : 13
64 : 2
65 : 2
66 : 2
67 : 2
68 : 2
69 : 2
70 : 2
72 : 2
73 : 2
74 : 2
76 : 2
77 : 2
80 : 2
82 : 2
84 : 2
85 : 2
87 : 3
94 : 11
95 : 14
96 : 2
97 : 2
98 : 2
123 : 14

Test cases including some with multiple valid outputs

These test cases are in the format input : [comma separated potential outputs] where any one of the listed outputs would be valid. These also include all of the single valid output test cases listed above.

Note that the output can be any one, but must be only one, of the potential outputs listed.

0 : [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
1 : [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
2 : [2]
3 : [3]
4 : [2]
5 : [2, 5]
6 : [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
7 : [7]
8 : [2]
9 : [2, 3]
10 : [2]
11 : [12, 13, 14, 15, 16]
12 : [2]
13 : [2, 7, 9, 13, 14, 15, 16]
14 : [2, 5, 7, 8, 10, 14]
15 : [3, 5, 9, 11, 15]
16 : [2]
17 : [2]
18 : [2]
19 : [2, 11]
20 : [2]
21 : [2, 13]
22 : [2, 14]
23 : [12, 15]
24 : [2]
25 : [2, 5, 14]
26 : [2, 9, 15]
27 : [3]
28 : [2, 3, 6, 7, 10]
29 : [3, 5]
30 : [3, 11]
31 : [3, 7, 9, 11]
32 : [2]
33 : [2]
34 : [2]
35 : [2]
36 : [2]
37 : [2]
38 : [2]
39 : [2, 14]
40 : [2]
41 : [2]
42 : [2]
43 : [2, 16]
44 : [2, 9]
45 : [2, 3, 5]
46 : [2, 7, 10]
47 : [12, 13]
48 : [2]
49 : [2]
50 : [2]
51 : [2]
52 : [2, 11]
53 : [2, 7, 9, 11, 14, 15]
54 : [3]
55 : [3, 7]
56 : [2, 12]
57 : [2, 3, 12]
58 : [2, 9, 10, 12, 13]
59 : [12]
60 : [13]
61 : [13]
62 : [9]
63 : [13]
64 : [2]
65 : [2]
66 : [2]
67 : [2]
68 : [2]
69 : [2]
70 : [2]
71 : [2, 15]
72 : [2]
73 : [2]
74 : [2]
75 : [2, 16]
76 : [2]
77 : [2]
78 : [2, 9]
79 : [2, 5, 9]
80 : [2]
81 : [2, 3]
82 : [2]
83 : [2, 3, 12]
84 : [2]
85 : [2]
86 : [2, 10, 13]
87 : [3]
88 : [2, 10]
89 : [2, 9, 10, 13]
90 : [2, 3]
91 : [2, 3, 7, 11, 16]
92 : [2, 11, 14]
93 : [2, 3, 11, 14]
94 : [11]
95 : [14]
96 : [2]
97 : [2]
98 : [2]
99 : [2, 3]
123 : [14]
1200 : [2]
1201 : [2]
1202 : [2]
1203 : [2]
1204 : [2]
1205 : [2]
1206 : [2]
1207 : [2, 11]
1208 : [2]
1209 : [2]
1210 : [2]
1211 : [12, 16]
1212 : [2]
1213 : [2, 16]
1214 : [2, 9]
1215 : [3]
1216 : [2]
1217 : [2]
1218 : [2]
1219 : [2]
1220 : [2]
1221 : [2]
1222 : [2]
1223 : [2]
1224 : [2]
1225 : [2]
1226 : [2]
1227 : [2]
1228 : [2]
1229 : [2]
1230 : [2]
1231 : [2]
1232 : [2]
1233 : [2]
1234 : [2]
1235 : [2, 12]
1236 : [2]
1237 : [2]
1238 : [2]
1239 : [2]
1240 : [2]
1241 : [2]
1242 : [2]
1243 : [2, 14, 16]
1244 : [2]
1245 : [2, 5]
1246 : [2]
1247 : [12]
1248 : [2]
1249 : [2]
1250 : [2]
1251 : [2]
1252 : [2]
1253 : [2]
1254 : [2, 12]
1255 : [2, 12]
1256 : [2, 12]
1257 : [2, 12]
1258 : [2, 12]
1259 : [12]
1260 : [2]
1261 : [2]
1262 : [2, 11]
1263 : [2, 11, 12]
1264 : [2]
1265 : [2]
1266 : [2]
1267 : [2]
1268 : [2, 12]
1269 : [2, 3, 12]
1270 : [2, 5, 12]
1271 : [12]
1272 : [2]
1273 : [2]
1274 : [2, 5]
1275 : [2, 3, 5, 9, 12, 16]
1276 : [2, 12]
1277 : [9]
1278 : [12]
1279 : [5, 12]
1280 : [2]
1281 : [2]
1282 : [2]
1283 : [2]
1284 : [2]
1285 : [2]
1286 : [2]
1287 : [2]
1288 : [2]
1289 : [2]
1290 : [2]
1291 : [2]
1292 : [2]
1293 : [2]
1294 : [2]
1295 : [12]
1296 : [2]
1297 : [2]
1298 : [2]
1299 : [2]

Explanations in answers are optional, but I'm more likely to upvote answers that have one.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

6 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+2
−0

Sclipting, (UTF-16) 86 bytes

標갠 관上가①要❶❹剩걉눑감⓶重右갰雙⓷加⓶❸分終⓷棄終并❶訂乾⓶折❷同終長괐縮⒈棄丟

Explanation:

Input n
標
갠 관上 for b from 2 to 16
    가 s = 0
    ① n' = n
    要 while n' is not 0
        ❶❹剩 x = n' mod b
        걉눑감 byte array 00 00 01 00 10 01 01 10 00 01 00 01 00 00 00 01
        ⓶重右 shift right by 2x
        갰雙 bitwise & with 0b11
        ⓷加 add to s
        ⓶❸分 n' = n' // b
    終
    ⓷棄
終
并
❶訂乾 Get the max value
⓶折❷同終長괐縮⒈棄丟 Get the index of the max value
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

The leaderboard reads this as 16 bytes from the UTF-16, so you might want to move the UTF-16 part som... (2 comments)
+3
−0

Japt -h, 19 18 bytes

Gõ ñ@ìX xg#‘5#}4s3

Try it

Gõ ñ@ìX xg#‘5#}4s3     :Implicit input of integer U
G                      :16
 õ                     :Range [1,G]
   ñ                   :Sort by
    @                  :Passing each X through the following function
     ìX                :  Convert U to base X digit array
        x              :  Reduce by addition after
         g             :    Indexing into
          #‘5#}4       :      14551254
                s3     :      Converted to base-3 string
                       :Implicit output of last element

"But, Shaggy, why ... no, how is that 14551254?" "Glad you asked! See this tip here"

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Ruby, 63 bytes

->n{(2..16).max_by{|x|n.digits(x).sum{45088003.digits(3)[_1]}}}

Attempt This Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Jelly, 20 bytes

³b‘ị“ḃṘ¤’b3¤S
⁴ḊÇÐṀḢ

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Vyxal, 19 18 bytes

16Ḣλ»≤ṪḢ»3τ?nτİ∑;∴

Try it Online!

The link goes to a program which has every test case.

-1 thanks to Steffan

Explained (old)

16Ḣλ?$τ»≤ṪḢ»3τ$İ∑;O
16# The range [2, 16]
   λ             ;O # Get the maximal items in the list by:#   Summing
    ?$τ             #   The input in that base#   Indexed into (as in, vectorised index)
       »≤ṪḢ»3τ      #   ⟨ 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 2 | 1 | 1 | 2 | 0 | 1 | 0 | 0 ⟩ (14551254 converted to base 3 - this is a 0-indexed list representing the number of holes in each letter)       
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

18 bytes: `16Ḣλ»≤ṪḢ»3τ?nτİ∑;∴` (1 comment)
+0
−0

Ruby, 77 bytes

->x{(2..16).max_by{x.to_s(_1).chars.sum{|y|"".bytes[y.hex]}}}

Attempt This Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »