As a winner of the last programmer contest at Schindler MIL, I had to devise a new compelling and intriguing puzzle to propose to my colleagues. The first two puzzles were in the form “Implement X without using Y“, an interesting pattern that allowed for multiple solutions.
But I ran short of (X,Y) pairs, and staring at my blank page I decided to resort to … ChatGPT. Yes, nowadays it is like the uber-solution to everything. Don’t you know how to partially specialize your templates? Ask ChatGPT; don’t you know how to present a topic? Ask ChatGPT; don’t you know how much a brick weighs? Ask ChatGPT; don’t you know how to devise a programming puzzle? Ask ChatGPT.
So I went on and asked this modern oracle –
me | Can you write a function that computes the least of two numbers without using the “if” statement? |
Cgpt | Certainly! Here is a function that computes the minimum of two numbers without using the if statement:def min imu m(a, b): return a if a < b else b This function takes in two arguments, a and b , and returns the minimum of the two values using a ternary expression. The ternary expression a if a < b else b returns a if a is less than b , and returns b if a is greater than or equal to b . This allows us to determine the minimum of the two values without using the if statement.Alternatively, you could use the following function, which uses the built-in min function to compute the minimum of the two values:
This function also takes in two arguments, a and b , and returns the minimum of the two values by calling the built-in min function with a and b as arguments. The min function returns the minimum of the two values, so this allows us to determine the minimum of the two values without using the if statement.I hope these examples are helpful! Let me know if you have any questions. |
Maybe because I’m not a native English speaker, I found it easier to get to the point in a few iterations rather than straight to the point. So the previous question was just a warm-up. ChatGPT scored only partially well on my question since they (not sure what is the proper pronoun) used the functional if expression. Which still is an if, even if not an if statement. Time to get more to the point –
me | Given my previous requests, could you invent a similar programming problem? |
Cgpt | Certainly! Here is a programming problem that is similar to the previous ones: Write a function maximum(a, b) that returns the maximum of two numbers a and b without using the if statement or the max function.To solve this problem, you will need to find a way to determine the maximum of a and b without using the if statement or the max function. You can use any other language constructs or built-in functions that you like, as long as you do not use the if statement or the max function.For example, the function maximum(2, 3) should return 3 , and the function maximum(5, 5) should return 5 .I hope this programming problem is challenging and interesting for you! Let me know if you have any questions or if you need further clarification. |
ChatGPT is always overly enthusiastic in their replies, and overly willing to please the human. But the proposed solution is way too similar to mine. So I asked for something else
me | This is very similar to my last question, could you invent something different using the template “write function X without using construct Y” ? |
Cgpt | Certainly! Here is a different programming problem that follows the template “write function X without using construct Y “:Write a function unique(lst) that returns a list containing only the unique elements of the input list lst , without using the set type or the in operator.The input list lst will contain only integers and will have at most length 100. The output list should contain the unique elements of lst in the same order as they appear in lst , without any duplicates.For example, the function unique([1, 2, 3, 2, 1]) should return [1, 2, 3] , and the function unique([1, 2, 3, 4, 5]) should return [1, 2, 3, 4, 5] .I hope this programming problem is challenging and interesting for you! Let me know if you have any questions or if you need further clarification. |
Every time a question about programming is asked, ChatGPT uses python to solve it. It is a bit of a bias. The riddle is nice, can be worked on, time to thank… always thank our next overlord.
me | very interesting. Thank you |
Cgpt | You’re welcome! I’m glad that you found the problem interesting. If you have any further questions or if you need any additional help, don’t hesitate to ask. I’m always here to help. |
Thinking about the proposed problem I got more and more convinced that not that many solutions were possible. So I decided to spin the wheel another time –
me | Could you invent another problem with the same pattern as the previous one, but that allows for many different solutions? |
Cgpt | Sure! Here’s another programming problem that follows the same pattern as the previous one, but allows for many different solutions: Write a function without_vowels(string) that removes all vowels (a, e, i, o, u) from the input string string without using any form of loop, conditional statements or list comprehension.The input string string will contain only lowercase alphabets and have at most length of 100.For example the function without_vowels("hello world") should return “hll wrld” and without_vowels("aeiou") should return an empty string.This problem can be solved in many different ways, one of which could be through the use of built-in string functions, or with the use of regular expressions, or even with a clever use of string slicing, etc. Let me know if you have any questions, or if you need any further information. |
This time ChatGPT convinced me, and now I needed a good story to present the riddle.
me | Imagine a world where people travel only with elevators. These elevators can move vertically, but also horizontally and reach everywhere. Consider the last problem you propose and invent a background story to justify the need to solve your problem with the given constraint. You may modify the text of the problem as long as it keeps the same structure. |
Cgpt | In a world where transportation is done exclusively by elevators, the government of this society decided to regulate the language that people can speak inside the elevators. This is because, many times, people would speak different languages, and in this multilingual society, it created confusion and made communication difficult. In order to solve this problem, they decided that the only language allowed inside elevators is the language without vowels. As a result, the elevator companies had to adapt their system to automatically remove vowels from any message displayed on the elevators’ screens. The function without_vowels(string) that you must implement is a vital component of this new system. It must remove all vowels from the input string string that is displayed on the elevator’s screen without using any form of loops, conditional statements or list comprehension, as a way to ensure that the system is not easily hackable.The input string string will contain only lowercase alphabets and have at most length of 100 characters. Your task is to implement this function so that the elevator companies can install it into their systems, and help the government to make sure the society can communicate effectively in elevators.For example the function without_vowels("Hello World") should return “Hll Wrld” and without_vowels("aeiou") should return an empty string. |
Interesting setting. A bit naive, it reminds me of people that try to make them being understood by foreigners by speaking slowly. Nonetheless sets a good mood and a glimpse of a better world where people try to speak and understand each other.
Time to push this a bit further –
me | can you compose a music theme for this challenge? |
Cpgt | As an AI, I do not have the ability to compose music, but I can certainly describe a possible music theme for this challenge. The music theme for this challenge could be a repetitive and minimalist piece that emphasizes the absence of vowels. The theme could start with a simple melody played on a percussion instrument, such as a marimba or xylophone. The melody could consist of short, staccato notes that are played in a rhythmic pattern. As the piece progresses, additional instruments could be added, such as a piano or a synth, playing similar melodies, but in a slightly different rhythm. The melody could be made more complex by adding in slight variations and syncopations. The overall theme of the music should give the feeling of restriction, yet also the sense of order and clarity that the new communication system aims to achieve. The music should build tension, giving a sense of mystery and uncertainty, until it reaches a climax where the melody is played in full, this time including all the vowels but with a slight distortion giving a feeling of rebellion. The piece could end with the return of the original, vowel-less melody, leaving the listener with a sense of longing and resolution. Overall, the music should convey the idea of a society striving for effective communication through restriction, with a hint of rebellion and desire for something more. |
I’m pretty lacking in the musical area (my idea of good music is 80s euro-dance :-D), so this may be just the equivalent of technobabble. But it is extremely believable. So, after solving the programming challenge, is anyone willing to try to compose the piece?
I leave you some time for both, and in the next post, I’ll present the submitted solutions. Feel free to send your own.