Carl Love

Carl Love

27621 Reputation

25 Badges

12 years, 100 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

The ​​​with command has global side effects, and it shouldn't be used in procedures (or, at the very least, it shouldn't be used in the way that you've used it). The fact that it may sometimes seem to work is irrelevant. You can replace the three with commands with 

uses plots, DEtools, PDEtools;

This is an outstanding explanation. You should formally publish it for a wider audience than the Maple community. 

So, is each pair of teams supposed to play exactly one match? For 8 teams, there are 28 pairs, so 2 matches per week covers 14 weeks. On such a schedule, 4 teams wouldn't play on any given week. For 10 teams, there are 45 pairs, so 3 matches per week covers 15 weeks. This schedule would also have 4 teams not playing on any given week.

@salim-barzani When someone on MaplePrimes says "1D input", this "Maple Input" that you see on the menu within Maple itself is exactly what they mean. I don't think that the term "1D input" is officially used by Maplesoft. Thiat's a bit strange because "1D input" is the most natural term for the mode that is the alternative to 2D Input, any either mode is a method of giving input to Maple, so a naive user wouldn't guess that "Maple Input" refers strictly to the non-2D mode.

@segfault There is no command s-convert. It's just the previously defined series s minus all of its terms other than the order term. In other words, the `-` is simply the ordinary subtraction operator, with its second operand being the result of the convert command.

Even easier:

TypeTools:-AddType(gtoint, And(posint, Not(1)));

This avoids two procedure calls every time that the type is checked: a call to `type/satisfies` and a call to the anonymous procedure s-> s > 1

Unlike satisfiesAnd and Not are built-in type constructors, which don't involve procedure calls.

@salim-barzani The fact that there are extra characters in your input is not completely hidden. Look closely at the solve command in your Question and the one in acer's Answer. For the one in your Question, notice that there is extra white space before the A[0] {between the { and the A). Suspicious extra white space in 2D input usually means extra, unseen, characters. Once you get used to it, these extra white spaces "stick out like a sore thumb" (an English idiom meaning "immediately visibly obvious").

@Rouben Rostamian  Maple strings, as we know them today, were introduced in Maple 6 (I think). Before that, there was no syntactic distinction between symbols (a subtype of names) and strings. They were only distinguished by their intended use. The command substring comes from that time.

Note that substring works for strings and symbols. It doesn't work for names that aren't symbols.

@janhardo  You wrote:

  • [T]he moderator could have put your wrong post under the existing question as an example and reminded you again of the correct procedure to ask questions.

No, that's not possible. Unfortunately, the MaplePrimes software doesn't have any option for a Moderator to move an item (posted by another author) to another thread. The only options are 

  • edit the item (including possibly its header info or title) in its current location;
  • delete it;
  • change its overall type, such as changing a Post to a Question or an Answer to a Reply (within fhe same Question);
  • move it within its own thread, such as changing to which Answer a Reply is attached.

The MaplePrimes software ought to be changed to allow a Moderator to move a Question to a followup Reply to a previous Question. Unfortunately, it seems that changes to the software are only made occasionally, every 5 years or so.

A Moderator---or anyone else for that matter---can make a "didactic" (as you say) Reply. The problem with this is that if the OP doesn't move the item, then the primary purpose of Moderation is not achieved. That primary purpose is to reduce the number of extraneous threads, which enhances the readability and searchability of MaplePrimes for all users, for all time.

This was the first Advent of Code problem that I tried. It seemed very easy. Indeed, as you suggested, parsing the text input is harder than doing the calculations.

Dedicated integer solution techniques are not needed. It can be done in each case by finding the rational-number solution of a pair of linear equations and discarding any non-integer solutions. Some extra work might be required if there were cases of multiple solutions, but that didn't occur. My CPU time for all 640 problems (both parsing and computation) was less than 1/2 second.

Advent of Code solution for 2024-Dec-13
Reference: https://adventofcode.com/2024/day/13
Maple solution by Carl Love <carl.j.love@gmail.com>

restart
:

interface(prompt= "")
:

# These operators have nothing specific to do with this particular problem. Rather,
# they are operator constructors that I very frequently use:

`&<`:= eval(curry):  `&>`:= eval(rcurry)
:
ST:= eval(StringTools): LA:= eval(LinearAlgebra): CT:= eval(CodeTools)
:
st:= time()
:
# The raw problem input is entered as a string in this Code Edit Region. For me,
# this is far more convenient and portable than using a text file:

Advent of Code 2024 Day 13 raw input

# After each command, I show the first few entries, just so the reader and I
# can stay oriented:
Raw[..128];

"Button A: X+49, Y+27
Button B: X+35, Y+65
Prize: X=4326, Y=4898

Button A: X+82, Y+64
Button B: X+20, Y+67
Prize: X=6818, Y=1040"

(* Split by paragraph (StringSplit \n\n), then by line (Split \n), obtaining a listlist.
Then use RegSplit to extract the 6 positive integers (as strings) from each paragraph.
Then use 'parse' to convert strings to numbers. Then make each paragraph's numbers in a 3x2
mstrix and transpose (^~%T) it.
*)
use StringTools in  #RegSplit, Split, StringSplit
    Data:= (
        (Matrix &< (3,2) @ parse~ @ RegSplit~ &< "[^0-9]+" @ Split &> "\n")~ @ StringSplit
     )(Raw, "\n\n") ^~%T
end use:
%[..7];

[Matrix(2, 3, {(1, 1) = 49, (1, 2) = 35, (1, 3) = 4326, (2, 1) = 27, (2, 2) = 65, (2, 3) = 4898}), Matrix(2, 3, {(1, 1) = 82, (1, 2) = 20, (1, 3) = 6818, (2, 1) = 64, (2, 2) = 67, (2, 3) = 10409}), Matrix(2, 3, {(1, 1) = 75, (1, 2) = 95, (1, 3) = 8360, (2, 1) = 72, (2, 2) = 15, (2, 3) = 4749}), Matrix(2, 3, {(1, 1) = 59, (1, 2) = 15, (1, 3) = 7401, (2, 1) = 26, (2, 2) = 29, (2, 3) = 3032}), Matrix(2, 3, {(1, 1) = 77, (1, 2) = 15, (1, 3) = 13582, (2, 1) = 38, (2, 2) = 46, (2, 3) = 10664}), Matrix(2, 3, {(1, 1) = 39, (1, 2) = 27, (1, 3) = 1367, (2, 1) = 11, (2, 2) = 40, (2, 3) = 2880}), Matrix(2, 3, {(1, 1) = 50, (1, 2) = 20, (1, 3) = 7220, (2, 1) = 28, (2, 2) = 55, (2, 3) = 383})]

#Part 1 solution:
Sol1:= CT:-Usage(
    <3,1> . add(select(type, LA:-LinearSolve~(Data), 'Vector'(nonnegint)))
);

memory used=23.54MiB, alloc change=37.00MiB, cpu time=47.00ms, real time=274.00ms, gc time=15.62ms

36250

#Part 2 extra number:
n:= 10000000000000
:

#Part 2 solution:
UpD:= <0,0,n; 0,0,n>:
Sol2:= CT:-Usage(
    <3,1> . add(select(type, LA:-LinearSolve~(Data +~ 'UpD'), 'Vector'(nonnegint)))
);

memory used=15.09MiB, alloc change=0 bytes, cpu time=62.00ms, real time=214.00ms, gc time=0ns

83232379451012

#CPU time for the whole shebang:
time()-st;

.422

 

Download AoC_2024_Dec_13.mw

@Carl Love Nevermind, I've confirmed that the essential difference is the use of "C""P", and "T" rather than C, P, and T.

@Samir Khan Could you please explain how your CP, which works, is different from the OP's CP(T1(t)), which doesn't work? Is it simply the quotation marks on the C, P, and T that are the crucial difference?

@nm Yes, the only reason that I did it with sprintf instead of concatenation was to get the leading zero(s) in a programmatically general way. The reason to use leading zeros is so that a standard string sort of the filenames will come out in numeric order.

Also, sprintf is a standard command in many languages, and it's much older than Maple.

@dharr I'd like to see your syntax error. This works perfectly for me:

restart;
P:= proc(x) sin(x) end proc:
P2:= subs(sin= evalhf@sin, subsop(3= (op(3,eval(P)), hfloat), eval(P)));
P2(3);

@mehdi jafari Sorry, I don't know how to use these commands or if they work in the current version of Maple, and I don't have the time right now to figure it out. Note that I wrote the above Answer over 6 years ago, and even at that time I suspected that those commands weren't up to date.

Is the SaveAll given by @stefanv above sufficient for your needs?

1 2 3 4 5 6 7 Last Page 1 of 704