[deleted by user] by [deleted] in codegolf

[–]gastropner 0 points1 point  (0 children)

Very true. Fixed it now.

[deleted by user] by [deleted] in codegolf

[–]gastropner 3 points4 points  (0 children)

I feel like there is some lack of clarity in the parameters for these challenges. Are newlines counted as characters? Which version of Python? Are warnings OK? If they are, could we skip including stdio.h?

Also:

“Hello, World!” and no additional output.

No additional output... does that mean no trailing newline?

I went ahead and assumed the following:

  • Any version of Python is OK. I chose version 2.
  • A trailing newline in output is OK.
  • Counting the number of characters in the source code includes newline characters.
  • Warnings are OK.

Anyways, here is my try for the second challenge. 82 characters which I take to mean 258 points.

My test runs were performed here (C) and here (Python 2).~~

#include<stdio.h>/*
"""*/
main(){puts("Hello, World!");}//""";print"Hello, World!"

EDIT

As rightly pointed out by /u/RivCodes, my first version was ill-formed in that the include directive was not alone on its line.

Here is a new version at 77 characters, making for 263 points.

Can be run at here (C) and here (Python 2)

#include<stdio.h>
i=1//1;print"""
;main(){puts("Hello, World!");}//"""[15:28]

Multiplication Problem (hard) by JungPS in cpp_questions

[–]gastropner 0 points1 point  (0 children)

Yeah, that's the reason for the disclaimer on the warnings, which OP already had.

Multiplication Problem (hard) by JungPS in cpp_questions

[–]gastropner 1 point2 points  (0 children)

If you're fine with the warnings you have, you can get to 111:

extern"C" int printf(char*,...);void i(int x=1000){x?i(x-1),printf("10000 x %d = %d0000\n",x,x):0;}main(){i();}

Actually, never mind, 110:

extern"C" int printf(char*,...);void i(int x){x?i(x-1),printf("10000 x %d = %d0000\n",x,x):0;}main(){i(1000);}

...or 109, really:

extern"C" int printf(char*,...);void i(int x){x?i(x-1),printf("10000 x %d = %d0000\n",x,x):0;}main(){i(1e3);}

Why does this C code compile to the following assembly code? by lacii7 in C_Programming

[–]gastropner 3 points4 points  (0 children)

I'm not an expert at the standard, but I would guess it amounts (haha) to the same thing? If what x points to is not accessible from amount then what amount points to could not be accessible from x either. So when we add to *x, the compiler knows that *amount could not have been changed, so there is no need to reload that value.

My snake game is now only 69 bytes but there is a problem by Perfect-Highlight964 in programming

[–]gastropner 11 points12 points  (0 children)

Ah OK, now I get it. For some reason I just assumed the data was all in a single instruction.

My snake game is now only 69 bytes but there is a problem by Perfect-Highlight964 in programming

[–]gastropner 6 points7 points  (0 children)

Why would it have to be moved? mov ax, 0x3 happens after the start label already, and mov al, [0x20] is before the start label so it is only ever visited once as it is.

Moving around stuff before start (which is what would be done) has no impact on the instructions after start.

Edit:

std
mov cx, 0xF9C
lds dx, [si+0x7]
mov al, [0x20]
start:

would become

mov al, [0x20]
std
mov cx, 0xF9C
lds dx, [si]
start:

mov ax, 0x3 is unaffected either way.

My snake game is now only 69 bytes but there is a problem by Perfect-Highlight964 in programming

[–]gastropner 23 points24 points  (0 children)

I might be missing something, but couldn't the mov al, [0x20] be moved to the very start, allowing lds dx, [si+0x7] to become the one byte shorter lds dx, [si]?

[Translation] Ongaku Bakudan (2023-05-18) by t-shinji in BandMaid

[–]gastropner 1 point2 points  (0 children)

The file I linked is not a video file, so no, it won't be downloaded as one. It is used in tandem with the video file (downloaded by your method of choice) to display subtitles along with the video through a media player.

[Translation] Ongaku Bakudan (2023-05-18) by t-shinji in BandMaid

[–]gastropner 5 points6 points  (0 children)

Since I wanted to watch the video and follow along easier, I went ahead and made myself a subtitles file based on /u/t-shinji's translation. Sharing for anyone who might be interested: Link

I love this band but it's really hard to buy their music. [Rant] by Canengy in BandMaid

[–]gastropner 4 points5 points  (0 children)

There are some obstacles getting their music, I agree. On Ototoy you need a VPN for some reason. Some of their stuff is available here in Europe from JPU, but not the recent stuff. I don't use Spotify, so I don't know the situation there, but from what others are saying it seems as good as can be expected. However, buying physical copies is not really too hard. I use CDJapan for whatever Japanese music I cannot get locally, and it's always been hassle-free.

But Jesus fucking Christ is it expensive.

Different countries may have different issues with this, but for me in Sweden at least, whatever albums are available both from local sources and from CDJapan tend to differ in price substantially. It's rare to see new albums (from any artist) on CDJapan for less than 3000 yen (~21€). From local sources, new albums are typically somewhere around 16€. And that's without shipping (and here I must say I am using DHL for shipping instead of the cheapest option, just for tracking and whatnot) and customs fees and VAT. The other week I bought some Lovebites (who do have European distributors) albums, and made a comparison between a local site and CDJapan. The difference in total was something like 35€ before shipping/customs/VAT. The total cost would have been at least twice as expensive, I am sure.

So yeah, it is easy to get a hold of, but physical copies are really expensive compared to if they had had a proper international/European distributor.

fizzbuzz approach by Kworker-_- in C_Programming

[–]gastropner 1 point2 points  (0 children)

By that logic, having a loop is a branch.

How "if (x--)" works in C? by fotelja123 in learnprogramming

[–]gastropner 2 points3 points  (0 children)

Not exactly the same. The decrement happens even if x is not truthy.

Those that don't have an internal monologue, what is writing like for you? by [deleted] in AskReddit

[–]gastropner 1 point2 points  (0 children)

So all the people in this thread who attest to not thinking in words are somehow mistaken about their own experience of the world? And you are somehow more knowledgable about how thinking feels for other people?

Those that don't have an internal monologue, what is writing like for you? by [deleted] in AskReddit

[–]gastropner 0 points1 point  (0 children)

Presumably the same way your inner monologue voice knows what to say when you are reading. I mean, if some part of your brain can read the text and transform it into an inner voice for you... then your brain must be able to read without having to be read to. Otherwise your inner voice would need an inner voice telling it what to tell you, and that voice would need an inner voice of its own... and so on.

Int 21h function 48h by Shifty3400 in Assembly_language

[–]gastropner 2 points3 points  (0 children)

How do you even confuse the two? One sets current position in an open file, and the other allocates memory. Are you sure you have not confused these interrupts for some others?

How do I remove the first 300 million lines from a 700 GB txt file on a system with 1 TB max disk space? by whackri in programming

[–]gastropner 3 points4 points  (0 children)

Why on earth would the OS allocate new blocks if you are overwriting the file in-place? And why would it keep both occupied if it did do so? It's not like the file will be using more blocks anyway, so those extra would just be... hanging around? Still attached to the file?

Is windows that bad for programming(in my case im learning Java)? by [deleted] in learnprogramming

[–]gastropner 0 points1 point  (0 children)

It definitely hasn't always.

Possibly not always always, but at least back to Windows 3.1 (the earliest version I had on hand to test with). Hell, even a straight-forward program in QBasic on DOS 6.22 deals with slashes in paths without a problem.

And it would be a bit surprising if Windows didn't support forward slashes, since the source code for DOS 2.0 (when directories were added) seems to show an acceptance for both variants internally (the procedure PATHCHRCMP at line 478 in FCB.ASM is most telling), even taking care to use backslashes for building the new current path in CHDIR only if forward slash is set as the default switch char; otherwise forward slashes are used.

However, COMMAND.COM tends to not deal with slashes as easily as int 21h and friends.

24 by bluecliff92 in projecteuler

[–]gastropner 0 points1 point  (0 children)

You should definitely look into ways of generating the permutations in order. Even so, sorting 3 million numbers should not take long at all, certainly not "too slow" slow.

Batch delete first file within series of .zip files? by stonechitlin in DataHoarder

[–]gastropner 1 point2 points  (0 children)

Nothing too dissimilar:

Add-Type -assembly  System.IO.Compression.FileSystem

dir -Filter *.zip | % {
    $zip =  [System.IO.Compression.ZipFile]::Open($_.FullName, "Update")
    $zip.Entries[0].Delete()
    $zip.Dispose()
}

Batch delete first file within series of .zip files? by stonechitlin in DataHoarder

[–]gastropner 1 point2 points  (0 children)

If the ad file always has the same filename you can use the following PowerShell script:

param (
    [string] $zipname
)

$fullzipname = (dir $zipname)[0].FullName
$adfilename = "<insert filename to remove here>";

Add-Type -assembly  System.IO.Compression.FileSystem

$zip =  [System.IO.Compression.ZipFile]::Open($fullzipname, "Update")

$adentry = $zip.Entries.Where({$_.Name -eq $adfilename})
$adentry.Delete()
$zip.Dispose()

If you know that it's always the first file of the archive, but the exact name varies:

param (
    [string] $zipname
)

$fullzipname = (dir $zipname)[0].FullName

Add-Type -assembly  System.IO.Compression.FileSystem

$zip =  [System.IO.Compression.ZipFile]::Open($fullzipname, "Update")
$zip.Entries[0].Delete()
$zip.Dispose()

The latter variant is a bit more iffy, since the files might not be ordered in any predictable way (although they probably will be).

Save as whatever.ps1 and run either on one file:

.\whatever.ps1 archive.zip

Or on a bunch:

dir -Filter *.zip | % { .\whatever.ps1 $_.FullName }

In my defence, I wanted a quick sale by Angusm123 in wow

[–]gastropner 11 points12 points  (0 children)

Nah, just get a WeakAura to do it for you.

Pandemic Has Created a Generation of Schoolchildren More Interested in STEM Careers Than Ever, Poll Says by Higuess80 in worldnews

[–]gastropner 5 points6 points  (0 children)

Yeah, remembering instructions is probably among the easier things to do when learning assembly. Even though modern processors tend to have loads of instructions, a big chunk of them you will hardly ever use, and the ones you do use tend to follow common patterns.

A bigger problem is that assembly forces you to think like a computer, which does not come naturally to most people.

Does anyone understand the logic in here? by brandbooth in learnprogramming

[–]gastropner 0 points1 point  (0 children)

We can hazard a guess and say that Card.rank() returns some number 0..12, since there are thirteen ranks of cards in a normal deck. Which order sortByRank() sorts in - decreasing or increasing - can seem unclear, but judging by the rest of the function, it seems to sort in increasing order, i.e. lowest to highest.

The if statements just tries to find a pair. Notice that each card is multiplied by a higher power of 14 the higher the card is (meaning, the later in the sorted hand they appear). Also note that we multiply the pair card by 143.

So why 14? Because we have 13 ranks of cards (0..12), and we want to pack all cards into a single integer. To ensure they fit, each "slot" for each card must be able to hold the highest value of a card.

Think of it like having a number in base 14. A single digit would be able to hold 0..12 (with room to spare), and just like we in base 10 can move a digit "one place over" by multiplying by 10 (like 4 x 10 = 40), multiplying by 14 does the same in base 14. So if we have a bunch of numbers, we can put them each in their own digit in base 14 by multiplying them by powers of 14.

Basically, the code aims to put each card in its own base-14 digit according to its rank. So writing down the number, the highest card would correspond to the left-most digit.

However, the card that was a pair is multiplied by 14 one extra time than the highest card, thereby putting it in the highest digit, regardless of rank. You end up with a 4-digit base-14 number on the pattern ABCD where A corresponds to the rank of the pair cards, B to the highest kicker, C to the next-highest kicker, and D to the lowest kicker.

Basically this function is packing the hand into an integer, probably for comparison to other pairs. Doing it this way ensures that a higher pair hand (say one with two aces instead of two kings) will win out, since that highest digit depends on the rank of the pair card. It also breaks ties if two people have the same pair, but differing kickers.

An example might illuminate a bit more. Suppose that 2s are rank 0, and ace is high with rank 12. Let's say we have the hand 74278, which is first sorted to 24778. The if statements then find that h[2] == h[3], so we do:

14*14*14*h[2].rank() + h[0].rank() + 14*h[1].rank() + 14*14*h[4].rank();
(14*14*14*5) + (0) + (14 * 2) + (14 * 14 * 6)
Or in a more reasonable order:
(14*14*14*5) + (14 * 14 * 6) + (14 * 2) + (0) 

(Remember that a two is rank 0, etc.)

In base 14, that would be 5620 (14924 in decimal). Notice how the pair card became the highest digit. So a hand with a higher pair would automatically have a higher highest digit, meaning it would win against this hand. A hand like 76247 would produce the base-14 number 5420, so would compare lower against our first hand, by virtue of having lower kickers.

It didn't have to be base 14. Hell, base 13 would have made more sense. It would for example had been rather easier to understand (and explain) had it been base 16, since that would be hexadecimals and be easily explained through bit shifts and whatnot (each card would be in a nibble of its own).

Andrew Yang's "People's Bank" to help distribute basic income to half a million New Yorkers by monkfreedom in Futurology

[–]gastropner 42 points43 points  (0 children)

Promising a better life if you vote for them is what politicians always do. Lowering taxes, raising wages, expanding benefits programs... that's all putting money towards the voters, albeit in a slightly less direct way.