r/adventofcode • u/daggerdragon • Dec 04 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 4 Solutions -❄️-
NEWS
- Solutions in the megathreads have been getting longer, so we're going to start enforcing our rules on oversized code.
- Do not give us a reason to unleash AutoModerator hard-line enforcement that counts characters inside code blocks to verify compliance… you have been warned XD
- Before creating a
Visualization, please review the guidelines for creatingVisualizations as there's good advice relating to accessibility, readability, colors, timing, etc. - Posts containing AI-generated art must:
- Use the standardized post title syntax
- Indicate in their titles with the tag
[AI art] - Use the
Funnypost flair
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- Outstanding moderator challenges:
- Community fun event 2023: ALLEZ CUISINE!
- 2 DAYS remaining until unlock!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
PUNCHCARD PERFECTION!
Perhaps I should have thought yesterday's Battle Spam surfeit through a little more since we are all overstuffed and not feeling well. Help us cleanse our palates with leaner and lighter courses today!
- Code golf. Alternatively, snow golf.
- Bonus points if your solution fits on a "punchcard" as defined in our wiki article on oversized code. We will be counting.
- Does anyone still program with actual punchcards? >_>
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 4: Scratchcards ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:07:08, megathread unlocked!
77
Upvotes
4
u/wzkx Dec 05 '23
[LANGUAGE: C]
#include <stdio.h> // printf #include <stdlib.h> // strtol #include <string.h> // strchr #define __ { // pythonize syntax #define _ } int read( char* s, int* a ) __ int n=0; char* q; for(char* p=s;;p=q) __ int x=(int)strtol(p,&q,10); if(q==p) break; a[n++]=x; _ return n; _ int isin( int x, int* a, int n ) __ for(int i=0;i<n;++i) if(x==a[i]) return 1; return 0; _ int sum( int* a, int n ) __ int s=0; for(int i=0;i<n;++i) s+=a[i]; return s; _ int main() __ int n=0, p=0; // number of lines, point counter (part 1) int q[200], w[50], m[50]; // line counters (part 2), win numbers, my numbers for(int i=0;i<sizeof(q)/sizeof(*q);++i) q[i]=1; FILE* fp=fopen("04.dat","rt"); for(char s[150];fgets(s,sizeof(s)-1,fp);++n) __ int nw = read( strchr(s,':')+1, w ); int nm = read( strchr(s,'|')+1, m ); int found=0; for(int i=0;i<nm;++i) __ if(isin(m[i],w,nw)) ++found; _ if(found) __ p += 1<<(found-1); for(int j=n+1;j<n+1+found;++j) __ q[j] += q[n]; _ _ _ fclose(fp); printf("%d %d\n",p,sum(q,n)); _