Skip to content

Instantly share code, notes, and snippets.

View marsgpl's full-sized avatar
🔴
Recording

Iurii Belobeev marsgpl

🔴
Recording
View GitHub Profile
@marsgpl
marsgpl / asyncMapper.ts
Last active December 7, 2023 00:43
asyncMapper.ts
// write async generator to return N random strings per call
// add parameter to limit total amount of strings returned by generator
// write async mapper that accepts async generator as argument and
// a callback that is applied for every generator result
// mapper should return all generator results as array
async function getLinesTotal() {
return 8
#include <stdio.h>
typedef int (*fn)(void);
void custom_transaction(fn *dos, fn *undos, size_t n) {
for (int i = 0; i < n; ++i) {
if (!(dos[i])()) {
while (--i >= 0) { undos[i](); }
return;
}
@marsgpl
marsgpl / replace-0-with-1.c
Created October 17, 2024 08:52
Write a Program to Replace all 0’s with 1’s in a Number
#include <stdio.h>
int main() {
int N = 102301;
printf("before:\t%d\n", N);
for (int power = 1; power <= N; power *= 10) { // 1, 10, 100, ...
int digit = N / power % 10;
// n must have exactly 2 distinct divisors to be prime
int is_prime(int n) {
if (n < 0) {
n = -n;
}
if (n <= 100) { // first 25 primes (add more?)
switch (n) {
case 2: case 3: case 5: case 7: case 11: case 13: case 17:
case 19: case 23: case 29: case 31: case 37: case 41: case 43:
#define STARS "****************************************************"
void print_pyramid(int levels_n) {
int max_w = levels_n + levels_n - 1;
for (int level = 1; level <= levels_n; ++level) {
int stars_n = level + level - 1;
int pad = (max_w - stars_n) / 2;
printf("%*s%.*s%*s\n", pad, "", stars_n, STARS, pad, "");
// given a string of digits and a target integer, insert + and * operators
// between the digits until the resultant equation results in the target,
// printing the result. if no possible equation exists with the given string,
// print "No solution found"
// Ex: "123456" and 464 prints 12*34+56
#include <stdio.h>
#include <string.h>