Not immediately clear what this means or if it is good or bad or something else.
The Languages of English, Math, and Programming
41–49 of 49 posts
Re: The Languages of English, Math, and Programming
#42What about o1? I think the world is sleeping on o1. Recently I misread a leetcode/neetcode problem (so I was curious that my version of the problem with an extra constraint could be solved in a different way). And 4o hallucinated incorrectly and double downed when asked follow up questions - but o1 solved it the first time what seemed like easily. It really is a major step forward.
So... Can you enlighten us how it went?
import itertools
def factors(n):
result = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
result.add(i)
result.add(n // i)
return sorted(result)
def main():
n = 108
factors_list = factors(n)
triplets = []
for a_idx in range(len(factors_list) - 2):
a = factors_list[a_idx]
for b_idx in range(a_idx + 1, len(factors_list) - 1):
b = factors_list[b_idx]
for c_idx in range(b_idx + 1, len(factors_list)):
c = factors_list[c_idx]
if a * b * c == n and a
Run: -▶ python a.py
All ways in which three distinct positive integers have a product of 108:
(1, 2, 54)
(1, 3, 36)
(1, 4, 27)
(1, 6, 18)
(1, 9, 12)
(2, 3, 18)
(2, 6, 9)
(3, 4, 9)
Too smart for its own good, maybe? Still, apparently correct on the first try.There's an import for `itertools` which isn't used, just as noted in the article for 4o.
Can someone who knows what it's about say how optimal this version is, compared to other answers?
Re: The Languages of English, Math, and Programming
#43Earlier quoted context omitted.
So... Can you enlighten us how it went?
After 34 seconds: import itertools def factors(n): result = set() for i in range(1, int(n**0.5) + 1): if n % i == 0: result.add(i) result.add(n // i) return sorted(result) def main(): n = 108 factors_list = factors(n) triplets = [] for a_idx in range(len(factors_list) - 2): a = factors_list[a_idx] for b_idx in range(a_idx + 1, len(factors_list) - 1): b = factors_list[b_idx] for c_idx in range(b_idx + 1, len(factors_l…
Algorithmically it is optimal, many corner cases thought of to make as few loops as possible.
But it is suboptimal in the sense that it uses for loops so it is not possible for an underlying engine to execute in parallel, or to optimize the looping in native (e.g. C) code.
In short - the for loops are 'how'. Without loops it is much more 'what' which leaves it up to the computer to optimize
Re: The Languages of English, Math, and Programming
#44Earlier quoted context omitted.
After 34 seconds: import itertools def factors(n): result = set() for i in range(1, int(n**0.5) + 1): if n % i == 0: result.add(i) result.add(n // i) return sorted(result) def main(): n = 108 factors_list = factors(n) triplets = [] for a_idx in range(len(factors_list) - 2): a = factors_list[a_idx] for b_idx in range(a_idx + 1, len(factors_list) - 1): b = factors_list[b_idx] for c_idx in range(b_idx + 1, len(factors_l…
My 5c. Algorithmically it is optimal, many corner cases thought of to make as few loops as possible. But it is suboptimal in the sense that it uses for loops so it is not possible for an underlying engine to execute in parallel, or to optimize the looping in native (e.g. C) code. In short - the for loops are 'how'. Without loops it is much more 'what' which leaves it up to the computer to optimize
Looking at https://news.ycombinator.com/item?id=41897526 caused me to try asking for a solution in a language that doesn't have `for` loops. Since SQL was taken, I tried Prolog:
% Define a predicate to find all positive divisors of N
divisors(N, Divisors) :-
findall(D, (between(1, N, D), N mod D =:= 0), Divisors).
% Define a predicate to generate all combinations of three distinct elements from a list
combination3(List, X, Y, Z) :-
select(X, List, Rest1),
select(Y, Rest1, Rest2),
select(Z, Rest2, _),
X
Run: ?- [a]. list_triplets(108).
[(1,2,54),(1,3,36),(1,4,27),(1,6,18),(1,9,12),(2,3,18),(2,6,9),(3,4,9)]
I'm in love. I both understand what is happening (I think I would understand it even if I didn't know the task description!) and could easily port optimizations from the previous solution.Maybe this is the point when being a polyglot developer - knowing tens of programming languages and their characteristics - will finally start paying off.
Re: The Languages of English, Math, and Programming
#45It's worth noting that math and programming do not appear to be considered "languages" by much of the academic and/or neuroscientific literature; see [0] on the front page right now and my comments regarding the same [1]. [0] https://news.ycombinator.com/item?id=41868884 [1] https://news.ycombinator.com/item?id=41892701
Huh, interesting. Programming languages were devised with Chomsky’s foundational theory of formal languages in mind, and they’re one of the few actual implementations of it. I read your comment and it seems your main thrust is that arithmetic activity lights up different brain regions than communicative activity, which I don’t personally see as a compelling basis for a definition of the word “language”. Of course, th…
I don't think that this is actually true at all (and modern neuroscience, sociolinguistics, etc. disagree pretty heavily with Chomsky), but it is impressive how far you can get with modelling natural language grammar with formal methods.
Re: The Languages of English, Math, and Programming
#46Earlier quoted context omitted.
I've recommended his book PAIP despite the AI in the title because you can take it as about the craft of programming (I mean things like style and efficiency, not the bare beginning of being able to code at all) -- using old-fashioned AI as the subject matter. To learn better coding you gotta code something. https://github.com/norvig/paip-lisp
Yes, this book is an incredible gem. Hard to believe that one human wrote it. I've been attempting to mine its secrets for a long time. Sometimes it makes me a little embarassed that I've probably spent more time trying to understand it than he spent researching/writing it but I am appreciative that it exists. But it's especially great if you want to appreciate PN's code more. He actually offers explanations of choic…
Speculating: the sheer bulk of the book might also push people away. It's usually an anti-signal for riches within.
Re: The Languages of English, Math, and Programming
#47>> Only 2 of the 9 LLMs solved the "list all ways" prompt, but 7 out of 9 solved the "write a program" prompt. The language that a problem-solver uses matters! Sometimes a natural language such as English is a good choice, sometimes you need the language of mathematical equations, or chemical equations, or musical notation, and sometimes a programming language is best. Written language is an amazing invention that ha…
Re: The Languages of English, Math, and Programming
#48What about o1? I think the world is sleeping on o1. Recently I misread a leetcode/neetcode problem (so I was curious that my version of the problem with an extra constraint could be solved in a different way). And 4o hallucinated incorrectly and double downed when asked follow up questions - but o1 solved it the first time what seemed like easily. It really is a major step forward.
So... Can you enlighten us how it went?
Note the added section compared to the leetcode question (https://leetcode.com/problems/two-sum-ii-input-array-is-sort...) is "And note also that index1 + 1 == index2."
If you enter that into 4o it'll just keep repeating leetcode 167 answers and insist binary search has nothing to do with it.
tangent: o1-preview isn't going to invent things quite yet (i tried to get it to come up with something original in https://chatgpt.com/share/6715f3fe-cfb8-8001-8c7c-10e970c7d3... via curiosity after watching https://www.youtube.com/watch?v=1_gJp2uAjO0). but it can sort of reason about things that are more well-established.
Re: The Languages of English, Math, and Programming
#49Earlier quoted context omitted.
So... Can you enlighten us how it went?
https://chatgpt.com/share/671604db-7ff0-8001-840e-960abfed0b... Note the added section compared to the leetcode question ( https://leetcode.com/problems/two-sum-ii-input-array-is-sort... ) is "And note also that index1 + 1 == index2." If you enter that into 4o it'll just keep repeating leetcode 167 answers and insist binary search has nothing to do with it. tangent: o1-preview isn't going to invent things quite yet (…