Nouvelle publication

Rechercher

Résumé
· Mai 13, 2024

InterSystems Developers Publications, Week May 06 - 12, 2024, Digest

Articles
Announcements
#InterSystems IRIS
#Learning Portal
#IRIS contest
#Global Masters
#InterSystems Official
Questions
#InterSystems IRIS
#VSCode
Annoying Bulb in VS Code
By Alexey Maslov
#InterSystems IRIS for Health
#Caché
#Ensemble
#HealthShare
May 06 - 12, 2024Week at a GlanceInterSystems Developer Community
Article
· Mai 13, 2024 1m de lecture

QuinielaML - Predicciones de la 57ª jornada de la Quiniela

Volvemos con las predicciones de la Quiniela que, desafortunadamente, no pudimos publicar el pasado viernes (mea culpa, mea maxima culpa).

Esta jornada es algo atípica al disputarse el miércoles e incluir partidos de Primera División, Premier League y Ligue 1. Veamos los partidos que entran esta jornada:

Veamos la estimación para la Primera División:

Para la Premier League:

Y finalmente para Ligue 1:

Esto nos da la siguiente Quiniela:

¡Mucha suerte a todos!

1 Comment
Discussion (1)1
Connectez-vous ou inscrivez-vous pour continuer
Discussion
· Mai 13, 2024

[Code Challenge] "Plan Your Dream Wedding"

Hello,

I would like to propose you a challenge.

It has been created by a web user called "uttumuttu" and it is being explained here: https://www.codewars.com/kata/66314d6b7cb7030393dddf8a

Here is the proposed challenge copied and pasted:

DESCRIPTION:

This kata was created as a contender for the EPIC Challenge 2024.

Background

It's your dream to have a magical wedding day, and you're willing to spend every last penny on it — while simultaneously planning for a stable retirement income.

Task

Your monthly surplus income (i.e., income after all taxes and mandatory monthly costs) is C dollars (e.g., C = $2,500), and will remain so until your retirement. At the end of each month, you will invest the surplus income in your savings account with a certain rate of monthly return r > 0 given in percentage (e.g., r = 0.5 percent per month), growing with compound interest. Your savings account is initially empty.

You are planning to retire in T years (e.g., T = 35), and have calculated that upon retirement, you need minimum S dollars of savings to finance a stable retirement (e.g., S = $3,000,000).

You are also planning to have a wedding in W years (e.g., W = 5), with 1 <= W <= T. What is the largest amount of savings you can spend on the wedding while ensuring that you will also have enough money for your retirement?

Notice that the savings spent on the wedding no longer produce investment returns at rate r per month. Also, you cannot finance the wedding on debt — you can only use the savings up to the wedding date!

Example 1

Let's say the function max_wedding_cost(C, r, S, T, W) gets the above inputs C = 2_500 (dollars per month), r = 0.5 (percent per month), S = 3_000_000 (dollars), T = 35 (years) and W = 5 (years).

If you spend zero dollars on your wedding, you will have approximately 3_561_775.75 dollars in your savings account upon your retirement, or 561_775.75 dollars over the required S = 3_000_000 dollars.

It turns out that the maximum amount you can spend on your wedding day is approximately 93_278.33 dollars. Your answer should be within 0.01% of the reference answer. See notes for further details on accuracy.

Example 2

Suppose in the above example S = 2_000_000, i.e., you need a million dollars less for your retirement.

In this case it turns out that you can blow all your savings up to wedding day — a total of approximately 174_425.08 dollars — on your wedding. Even though you have to re-start saving from scratch, you can still reach your two-million-dollar retirement goal.

Notes

Your magical savings account operates on double-precision floating point arithmetic, so you don't have to deal with rounding numbers to cents. Just return the final result as a floating point number without any rounding; it only needs to be within 0.01% of the reference solution.

It is guaranteed that with zero wedding costs, you will reach your retirement goal S. Parameters will have the following ranges: 100 <= C <= 3_0000.1 <= r <= 1.0100_000 <= S <= 3_000_00010 <= T <= 40, and 1 <= W <= T.

 

 

I have solved it by myself in Java, and I was curious about how could you solve it using ObjectScript.

 

The initial code provided by the challenge in Java is as follows:

class Kata
{
  public static double maxWeddingCost(int C, double r, int S, int T, int W)
  {
    return 0;
  }
}

 

The approach I used was this, I renamed the variables to make it clearer:

public class Kata {
    public static double calculateTotalSavingsAtTime(double initialPrincipal, double monthlyInterestRate, double monthlyDeposit, int timeMonths) {
        return monthlyDeposit * ((Math.pow(1 + monthlyInterestRate, timeMonths) - 1) / monthlyInterestRate) + initialPrincipal * Math.pow(1 + monthlyInterestRate, timeMonths);
    }

    public static double calculateRequiredPrincipal(double targetSavings, double monthlyInterestRate, double monthlyDeposit, int timeMonths) {
        return (targetSavings - monthlyDeposit * ((Math.pow(1 + monthlyInterestRate, timeMonths) - 1) / monthlyInterestRate)) / Math.pow(1 + monthlyInterestRate, timeMonths);
    }

    public static double maxWeddingCost(int monthlySurplusIncome, double monthlyInterestRate, int retirementSavingsGoal, int yearsToRetirement, int yearsToWedding) {
        double savingsAtWedding = calculateTotalSavingsAtTime(0, monthlyInterestRate / 100, monthlySurplusIncome, 12 * yearsToWedding);
        double remainingSavingsNeeded = calculateRequiredPrincipal(retirementSavingsGoal, monthlyInterestRate / 100, monthlySurplusIncome, 12 * (yearsToRetirement - yearsToWedding));
        double maxWeddingCost = savingsAtWedding - Math.max(0, remainingSavingsNeeded);
        return maxWeddingCost;
    }
}

 

How would you like to solve it, using ObjectScript?

6 Comments
Discussion (6)1
Connectez-vous ou inscrivez-vous pour continuer
Résumé
· Mai 13, 2024

Publications des développeurs d'InterSystems, semaine Mai 06 - 12, 2024, Résumé

Article
· Mai 13, 2024 1m de lecture

Trucs et astuces de VSCode - Ouverture d'une classe par son nom

Dans Studio, vous pouviez ouvrir une classe directement par son nom, sans avoir à parcourir l'arborescence du paquetage par de multiples clics jusqu'à ce que vous arriviez à la classe souhaitée.

Vous pouvez faire Ctrl + O ou (File -> Open) et taper simplement le nom de la classe, par exemple :

Appuyez sur la touche "Enter" et la classe est ouverte.

Comment y parvenir en VSCode ?

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer