These are public posts tagged with #toyprogrammingchallenge. You can interact with them if you have an account anywhere in the fediverse.
AdventOfCode is coming midnight est tonight
#toyprogrammingchallenge #adventofcode #adventofcode #adventofcode2022
Okay, here is the challenge for this week.
Tennis is a cool sport to watch. Especially, if either Serena or Venus or both are playing. :) However, the scoring is really odd, because it is based on the clock face. To make it even more fun, it did come from France, so instead of Zero we refer to l'œuf or "the egg". However, as we now pronounce it , it is "love". I am certain that there can be some interesting jokes in there, but I am not going for any of them. :)
Anyway, when you begin a game both players have scored zero times so their score is said to be "love - love" or "love all". When a player has scored 1 time, they are said to have "15" as advancing around the clock face 1/4 of the way. Their second score would be called "30" since that would be 1/2 way around. Obviously, their third score should be "40" because that forces you to win by 2 :) Not sure it makes sense, but that is how it works. So as an example a game might go like this:
love - love
15 - love
30 - love
40 - love
Game - player1
Not all games work out that one player gets to run the score, so it could also go like this:
love - love
15 - love
15 - 15
15 - 30
30 - 30
30 - 40
Game - player2
However, after the 3rd point is scored if both players have 40 the score is said as
"Deuce"
Because, France. :)
At any point when a player becomes 2 points ahead after 40 they win, and we say Game - <player name>
But after the score is tied at 40 or higher, the next point is called "advantage" so we no longer care about the underlying clock face scores, and merely go through "Deuce", "Advantage - player1" "Deuce" "Advantage - player2" "Game - player2". In theory, one could continually bounce from "Deuce" to advantage one player or the other until one of them players simply falls out or dies. Though I am not aware of that ever actually happening. There have been some pretty long games.
"Back in 1975 on May 26, at the Surrey Grass Court Championships at Surbiton, Anthony Fawcett and Keith Glass racked up a record 37 deuces in a single game for a grand total of 80 points."
But I digress. Here is your challenge if you choose to accept it.
Write a method/function that takes any legal tennis game score, such as (0, 0) or (5,3) and so on, and have it output the traditional tennis score as described above, "love - love" or "Game - player1" in my example of legal scores. Keep in mind, (12, 2) is not a legal score, as once the first player achieved 4 he would have already won. You don't need to test for this, but be aware it is not a scenario you should have to deal with. You can represent any tie up to 2 simply as 'love - love' or '15 - 15' or '30 - 30' but starting at 3 you would not say '40 - 40' but rather "Deuce" at that level and any higher. If you would like to do so, as a bonus you could represent the simple ties less than 3:3 (Deuce) with the 'all' so 'love all', '15 all', or '30 all' would be a bonus representation, but '40 all' would be incorrect, as it should merely be 'Deuce'.
Use whatever language or methods you like. I am using Java. I will also have unit tests. You are free not to use them, but I am not interested in testing anyone's code for accuracy, so if you don't provide them, the best you can hope for is "Nice job. Good effort. I guess." At least from me :)
Try to focus on good quality code. Also focus on reduction of complexity, DRY, and certainly use subroutines as necessary.
Good Luck!!
I will probably be checking mine in to my GitHub or GitLab repo at some point later in the week.
Here should be a simple one. It was fun to do in Java and with chained calls it turns out to be somewhat of a one-liner. This is not a code-golf thing, but feel free to try it that way if that is your interest.
"Square Odd"
Let's process an integer. The idea is that if the number contains odd digits they need to be converted to their squared value. Even digits are passed through unchanged.
For example, given the number 232, you would output 292. Or in the case of 99, you would output 8181. But if it were 22 then the output would be 22.
If this is too simple and you would like a bit more of a challenge see if you can try a couple bonus situations.
1*. determine if a number is already in this state. For example 232 wouldn't be because 3 is not squared. However, 212 could be, as could 2814 since that could have come from 294.
and
2*. given a number possibly in this state already, decode it back to the original number.
Since 1 squared is 1 and some squares have even digits like 81 such a number could have started out as '9' or actually '81'. So in 1 and 2 you may want to come up with multiple initial beginnings. So given such '81' the answer would be both of those '81' and '9'.
Things in my life have changed. I am now in a much larger focus on Java. I am still a huge fan of TDD and Test First, but I guess that is a religious thing so I will try to contain my zeal.
Initially the challenges were intended as small problems that should be in the 1-3 hour at most. As well, I focused towards Python and the problems I was using to learn the particular concepts I was working on at the time. Since my shift to Java I am less interested in some of the finer concepts and more interested in general issues. So even though I might find a solution that uses a whole pile of chained references interesting, its solution in some other language may not be nearly as interesting to you :)
I will try to be better about posting more often. Unless I find people aren't interested, in which case I won't waste the bandwidth :)
I just boosted the last #toyprogrammingchallenge that I had posted from over a year ago.
I still think this is an interesting problem to solve. I have yet to attack it myself, but am definitely considering it. I have recently been doing a bunch more smaller exercises, and perhaps can post a few of those. Though I haven't necessarily written them, I have found them fun to do.
I do have some ideas, but for now I am waiting to see if anyone is even still interested in the #toyprogrammingchallenge puzzles anyway.
So you terraformed your marses and made yourself these perfectly square flat islands, on which you made bunch of single rover housing stations in a perfectly square NxM grids, and then randomly air dropped bunch of rovers there. Now you need a program to plan a course to get each of them to a place they can call home. Some of you went for the Electric Wheelchair 4.2 model, and others preferred the Atomic Tank 6.6.6.
1. EM 4.2: these are super efficient but have limited fuel, so need to make sure you do not ran out of it on any rover.
2. AT 6.6.6: these have unlimited fuel but wreck the environment, so gotta have them moving as little as possible altogether.
Rovers can't collide thanks to state of the art interdenominational wormhole technology, but it's proprietary and patented so you can't use it for anything other than avoiding collision.
For those who have no or too much imagination:
given an NxM grid and K (<= N*M) random points, both in the same range (say 0 to 1 on each axis), pair the random points to grid vertices minimizing the
1. maximum distance
2. sum of distances
between each pair.
Tried a #toyprogrammingchallenge today, was pretty fun. @namark thanks for recommending these! I expect I'm gonna spend a lot of hours on these in the next few weeks.
Okay, here's one with a story :) Let's see if this is entertaining enough :D
Here is a problem that involves being jerk.
You receive a parking ticket and decide to pay in the least
convient way possible... change. This decision comes to mind
because the tickets are in strange amounts because they use
the cents portion for some kind of internal encoding.
You decide to pay all in pennies but when you start to collect
them someone informs you that although change will be accepted,
if the counts of coins exceed the quantities required for a wrapper
then you must roll them.
US Coinage count to a roll
0.01 = 50
0.05 = 40
0.10 = 50
0.25 = 40
0.50 = 20
$1.00 = 25 (small) or 20 (large)
Question 1.
How many rolls and free coins of each can you provide to pay your
$100.37 ticket in order to use the highest count of unrolled coins?
Considering that a ticket can cost anywhere from $1.00 to $250.00.
You start telling everyone else about your plan and they decide to
play too, so you calculate how they should pay as well.
For example, 45 pennies 21 nickles for a $1.00 ticket might be
pretty obnoxious :).
Question 2. Which fine amount (in that range) would allow you to
provide the highest number of unrolled coins?
Question 3. The parking authority figures out what you are doing
and decides to change things up by hiring you. Your job is to
determine the best fine values to get paid in the least amount of
unrolled coins. What are those amounts what are those amounts (still
within that range of $1.00 to $250.00)
@Lossberg by the way, I do a #toyprogrammingchallenge here, you can look at the origination of it all the way back the 'Ninety-Nine Bottles of Beer" challenge. https://qoto.org/@Absinthe/102805659580967435
Feel free to play at any of them that interest you. There is no timebox on these. Watch for the tag #toyprogrammingchallenge and include it on any answers you offer to any of them.
Okay folks, this should be simple, but maybe not.
The goal is to write a function that takes a positive integer and returns a list of its prime factors. So if you did 12 you should get the list [2, 2, 3]
As neither 1 nor zero are prime, as a result should return an empty list.
This is taken from a #tdd #Kata, so if you have not done this one I encourage you to do so. If you are not into #TDD then solve it however you like.
exploiting intellectuals for my mathematical needs
While pondering about a pointless optimization of a pointless feature of one of my pointless projects, I stumbled upon a #toyprogrammingchallenge similar to this one
https://qoto.org/@Absinthe/103194125533950090
but different.
A couple of ways to put it.
Colloquial(mathy jargon):
Given a prime factorization of a number, generate all of its factors(prime or otherwise) in ascending order.
Down to code(with fumbling):
Given a multiset(in ascending order) of prime numbers, generate all numbers... whose prime factors are subsets of that set... too mathy?... maybe then "that can be obtained by multiplying numbers from that set together"... in ascending order.
Examples:
Input: 30 = (2,3,5)
Output: ([1,]2,3,5,6,10,15[,30])
Input: 60 = (2,2,3,5)
Output: ([1,]2,3,4,5,6,10,12,15,20,30[,60])
@p @yohanandiamond @l0wk3y@freespeechextremist.com I still want to find a good all purpose "Toy" program. I might dig through some of the AdventOfCode stuff this year, as I loved some of his problems. Getting interrupted half way through with my Tahiti trip (poor me :D ) kind of stopped me at day 10 for the time being, but I liked the potential of his IntCode computer and things like that.
Who knows, soon time to get back to coming up with more #toyprogrammingchallenge problems again. Feel free to participate or suggest some as well.
@p @yohanandiamond @l0wk3y@freespeechextremist.com
The first #Toyprogrammingchallenge I put up was for 99 Bottles of Beer. However, I added the twist, that it has to output text only, no numerals. So it was for "Ninety-nine Bottles of Beer".
Feel free to give it a shot at :
As long as I continue working on the #AdventOfCode #AdventOfCode2019 I will not be posting a new #toyprogrammingchallenge
However, I encourage you all to give the #AdventOfCode a try. You don't have to do them all, though I would recommend doing them in order. You can even go back and do them from previous years.
@JJFlash it's a great ride. I have been doing it for all the #toyprogrammingchallenge posts, I am no Eric but I try to find stuff.
@Absinthe how often do you usually post a #toyprogrammingchallenge?
@JJFlash I will have to look into that. As it is, I will soon be 2 weeks behind in the AoC because I am going to Tahiti, and I have been slow coming up with puzzles here for
#Toyprogrammingchallenge as well. So there's that :)
I did not solve both with the first try because I got the first one pretty easy, but when the second one came around, I felt the need to rewrite the InCode machine in a cleaner way and I was not happy separating the direct and relative and "output" ones. I guess I am missing a "reference" or "pointer" in my Python repertoire :) But it is working.
GitLab Enterprise Edition
git.qoto.orgOkay, this isn't me, but consider doing this this month:
It is the Advent of Code for 2019
Unfortunately the fediverse is not a supporter or OAth so you will have to use Twitter, Google, Github to login.
I shall be lazy and only do a freebie.
This problem was asked by Microsoft.
Given a 2D matrix of characters and a target word, write a function that returns whether the word can be found in the matrix by going left-to-right, or up-to-down.
For example, given the following matrix:
[['F', 'A', 'C', 'I'],
['O', 'B', 'Q', 'P'],
['A', 'N', 'O', 'B'],
['M', 'A', 'S', 'S']]
and the target word 'FOAM', you should return true, since it's the leftmost column. Similarly, given the target word 'MASS', you should return true, since it's the last row.