/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1562965914194.jpg (1280x720, 356K)

What are you working on, OP?

nth for negative progress

trying to solve the halting problem

Attached: 1563099583624.jpg (319x198, 26K)

>What are you working on, Jow Forums?
Mustering up the energy to implement locking memory pages into my allocator so that I can keep my secret keys from being swapped out.

It's easy, but boring, which is why I haven't done it yet.

Porting a I2C sensor library written in Python to Go.

Attached: cd53c61559974d1fa22a094ecff1f8a3_original.jpg (1552x873, 266K)

Why do you heff to be so mad?

...

post a challenge

Attached: cr1135454337795.jpg (1737x1345, 497K)

java is the most powerful programming language

implement an interesting eso-lang.

Write a program that adds two numbers together.

Why hate them? Do you lack emotional competence?

implement try, throw and catch in a language of your choice (without using builtin exceptions if your language already has them)

Given a pattern and a string str, find if str follows the same pattern.

Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

Example 1:
Input: pattern = "abba", str = "dog cat cat dog"
Output: true


Example 2:
Input:pattern = "abba", str = "dog cat cat fish"
Output: false


Example 3:
Input: pattern = "aaaa", str = "dog cat cat dog"
Output: false


p.s. You may assume pattern contains only lowercase letters, and str contains lowercase letters that may be separated by a single space.

>not calling out leeches for being leeches is emotional competence somehow

Attached: 1405462360897.jpg (380x572, 138K)

have sex

What language does it compile to?
And why'd you start making it?

From my perspective you seem delusional. Your view of yourself seems to be greater than what it is in reality. Not to put you down, just seems odd you would use incompetence as a reason to be angry. Perhaps, it is projection?

Abracadabra! Now Anone won't be late for my JavaScript lesson next time or his peepee will be small!

Attached: ee58db391d031da8257d3a2f4dd8ce93.png (510x680, 679K)

impossible
oh fuck, the stakes have risen

>From my perspective you seem delusional
From my perspective I don't give a fuck about your opinion. What I care about is you stealing my time, which I'll prevent by ignoring you henceforth.

Appropriate response, I suppose.

>henceforth.

Attached: 1559553918450.png (583x482, 119K)

>insofar

Go back whence you came.

That language is very unbecoming of you

>hitherto

>letten us beginnen

I want to start with osdev. what do?

start?

>make haste

Come back once you reached long mode in QEMU.

good tip.
let's write generic tips in fancy pants language.

>thou dost jest

> fancy pants
Pantaloons, user.

I'm working on a Majora's Mask HD Installer(which installs Project64, GlideN64, etc etc) for newbies since installing it requires a lot of effort from the user, so I'm completely automating the process, it's already largely done functionality wise(already works) and I made it flexible(I have an installer config the installer fetches when installing, which contains all the components it needs to install).

Lisp is the most powerful programming language.

Don't think too much, just start.

Maybe only second best to C++ if anything

can sepples do this
CL-USER> 12/9
4/3

yes

show me

#include

Rational r = 12_R / 9_R;
}

lulz

Aren't identifiers not allowed to begin with a number?

>>> from fractions import Fraction
>>> Fraction(12,9)
Fraction(4, 3)

(print 12/9.6)
*** - EVAL: variable |12/9.6| has no value

that's a user defined literal, not an identifier

here you go

Attached: www.png (737x2966, 137K)

In that case wouldn't it be
12r / 9r

, like in
12ul / 9ul

?

only literals defined by the standard library can have single letter suffixes
user defined literal suffixes must begin with _

void Main()
{
var inputs = new []
{
Tuple.Create("abba", "dog cat cat dog"),
Tuple.Create("abba", "dog cat cat fish"),
Tuple.Create("aaaa", "dog cat cat dog")
};

foreach (var input in inputs)
Console.WriteLine(solve(input));
}

bool solve(Tuple input)
{
var dict = new Dictionary();
var pattern = input.Item1;
var arr = input.Item2.Split(' ');

for (var i = 0; i < pattern.Length; i++)
if (!dict.ContainsKey(pattern[i]))
dict.Add(pattern[i], arr[i]);
else
if (dict[pattern[i]] != arr[i])
return false;
return true;
}

please don't kill me for not using {} in if & for

version 2, change solve's parameters
void Main()
{
var inputs = new []
{
Tuple.Create("abba", "dog cat cat dog"),
Tuple.Create("abba", "dog cat cat fish"),
Tuple.Create("aaaa", "dog cat cat dog")
};

foreach (var input in inputs)
Console.WriteLine(solve(input.Item1, input.Item2));
}

bool solve(string pattern, string sentence)
{
var dict = new Dictionary();
var arr = sentence.Split(' ');
for (var i = 0; i < pattern.Length; i++)
if (!dict.ContainsKey(pattern[i]))
dict.Add(pattern[i], arr[i]);
else
if (dict[pattern[i]] != arr[i]) return false;
return true;
}

yes, that is not a ratio

it should print the float value then

version 3 with checking if pattern or sentence is empty
void Main()
{
var inputs = new []
{
Tuple.Create("abba", "dog cat cat dog"),
Tuple.Create("abba", "dog cat cat fish"),
Tuple.Create("aaaa", "dog cat cat dog"),
Tuple.Create("aaa", ""),
Tuple.Create("", "dog cat"),
Tuple.Create("", "")
};

foreach (var input in inputs)
{
Console.WriteLine(solve(input.Item1, input.Item2));
}
}

bool solve(string pattern, string sentence)
{
if ((pattern.Length == 0 && sentence.Length > 0) || (pattern.Length > 0 && sentence.Length == 0))
{
return false;
}

var dict = new Dictionary();
var arr = sentence.Split(' ');
for (var i = 0; i < pattern.Length; i++)
{
if (!dict.ContainsKey(pattern[i]))
{
dict.Add(pattern[i], arr[i]);
}
else
{
if (dict[pattern[i]] != arr[i])
{
return false;
}
}
}
return true;
}

i'll be a good boy before someone murders me for not writing those {}

that for loop is way faster than a for each right?

i tried using foreach first, but decided to change it.
if i use foreach, i still need to access the arr variable based on the index.
so i use for.

you could give a number to the pattern like
pattern: abba -> 1221
string: dog cat cat dog -> 1221

and then compare them

Next challenge. Given a finite list as an argument, generate a circular list.

Example:
Input: [1, 2, 3]
Output: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1...]

(ns fun.challenge
(:require [clojure.core.unify :refer [make-occurs-unify-fn]]
[clojure.test :refer [is]]
[clojure.string :as string]))

(def unify (make-occurs-unify-fn string?))

(defn follows? [string pattern]
(= (count (set pattern))
(count (unify (map str pattern)
(string/split string #" ")))))

(is (= true (follows? "dog cat cat dog" "abba")))
(is (= false (follows? "dog cat cat fish" "abba")))
(is (= false (follows? "dog cat cat dog" "aaaa")))

>those {}
It was fine without them.

it means i still need that variable to store the number, right? and increment it every time i get a new one (1 -> 2, 2 -> 3, etc).

>generate a infinite list
what

While True: input.repeat()

(cycle [1 2 3])

I saw your Dictionary and thought you could use 2 simple arrays of integers and you fill them while parsing the input

can you give an example?
i'm not sure i understand it.

Working on my kernel a bit today. Just added a sweet mechanism that allows you to block a thread until an arbitrary condition is true :)
void Thread::block_until(Function condition);

Attached: Screenshot at 2019-07-14 14-58-43.png (1920x1080, 723K)

function* repeat(iterable, amount = Infinity) {
if (amount === Infinity || amount !== amount) {
for (;;) {
yield* iterable;
}
}
let i = 0;
for (;;) {
for (const value of iterable) {
if (i++ >= amount) {
return;
}
yield value;
}
}
}

pattern: abba -> 1221
string: dog cat cat dog -> 1221

start with "a" give it a value of 1, then you have "b" give it a value of 2, next you have a "b" again so you give 2 again next you have "a" then you give 1 again

Neat, user! Very sweet mechanism indeed. That piano looks neat too!

Why are you using the Tuple class instead of value tuples?

(define (match s l)
(define (go ss l acc)
(cond ((null? ss) (null? l))
((null? l) #f)
((hash-ref acc (car ss) #f) => (lambda (x)
(and (equal? x (car l)) (go (cdr ss) (cdr l) acc))))
(else (begin
(hash-set! acc (car ss) (car l))
(go (cdr ss) (cdr l) acc)))))
(go (string->list s) (string-split l #\space) (make-hash-table 32)))

well, i changed the parameters in v2.
the tuple is only used for problems.
i could changed them too into pair of strings

Oh yeah, computers should always have a little desktop piano for tinkering

after adding a & b
then you add b & a, you need to check what are the values of b & a.
i use dictionary because it's fast to check.
of course it's not noticeable if the pattern is short like this example (only 4 chars).

static IEnumerable Circular(IEnumerable items)
{
while (true)
{
foreach (var item in items)
{
yield return item;
}
}
}

static void Main(string[] args)
{
IEnumerable items = new List() { 1, 2, 3 };

var sequence = Circular(items).Take(10);
}

he didn't say the challenge was to prove how retarded this
{
bracing style
}
is

lol try to be nice

Pretty nifty, bud. Have you managed to make the install/build process simpler, yet? That's the only thing that's been holding me back from tinkering with it.

const builderFactory = () => ({
map: Object.setPrototypeOf({}, null),
getId: (i => () => ++i)(0),
});

function patternMatch(pattern, string) {
const patternNumbers = Array.from(
pattern,
function (char) {
return char in this.map ?
this.map[char] :
this.map[char] = this.getId();
},
builderFactory(),
);
return string.split(" ").every(
function (word, i) {
const number = word in this.map ?
this.map[word] :
this.map[word] = this.getId();
return number === patternNumbers[i];
},
builderFactory(),
);
}

Why aren't you using Go yet, user?

Attached: go-peek.png (179x300, 19K)

in python this is just
>>> circular = lambda l,n:l*n
>>> circular([1,2,3],5)
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]

static IEnumerable Circular(IEnumerable items {
while (true) {
foreach (var item in items) {
yield return item;
}
}
}

static void Main(string[] args) {
IEnumerable items = new List() { 1, 2, 3 };

var sequence = Circular(items).Take(10);
}

FTFY

>greedy execution
lmao

I use the idiomatic bracing style for the language being used because stylistic loyalty is for hobbyist devs.

I can't into go routines. I think synchronously and have synchronous problems.

Because Go doesn't allow me to perform memory allocation optimisations.

Are those {}s for single things necessary in C#? Kinda sad

it's different.
in his code, when taking 10 the result is:
1,2,3,1,2,3,1,2,3,1 -> only 10 numbers
your code replicates the array by a number

see no

It should be pretty easy these days. :)

cd serenity/Toolchain/
bash BuildIt.sh
source UseIt.sh
cd ../Kernel/
./makeall.sh
./run

Attached: 1560384674333.png (539x539, 285K)

>i'm stylistically loyal to ENTERPRISE because stylistic loyalty is retarded

Attached: 1562575877342.gif (500x382, 167K)

C# is just like C/C++.
Single statement block doesn't need {} at all.
But some will try to murder you if you omit them.

It's not but C# doesn't understand shadowing :^)

if (true)
{
int x = 34;
}

int x = 11; // error

Oh that is based as fuck. Time to fire up my Lubuntu VM.

Thanks, Kling. You should hang out on the discord more.

Attached: 1522882308682.jpg (990x682, 49K)

Why aren't you learning the necessary math right now? This guy explains it so that even a brainlet can understand it!

Attached: 3b1b.jpg (900x900, 75K)

it's fine

DISCORD TRANNY

You misspelled "maths".