Code:
”‡Á•Ë: ÿ”,”Vowelš‹: ”?"aeiou"©vy": "¹y¢««}", "ý,“«¶šÞ: “ª¹®-J,
Explanation:
There is a lot of string compression going on here. Here is a list of all strings that are compressed:
”‡Á•Ë”
is equivalent to Enter String
.
”Vowelš‹”
is equivalent to Vowel Count
.
“«¶šÞ“ª
is equivalent to Remaining characters
.
To see how the actual string compression works, see the Hello, World! answer, or an even more elaborate explanation at the bottom of the Code Review question. Without the string compression, the code looks like this:
"Enter String: ÿ","Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,"Remaining characters: "¹®-J,
Or a more readable 3-part version:
"Enter String: ÿ",
"Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,
"Remaining characters: "¹®-J,
Part 1:
We first push the string "Enter String: ÿ"
. The ÿ
here is used for string interpolation. But since the stack is empty, implicit input is requested. The ÿ
will be substituted with the user input. We print this with a newline using ,
.
Part 2:
We first print the "Vowel Count: "
string without a newline using ?
. After that, we push the aeiou
string, ©
opy that to the register and map over the string using v
and do the following:
vy": "¹y¢««} # Mapping loop
v } # The loop itself
y # Push the current letter (which is a, e, i, o or u)
": " # Push this string
¹ # Push the first input again
y # Push the letter again
¢ # Count the number of occurences of that letter in the input
«« # Concatenate to one single string, (e.g. "a: 4")
This leaves 5 different string onto the stack, the stack looks like this now:
stack: ['a: 0', 'e: 1', 'i: 0', 'o: 2', 'u: 0']
We join each element in the stack with ", "
using ý
. After this, we print it with a newline using ,
.
Part 3:
We first push the string "Remaining characters: "
. We push the first input again using ¹
. We then push "aeiou"
which we retrieve from the register using ®
. After this, we remove all letters in aeiou
using -
and J
oin this with the Remaining characters
-string. Finally, we output this with a newline using ,
.
Uses CP-1252 encoding. Try it online!.
1Edited to better suit the site. Yeah... Just browsing other questions and even taking the tour isn't much help. Gotta be a better way. – Caleb Woodman – 2016-05-03T16:25:56.577
1
Yeah, that is something that I have been complaining about recently. Your edit makes the post a lot better. The only other thought I have would be to add some test input and output like you had in the first revision. Maybe even some additional test cases.
– James – 2016-05-03T16:27:59.4835Okay. I can certainly do that. And thank you, wonderful community, for being more forgiving than Stack Overflow to noobs. – Caleb Woodman – 2016-05-03T16:31:42.560
2Is the output format flexible? For example, can the output contain only the numbers (without the vowel names) and then the consonants in a different line? – Luis Mendo – 2016-05-03T16:35:50.897
No not flexible, this interface specifically. – Caleb Woodman – 2016-05-03T16:36:47.280
Also, is the input format flexible? Rather than prompting the user, could I take the string as a function argument? (This is generally the default. You can override the default, but it's not recommended.) – James – 2016-05-03T16:36:57.967
No. It must be an input in this case, I agree, this is a little against the norm :) – Caleb Woodman – 2016-05-03T16:38:06.287
Unfortunately I think this question will boil down to which language has the shortest compression of strings – Blue – 2016-05-03T16:43:57.473
6You're treating lowercase
a
different than capitalA
? – AdmBorkBork – 2016-05-03T16:45:02.0775
Also, for future challenges, I heartily recommend using the Sandbox, so you can elicit feedback before posting to the main page, and thus make your challenge even better. Welcome to PPCG!
– AdmBorkBork – 2016-05-03T16:46:59.123This is missing a blurb about what characters will be in the input. Will the input include newlines, unicode, etc? From your example it seems like you might not want spaces. – FryAmTheEggman – 2016-05-03T17:13:09.023
4The fun fact is that we are trying to be nice – edc65 – 2016-05-03T19:27:21.150
5
@CalebWoodman I don't think it has anything to do with being a noob or not -- rather, restrictive input/output requirements on non-Kolmogorov challenges shift the focus of the challenge, so that instead of actually doing work on the interesting part, people instead need to account for the I/O requirements, which instead feels like drudgery. Please don't take the downvotes personally (see the PostScript to Peter's answer)!
– AdmBorkBork – 2016-05-03T19:30:00.2002
Welcome to Programming Puzzles and Code Golf. This might be worth reading. The main problem here is the cumbersome output format, which isn't actually the interesting part of this challenge. Since no one actually gave a solution on how this can be fixed, here's my suggestion. Instead of the long output format, try to change the output format to something like
– Adnan – 2016-05-03T20:56:18.377[1, 2, 0, 3, 4] \n LrmIpsmDlrStAmtCnsctrAdpscngElt
. Or something else involving just an array and a string :p.Do capital vowels not count as vowels (i.e. are not counted and removed)? – Michelfrancis Bustillos – 2016-05-04T12:28:30.350
You're clearly missing a vowel.. (
y
). You English people and their lack of 'y' as vowels.. shakes head in disappointment – Kevin Cruijssen – 2016-05-04T12:44:15.493For these purposes, no 'y', but yes, I believe in its vowelitude. – Caleb Woodman – 2016-05-04T15:43:19.473
@KevinCruijssen. And w. Tsk. All the Welsh people must be feeling left out. – TRiG – 2016-05-06T10:41:00.600
Um, crafting my solution-- vowel majuscules seem to be ignored. Is that correct? Otherwise the vowels should be a: 2 e: 5 i: 5 o: 4 and u:3. – Dúthomhas – 2016-05-06T11:53:22.550