Last edited by Coffee table knight (2024-07-20 10:00:40)
flood #4 midsummer night's dream
Posts 361 to 390 of 848
Share12024-07-15 22:07:33
Share3612024-07-22 19:22:54
В Питере теперь знаю больше исторических мест чем в родной Москве, а так всегда - где живешь, там все пофиг
Share3622024-07-22 19:23:40
The Herald
I've been to Ermitage once. When my friend came to visit )
Share3632024-07-22 19:42:39
I know a lot of places in Moscow (a native Muscovite). And I know several attractions in St. Petersburg
Share3642024-07-22 20:20:28
Coffee table knight
soon you'll know all the places in Belgrad
Share3652024-07-22 20:23:14
soon you'll know all the places in Belgrad
Dream of going to museums. While I visited the botanical garden and zoo. It was amazing!
Share3662024-07-22 20:24:53
I always considered Moscow grey and dull, but, in the hindsight, it might be because I never went exploring further than the route from home to school/work. But now I know the waterfront of Toronto almost intimately
Share3672024-07-22 20:41:55
we bought a comic in serbian)))
I like how they call wonder woman: чудесна жена
Share3682024-07-22 20:46:52
Share3692024-07-22 20:50:29
42
How are you doing today?)
Share3702024-07-22 20:51:10
wonder woman: чудесна жена
if I ever have a wife that's how I'll call her
Share3712024-07-22 20:54:24
Lucifer
I have an interesting brain-wrecking task, so I'm good)
And you?
Share3722024-07-22 20:55:28
I have an interesting brain-wrecking task, so I'm good)
is it work related or one of your pet projects?
Share3732024-07-22 21:01:41
Lucifer
Work-related this time. In truth, it sounds rather simple, but when you start coding it, it gets quite complicated
Share3742024-07-22 21:19:39
42
well, you like a challenge )
Share3752024-07-22 21:27:36
Lucifer
I do. And I've always solved it (at least in broad strokes), but I cannot pin down how to write the recursion nicely here...
Share3762024-07-22 21:44:30
And you?
My leave starts in 15 minutes. I'm counting
Share3772024-07-22 22:00:08
Lucifer
Lucky you!
I think I more or less did it!
const timeStart = '2023-05-12 00:00:00';
const timeEnd = '2024-07-15 23:59:59';const timeStartDate = new Date(timeStart);
let timeEndDate = new Date(timeEnd);
timeEndDate = new Date(timeEndDate.valueOf() + 1000)const periods = {
"year": [],
"month": [],
"week": [],
"day": [],
"hour": []
}function extractPeriods(timeStartDate, timeEndDate, period) {
let lastPeriodStart = new Date(timeEndDate);
lastPeriodStart = getFirstDayOfPeriod(lastPeriodStart, period)let prevPeriodStart = new Date(lastPeriodStart);
prevPeriodStart = onePeriodBack(prevPeriodStart, period);
let prev = new Date(prevPeriodStart);
while (timeStartDate < prevPeriodStart) {
periods[period].push(prevPeriodStart.toISOString())
prev = new Date(prevPeriodStart);
prevPeriodStart = onePeriodBack(prevPeriodStart, period);
}
if (timeStartDate < prev) {
return [
{
timeStartDate: timeStartDate,
timeEndDate: prev
},
{
timeStartDate: lastPeriodStart,
timeEndDate: timeEndDate
}
]
} else {
return [
{
timeStartDate: timeStartDate,
timeEndDate: timeEndDate
}
]
}
}function getFirstDayOfPeriod(date, period) {
switch (period) {
case "year":
date.setMonth(0, 1);
return date;
case "month":
date.setDate(1);
return date;
case "week":
const d = date.getDay()
date.setDate(date.getDate() - d);
return date;
case "day":
return date;
case "hour":
return date;
}
}function onePeriodBack(date, period) {
switch(period) {
case "year":
date.setFullYear(date.getFullYear() - 1)
return date;
case "month":
date.setMonth(date.getMonth() - 1);
return date;
case "week":
date = new Date(date.valueOf() - 604800000);
return date;
case "day":
date = new Date(date.valueOf() - 86400000);
return date;
case "hour":
date = new Date(date.valueOf() - 36000000);
return date;
}
}const timeIntervals = [ {
timeStartDate: timeStartDate,
timeEndDate: timeEndDate
}];
const periodNames = ['year', 'month', 'week', 'day', 'hour']function extractPeriodsRecursive(timeIntervals, periodNameIndex) {
timeIntervals.forEach((timeInterval) => {
const newTimeIntervals = extractPeriods(timeInterval['timeStartDate'], timeInterval['timeEndDate'], periodNames[periodNameIndex])
if (periodNameIndex < periodNames.length - 1) {
extractPeriodsRecursive(newTimeIntervals, periodNameIndex + 1)
}
})
}extractPeriodsRecursive(timeIntervals, 0);
Last edited by 42 (2024-07-22 22:00:31)
Share3782024-07-22 22:02:36
that's a lot of code
Share3792024-07-22 22:11:05
Faded Star
It's not as big as it looks, there are a couple of switches inside.
Basically, what it is supposed to do, given an arbitrary time period, it will split it into some calendar periods trying to prioritize the largest. So, if it's, say, a period of three years and some days, it will extract the full calendar years first, than, from the remaining time, it will extract all the full calendar months, than weeks, days and finally hours (my time periods don't go more granular than hours).
Share3802024-07-22 22:14:08
Faded Star
It's not as big as it looks, there are a couple of switches inside.Basically, what it is supposed to do, given an arbitrary time period, it will split it into some calendar periods trying to prioritize the largest. So, if it's, say, a period of three years and some days, it will extract the full calendar years first, than, from the remaining time, it will extract all the full calendar months, than weeks, days and finally hours (my time periods don't go more granular than hours).
Sounds formidable even though hard for me to grasp as of now
Keep up the good work, it does not sound easy in the slightest
Share3812024-07-22 22:20:21
Faded Star
This actually supposed to be the easiest part of the whole data processing module I've been developing But this time sorting algorithm is a little b*tch, it's true
Share3822024-07-22 22:44:18
Why is the code similar to English? Is it a python that speaks Rudyard Kipling's language?
Share3832024-07-22 22:49:26
Coffee table knight
Why would not it be? The code consists of functions, memory blocks (variables) and operations. All these things need names, and ideally those names should be eloquent enough that, simply by looking at the name, you would guess what the function does. So yes, the names of the functions, variables and everything else always make perfect sense in English
Share3842024-07-22 22:53:32
42
How do you know which words the progamming language recognizes in code and which ones it doesn’t? Who gives it a list of English words to recognize? And how to replenish a dictionary?
Share3852024-07-22 22:59:51
Coffee table knight
The compiler (the program) does not care about the words. All those words are names and needed only for humans' benefit. For the compiler they are simply names. Like "Jack" does not have any meaning on its own and simply points to a person, the same way calculateDates() does not mean anything for the compiler, it simply indicates which chunk of code to execute
Share3862024-07-22 23:09:01
42
I mean, how do you know what to say in code, so the computer can do what you want?
For example, how do you know what to write exactly this?
const timeStart = '2023-05-12 00:00:00';
const timeEnd = '2024-07-15 23:59:59';const timeStartDate = new Date(timeStart);
let timeEndDate = new Date(timeEnd);
timeEndDate = new Date(timeEndDate.valueOf() + 1000)
How do you know that the computer will understand you? Have you learned all these commands? Is there a dictionary of all the commands in the world? Who’s filling in the dictionary? The developers of the programming language?
Share3872024-07-22 23:11:53
Coffee table knight
Yes. It's called "the programming language syntax". It is slightly different for every language although most of the languages are similar enough. Each language has specific rules for how you need to structure your commands and a set of predefined, the most commonly used functions (a very large set of thousands of functions usually). You do not have to know them all, of course, but the most common you memorize fast enough.
In a way, it is like learning another language
Last edited by 42 (2024-07-22 23:15:48)
Share3882024-07-22 23:14:42
42
Wow, thank you, it's interesting!
Share3892024-07-23 07:25:43
Good morning
Share3902024-07-23 10:05:17
Lucifer, hello! New puzzles are waiting for you.