最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

typescript - Generating Unique Codes Not Including All Words (Angular + TS) - Stack Overflow

matteradmin6PV0评论

I have the following:

.ts

Where I am trying to generate a code based on an input. For my example above I have:

input: Project Tracker Tool & Category Beta (BET)

output: PROTTERTBET and POCTERTOBET and so on...

(it ends with the same category depending on the input category)

But I have the issue where ideally I want the code to be more meaningful because my code only slices the first 8 characters which means for the word "Tool", none of its characters are included in the final output. My desired output is:

  • At least 1 character at minimum from each word is included.

  • It maintains the ordering of the characters so no randomization of selected characters

  • For longer inputs ideally all max out 8 characters, can vary e.g. selects 3 characters from first word, 3 from second, 2 from 3rd and so on. By this I mean the itemName maxes at 8 not the entire output.

  • Will also have smaller inputs e.g. "Tool" where it will maybe just use the entire word.

  • 6 character words MyItem maybe MyItem or MYITM.

  • Should generate new outputs (chances of the having same output is fine).

Project Tracker Tool examples should output PRJTRTOL or PJCTTKTL

I have the following:

https://stackblitz/edit/stackblitz-starters-ujlmy6?file=src%2Fmain.ts

Where I am trying to generate a code based on an input. For my example above I have:

input: Project Tracker Tool & Category Beta (BET)

output: PROTTERTBET and POCTERTOBET and so on...

(it ends with the same category depending on the input category)

But I have the issue where ideally I want the code to be more meaningful because my code only slices the first 8 characters which means for the word "Tool", none of its characters are included in the final output. My desired output is:

  • At least 1 character at minimum from each word is included.

  • It maintains the ordering of the characters so no randomization of selected characters

  • For longer inputs ideally all max out 8 characters, can vary e.g. selects 3 characters from first word, 3 from second, 2 from 3rd and so on. By this I mean the itemName maxes at 8 not the entire output.

  • Will also have smaller inputs e.g. "Tool" where it will maybe just use the entire word.

  • 6 character words MyItem maybe MyItem or MYITM.

  • Should generate new outputs (chances of the having same output is fine).

Project Tracker Tool examples should output PRJTRTOL or PJCTTKTL

Share Improve this question asked Nov 16, 2024 at 23:18 WickedWicked 1332 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

From what I understand, the reference must be a maximum of 8 characters long. But does it have to be this length? If so, you'll need to take into account that you'll need to add one or more predefined characters to fill in if the item passed as a parameter is smaller than the minimum size.

Secondly, to answer your question, the human brain can recognize a word, especially by its first and last letters, and the content in the middle more or less resembles the complete word. For example, reading 'acheivement' when there's an error is relatively easy. It's also worth noting that the human brain is very good at reading without vowels, which it can reconstruct fairly well. If we take the word 'table' for example, it's quite easy to read with 'TBL'.

So, in terms of algorithm, I think it might be interesting to keep the first and last vowels of the word. Delete vowels (word by word), as long as the string is not smaller than the maximum size. If there are strictly more than 4 words in the input, you'll need to define a different algorithm (keep only the first of each word?). The same question arises if there are more than 8 words in the input (keep only the first letter of the first words?).

I'm sure we'll need more details on what you really want from your coding system. Once all this is defined, an algorithm will emerge naturally from your requirements.

Post a comment

comment list (0)

  1. No comments so far