Any one doing Advent of Code 2023 & suggestions of a python handy book

New Topic
This topic has been archived, and won't accept reply postings.
 Philip 11 Dec 2023

Each year I try to do Advent of Code ( https://adventofcode.com/ ) partly to keep my coding skills in use and partly because I try to enthuse my son (and probably now my daughter too) to try some.

I'm a bit late starting 2023 and I've knocked off the first 2 days pretty easily - day 1 with some horrible code. I spend too long having to remind myself of the built in functions (like how to use re.search or to convert and array of str to int). Any suggestions for a good python bible to check this stuff.

Secondly, I moved to Python from Fortran. I've also used perl for data processing, and years ago QB, VB, C & pascal. I thought it might be fun to try and learn something new. I have no interest in learning javascript, C++ or assembly. But what else might be fun - particularly if I'm learning it to teach young people later.

 lowersharpnose 11 Dec 2023
In reply to Philip:

Post the code here.  You will get comment.

I used Codewars.  Tasks of different grades.  After you have completed a task, you can view the ranked solutions of others.  There are other platforms.

 elsewhere 11 Dec 2023
In reply to Philip:

Long ago Guido van Rossum's book was good, I think it's the tutorial in the documentation.

https://docs.python.org/3/tutorial/

 mondite 11 Dec 2023
In reply to Philip:

>  But what else might be fun - particularly if I'm learning it to teach young people later.

Wouldnt be great for advent of code since not a bible but may well enthuse the young people are some of no starchs python books.

Got at least one book aimed at kids specifically and then several "project" books which teach various parts of python with (semi) useful mini projects. Ones like "automate the boring stuff with python" and then several others getting more advanced.

OP Philip 11 Dec 2023
In reply to lowersharpnose:

I'm not interested in critique of my code. My Day2 was much neater though 😁

I'll progress on my own. Pointers for a good ref book (rather than stack overflow) would be useful.

OP Philip 11 Dec 2023
In reply to mondite:

> Got at least one book aimed at kids specifically and then several "project" books which teach various parts of python with (semi) useful mini projects. Ones like "automate the boring stuff with python" and then several others getting more advanced.

My son has a python for kids book. It's not that part, it's having a handing reference to look up syntax, etc. last time I had such was some huge tome for VB 2.0

 lowersharpnose 11 Dec 2023
In reply to Philip:

Look at this guy's recommendations:

youtube.com/watch?v=ubV-8EYzTyc&

 Ramblin dave 11 Dec 2023
In reply to Philip:

For a reference, and assuming based on your background that you don't need a hand-holding "this is a loop, this is a variable" sort of introduction, the main documentation site is pretty good:
https://docs.python.org/3/library/index.html

For working out where in the docs to look, I've been learning a bit of Haskell recently and I've actually found that Bing's chat feature is quite good for pointing you to (and summarizing) the relevant bit of documentation based on a hand-wavey description of what you're trying to achieve.

Post edited at 22:12
 wintertree 11 Dec 2023
In reply to Philip:

> last time I had such was some huge tome for VB 2.0

I remember devouring the manuals for VB 3.0 from cover to cover in a few days. The era of manuals like that is gone.  Good luck finding a GUI builder that works as well as the early VB era too, all way over complicated now.

Modern languages lack the immediacy and simple graphics mods that children of the 80s like me grew up with and found so rewarding.

You might have a look at books like “Making Games with Python & Pygame”; if you use Python as a glue to tie a games library, level designs and assets (sounds/graphics) together you can get some of the immediacy back.

 Ramblin dave 11 Dec 2023
In reply to Philip:

> Secondly, I moved to Python from Fortran. I've also used perl for data processing, and years ago QB, VB, C & pascal. I thought it might be fun to try and learn something new. I have no interest in learning javascript, C++ or assembly. But what else might be fun - particularly if I'm learning it to teach young people later.

Maybe Clojure? It's a predominantly functional language but dynamically typed and fairly user-friendly and doesn't expect you to use monads to do IO. Interesting if you want a very different way of looking at programming (immutable data, iteration rather than loops) but also don't want to have to work out what a monad is.

Maybe Rust? It's sort of like C in terms of performance and intended purpose, but with a really expressive type system that does smart things for memory safety and safe concurrency. Maybe not so good for teaching kids, though, it gets a bit galaxy-brain at times.

Maybe Go? It's good for fast, scalable stuff but also (apparently) relatively easy to learn. 

And to be honest, Javascript (or specifically a modern js framework) does seem like an annoyingly useful thing to know in the modern world. The browser is now where most UIs live, and JS is how most people seem to build nontrivial UIs in the browser. I guess you could try a hipster alternative like Dart or Elm or Typescript or something?

OP Philip 11 Dec 2023
In reply to wintertree:

In 1985 only had Toshiba's MSX with basic. A gui was a luxury I didn't get until C64, and then not truly until my first windows machine. Then 1998 I swapped to Linux, and the only graphics were piping stuff to gnuplot from perl.

I'm not too bothered about gui, there are plenty of kids graphical stuff with turtle and scratch. I want something that covers array manipulation, regex, probably numpy.

In reply to Philip:

Get a perl golf tournament going. 

 CameronDuff14 12 Dec 2023
In reply to Philip:

The w3 schools pages are really good, covers most of the basics (and some of the less basics) and has interactive code snippets build in to examples. 

https://www.w3schools.com/python/default.asp

 gravy 12 Dec 2023
In reply to Philip:

Python from Fortran - wow - that's like "Go to jail, do not pass go and do not collect £200".  No one programs in python, they just copy code from the internet or use CharGPT to get it wrong for them (seriously).

If you want something interesting try Haskall (or something else purely functional) - it's not really all that useful except changing the way you think.

You could also attempt to become fluent in a code golf language - that would waste a lot of your time fruitlessly as well.

Post edited at 09:01
5
 remus Global Crag Moderator 12 Dec 2023
In reply to Philip:

> I'm a bit late starting 2023 and I've knocked off the first 2 days pretty easily - day 1 with some horrible code. I spend too long having to remind myself of the built in functions (like how to use re.search or to convert and array of str to int). Any suggestions for a good python bible to check this stuff.

ChatGPT is great for these kinds of questions (regardless of what gravy thinks 😉) See below for an example answer to your question.


 remus Global Crag Moderator 12 Dec 2023
In reply to gravy:

> Python from Fortran - wow - that's like "Go to jail, do not pass go and do not collect £200".  No one programs in python, they just copy code from the internet or use CharGPT to get it wrong for them (seriously).

> If you want something interesting try Haskall (or something else purely functional) - it's not really all that useful except changing the way you think.

> You could also attempt to become fluent in a code golf language - that would waste a lot of your time fruitlessly as well.

Personally I don't think this kind of attitude is very helpful. Maybe OP just wants to refresh their programming skills a little and get a few mini-projects done. Something like haskell that challenges how you think about programming is definitely cool, but it's not for everyone and would put a lot of people off programming altogether if that was the only language they had access to.

 midgen 12 Dec 2023
In reply to remus:

Yes Python is pretty ideal for a basic introduction to programming. I'm not a fan personally, but I'm a C++ programmer so used to more low-level languages and all the nonsense that comes with it :P

ChatGPT is incredibly useful for programming. Saves me a bucket load of time doing boilerplate and is great at providing maths code that I'd otherwise have to trawl reference books for and translate into code.

 wintertree 12 Dec 2023
In reply to gravy:

> No one programs in python, they just copy code from the internet or use CharGPT to get it wrong for them (seriously).

Scene: A dark, dingy office.  Camera pans to Wintertree looking at the status dashboard of his code base (99.5% Python, written pre chat-GPT), headline figure in a 1980s magnetic style font “Data processing rate: 102.4 GB/s.”

 

Post edited at 10:08
OP Philip 12 Dec 2023
In reply to wintertree:

> > No one programs in python, they just copy code from the internet or use CharGPT to get it wrong for them (seriously).

> Scene: A dark, dingy office.  Camera pans to Wintertree looking at the status dashboard of his code base (99.5% Python, written pre chat-GPT), headline figure in a 1980s magnetic style font “Data processing rate: 102.4 GB/s.”

>  

Must be an age thing with that user. I'm not sure how ChatGPT was going to help me in 2006 to port Fortran 66 to something I could update and compile on my Fedora laptop.

I'm quite fond of Python. Granted computer power now exceeds my requirement for optimization - I do remember when running least squares optimization in 200 dimensions required leaving the machine for a few hours, but timed correctly that could be evening beers.

 Ramblin dave 12 Dec 2023
In reply to Philip:

> I'm quite fond of Python. Granted computer power now exceeds my requirement for optimization - I do remember when running least squares optimization in 200 dimensions required leaving the machine for a few hours, but timed correctly that could be evening beers.

Yeah, Python's a really good language for actually getting normal, human-level stuff done. Read some files, twiddle some strings, call an API, bish-bash-bosh you're done. Turning your nose up at it because it doesn't give you enough opportunities to show how good you are at avoiding segfaults or memory leaks would seem churlish.

I've not tried it, but Julia seems like an interesting high-level language for doing heavy numerical stuff if you ever want to step outside of Numpy...

 kathrync 12 Dec 2023
In reply to Philip:

I'm not doing Advent of Code, but I am marking programming coursework from 40 students so I guess that counts...?

As a general all-rounder and for enthusing kids Python is pretty good. I like it because:

  • It's quite easy to pick up
  • Massive user base = lots of help online and lots of libraries/APIs
  • Allows you to play around with different paradigms without switching languages
  • A lot of kid's programmable toys as well as Arduino and similar have Python APIs

I know it's not the fastest, and it's definitely a jack-of-all-trades, master-of-none type language, but for a hobbyist or beginner I don't think you can beat the accessibility.

It's honestly been years since I last bought a Python reference book. The online documentation is so accessible, I just use that now: https://docs.python.org/ 

If you want to try something different, I've been enjoying Julia (up and coming in my field for machine learning/AI applications) and Rust (tried it just because it sounded interesting) recently. I've also been playing with TypeScript, which I enjoy less - but as a long-time loather of JavaScript I quite like it because it behaves more predictably.

 wercat 12 Dec 2023
In reply to wintertree:

you're beginning to make me want to blow the dust off my Rockwell Aim-65

 wintertree 12 Dec 2023
In reply to Philip:

I was an Amstrad CPC-464 not an MSX but they were quite similar machines I think.

If you’re looking to build your numpy experience have you considered implementing some cellular automata like Conway’s Game of Life or Wireworld?  Start with some “for” loops and time the execution of a generation, then figure out how to move more of the computation to numpy and plot the speed ups.  You’ll learn plenty along the way.  Then you can look in to how “hashlife” works…

Post edited at 19:00
 wercat 13 Dec 2023
In reply to wintertree:

This is what happens when a lad is brought up on an old Acorn Electron/BBC in the modern era. (He did write the training programme and visuals showing the learning happening in BBC Basic for Windows running on a modern machine)

https://www.reddit.com/r/vintagecomputing/comments/15ph7pt/not_sure_if_this...

 kathrync 13 Dec 2023
In reply to wintertree:

> I was an Amstrad CPC-464 

My first experiences were with a slightly later model Amstrad - the CPC 6128, with a whole 128Kb RAM! Good times!

Also, the reason why, to this day, I leave large amounts of white space between blocks of code. Annoying GOTO linenumber syntax!

> If you’re looking to build your numpy experience have you considered implementing some cellular automata like Conway’s Game of Life or Wireworld? 

Conway's Game of Life is fun - I did this in Python with my students as a fun "last lab of the semester" activity.

 wercat 13 Dec 2023
In reply to kathrync:

wow! 128 kilobytes!

a bit more than I had:

https://t-lcarchive.org/tangerine-microtan-65/

it could manage a game of life within the 1k though (the screen took up 512 bytes leaving the rest split between the hardware stack, monitor program and the user

I think the life cells were stored for display and processed as data in the screen RAM (so long as you did not do anything to scroll the screen contents which destroyed its meaning as data)

Post edited at 13:08
In reply to wercat:

You were lucky! University mainframe computers in the late 60s were 64 k, and 128 k by the early 70s. Around 1982, I bought a Sharp pocket computer, which had 2 kb of memory, and in 1985 an HP-110, which had 272 k and ran at astonishing 5 MHz. After that, it was the first generation PCs...

 wercat 13 Dec 2023
In reply to John Stainforth:

Lucky - with 1024 bytes? and .75Mhz clock?

Plus needed to solder it together!  Happy days ...

When I got the expansion board with another 7k of memory I didn't know how I'd ever fill it!

Post edited at 13:53
 Petrafied 14 Dec 2023
In reply to wintertree:

> I remember devouring the manuals for VB 3.0 from cover to cover in a few days. The era of manuals like that is gone.  Good luck finding a GUI builder that works as well as the early VB era too, all way over complicated now.

Oh I don't know.  We used to use X11/Motif for real user interfaces back then (and pre-VB).  Extremely powerful, especially for producing GUIs able to resize properly across different workstation architectures and screen sizes.  However, the framework was way more complicated than things like tkinter (which people, inexplicably, seem to struggle with).  Must admit, I always found VB to be a bit of an abomination.

 Petrafied 14 Dec 2023
In reply to Philip:

> Secondly, I moved to Python from Fortran. I've also used perl for data processing, and years ago QB, VB, C & pascal. I thought it might be fun to try and learn something new. I have no interest in learning javascript, C++ or assembly. But what else might be fun - particularly if I'm learning it to teach young people later.

I know you say you've no interest in learning assembler, but I'd really recommend it.  I know that for almost all applications (other than certain embedded systems (which is where I've where I've used it)) it's a bit pointless, but as a learning exercise and to form an understanding of what's actually happening underneath the "hood" of the computer it is quite useful.  It's also oddly satisfying, a bit like catching your own food rather than nipping down to Tesco's.  A great way to help teach the fundamentals of computing is to get students to design a simple high level programming language and for them also develop an interpreter or compiler than generates executable assembler.

I do wonder if the success of LLMs will make programming totally obsolescent in the next few years.  Whilst ChatGPT can churn out garbage at times, it can also churn out quite amazing stuff.  It all depends on how much the training data reflects what you want to do.  For example, libraries like mathplotlib have been around for a while with lots of resources for it on the internet and I've had ChatGPT produce pretty sophisticated software based on it.  On the other hand, I'm currently using a simple GUI framework called pysimplegui for rapid prototyping for which there's less useful internet information.   For this ChatGPT does a fair bit of hallucinating and is far less useful.  I'd expect it to improve dramatically with time.

​​​​Will these things make programmers mostly redundant in the short/medium term, or simply mean they can get more done so expanding the range of possible applications?  I can see it going either way.  If I was starting out (or eve mid-career) I'd be nervous.

​​​​​​


New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...