我提议一种新的编程语言,CPC。
我正在创建一种自己的编程语言,用于理解和解决谷歌的 LeetCode 问题。这种语言叫做可编译伪代码,简称 CPC。确实,这个名字故意带有悖论的意味;其目标是创造一种足够严谨的伪代码,能够被编译。灵感最初是在 2023 年的一次谷歌面试后产生的。面试官告诉我:“伪代码很好。”老实说,当时我脑海中想着的是用 Python 实现的图的深度优先搜索来检测循环,所以我并没有认真追求伪代码。这是一个错误,因为这使得与面试官的对话中断了,导致我失分。因此,我提出了 CPC。
其目的在于谷歌的面试官不仅能理解你的解决方案,还能看到你在算法思维方面的流利程度。
这个想法很简单。所有的东西都是一个列表。在 CPC 中,列表的定义使得即使是一个天才儿童也能轻松理解:列表是一个按顺序排列的项目集合,每个项目都有一个位置。
将 LeetCode 中出现的所有数据结构抽象为它们在列表中的最常见形式。换句话说,哈希表就是一个列表,其中每个项目都有一个名称和一个值。对每种数据结构都重复这个过程,以便在 CPC 中尽量减少行话。
然后,CPC 的语法就是用简单的英语描述伪代码。代码支持“摇摆”。换句话说,你可以用简单的英语以多种方式描述一个解决方案。
有什么想法吗?如果这里有支持者,我提议我们作为一个社区继续推导出针对流行 LeetCode 问题的 CPC 解决方案。一旦我们解决了 500 个问题,就可以将 CPC 发布为一种官方的可编译语言。
查看原文
I'm starting my own programming language for understanding and solving leetcode problems at Google. It is called compilable pseudocode, or CPC. True, the name is intentionally paradoxical; the goal is pseudocode rigorous enough to compile. The inspiration first came to me some time after a Google interview in 2023. The interviewer told me, "pseudocode is fine." Honestly, I had depth first search on a graph to detect cycles in Python on my mind, so I did not seriously pursue pseudocode. That was a mistake, because it shut down conversation with the interviewer, and cost me points. Hence, I propose CPC.<p>The purpose is that Google interviewers will not only comprehend your solution, they will see you are fluent in algorithmic thinking.<p>The idea is simple. Everything is a list. In CPC, a list is defined so that a child - albeit a prodigy - could easily understand: a list is a collection of items, in order, where each item has a position.<p>Take all the data structures that appear in leetcode, and abstract them away to their most common denominators in terms of lists. In other words, a hash table is a list where each item has a name and a value. Repeat this for every data structure so that there is as little jargon as possible in CPC.<p>Then the syntax for CPC is just the plain english describing the pseudocode. The code supports “wobble”. In other words, you can use plain english to describe a solution in more than one way.<p>Any thoughts? If there are supporters here, I propose we as a community proceed to derive CPC solutions to popular leetcode problems. Once we hit the 500 problem mark, we can publish CPC as an official compilable language.