Skip to content

Instantly share code, notes, and snippets.

@codepo8
Last active November 8, 2023 13:01
Show Gist options
  • Save codepo8/84248aea816544c8e730c8dffb975c0e to your computer and use it in GitHub Desktop.
Save codepo8/84248aea816544c8e730c8dffb975c0e to your computer and use it in GitHub Desktop.
Code100 Puzzle: Code Block

Puzzle: Event Block

The challenge here is to turn this JSON object:

{
    "columns": 80,
    "padChar": "·",
    "events": [
        { "name": "CODE100", "location": "Zagreb, Croatia", "date": "29.11.2023" },
        { "name": "LIVE", "date": "ongoing" },
        { "name": "Coffee With Developers", "location": "various", "date": "ongoing"} ,
        { "name": "World Congress","location": "Berlin, Germany", "date":"17-19.07.2024" }
    ]
}

Into a block like this:

································································
· CODE100 ············ Zagreb, Croatia ··········· 29.11.2023 ·
· LIVE ··············································· ongoing ·
· Coffee With Developers ·· various ·················· ongoing ·
· World Congress ······ Berlin, Germany ········ 17-19.07.2024 ·
································································

The rules are that the location needs to be centered in the 80 columns wide block, the name on the left and the date on the right. Each need to have spaces surrounding them. (and no, this demo isn’t the right amount of chars).

Happy coding!

Explain or link to your solutions in the comment section here.

@dk5ax
Copy link

dk5ax commented Oct 26, 2023

Some initial thoughts on this while having breakfast...might not fit all edge cases.....is the whole data set available?
.https://gist.github.com/dk5ax/ca1d80b011a029f361cba3667682d9e8

@codepo8
Copy link
Author

codepo8 commented Oct 26, 2023

This is the whole dataset. This is cool, but misses the padding around the data parts and the upper and downer line

@AlenOblak
Copy link

@riascho
Copy link

riascho commented Oct 26, 2023

@8lall0
Copy link

8lall0 commented Oct 26, 2023

My simple solution in Go: https://gist.github.com/8lall0/80bfde652581cee6cc153dd272f2b7ff
Feedback much appreciated!

@codepo8
Copy link
Author

codepo8 commented Oct 27, 2023

Output looks like it should. Can't comment on Go, as I don't use it though. Anyone?

@codepo8
Copy link
Author

codepo8 commented Oct 27, 2023

@philnash
Copy link

I really don't like counting things and halving them and adding things to make sure things turn out right and then hoping I can explain why I added 1 or 2 to the right place.

Anyway, I got there in the end and it was maybe more fun than I'm letting on: https://gist.github.com/philnash/26dd64fc9896b982392818089e0619f4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment