/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1473271813941.jpg (1015x1505, 502K)

Other urls found in this thread:

projecteuler.net/problem=85
streamable.com/wfxwu
en.wikibooks.org/wiki/Haskell
twitter.com/AnonBabble

What are YOU working on, OP?

Attached: 1549817598176.png (1920x1080, 2.5M)

Why read the magic wizard Scala book /dpt/? It is creaky and old, no longer relevant in this brave new age.

...

basically this, 2hu fag cheated last time. I saw you, so I posted a touhou.

Attached: 1424433907489.png (1021x680, 205K)

touhou isn't an anime though

>What are you working on, Jow Forums?
15 channel pwm/servo-controller
>why 15?
because one channel is occupied by the usb port
>why usb?
because you have usb and an ftdi everywhere. i2c might to come

Attached: IMG_7308.jpg (3000x2000, 623K)

I know but I don't have a >muh touhou dpt image.

A bunch of the patterns in the book are out of date or became common sense instead of being recognized as a pattern (e.g. frameworks). There are other patterns only applicable to functional programming, but they aren't talked about much.

here u go

Attached: 1556054806996.jpg (1200x1100, 375K)

I love JavaScript! It rocks!

Attached: 7b02d5a4e0567c3a9f8cb3abeda79ac5.jpg (908x1210, 220K)

fake image. There is no legacy captcha. Never have been.

I'm too stupid for Lisp.

Attached: .jpg (600x500, 145K)

18 NAKED IMPROPERLY INFERRED TYPES OUT IN THE YUARRD

There's a whole of bunch touhou programming images, it's not what I meant. I was talking to touhou/yuno OP.

Attached: 1484619016074.png (720x660, 390K)

Mostly fucking around on Reddit and GitHub right now. There's this idea I have but I don't see the point if there's already been people working on it for years.

is literally admitting to using reddit a bannable offense? it should be.

no, not on Jow Forums anyway. maybe in the mod hangout of /a/, if you act like a fag at the same time.

...

Where are you getting these cute doll pics?

no, nor should it be

Project Euler 85 in F#.
projecteuler.net/problem=85
The code is ugly, bigints aren't needed, sue me.

Analysis: Marking a rectangle in the grid is essentially the same as picking 4 lines.
Imagine a 3x1 grid, you draw it with 4 vertical lines (3+1) and 2 horizontal ones.
Drawing a rectangle requires 2 horizontal lines, so your horizontal lines are static.
There are now 4 choose 2 (binomial coefficient) = 6 ways to draw the vertical lines to get your rectangle.
I.e. 0011, 0101, 0110, 1001, 1010, 1100.
To get how many ways there are to draw a rectangle in a 2d grid, just multiply the ways to select horizontal lines with the ways to select vertical lines (in the 3x1 example there's only 1 way to select horizontal lines anyway).
So for the 3x2 example we get: 4 choose 2 * 3 choose 2 = 6 * 3 = 18, so our formula checks out with the example.
So just loop through all combinations of x, y and keep the current best result.

let factorial n =
[1I .. n]
|> List.reduce (*)

let combinationsNoRepetitions n r =
(factorial n) /
((factorial r) * (factorial (n - r)))

let rectsInGrid (x, y) =
(combinationsNoRepetitions (x + 1I) 2I) * (combinationsNoRepetitions (y + 1I) 2I)

let euler85 =
let target = 2_000_000I
let rec findClosest area bestDiff lst =
match lst with
| [] -> (area, bestDiff)
| (head : bigint * bigint :: tail) ->
let x, y = head
let rects = (rectsInGrid (x, y))
let diff = abs (target - rects)
if (diff < bestDiff) then
findClosest (x * y) diff tail
else findClosest area bestDiff tail

List.allPairs [3I..100I] [3I..100I]
|> findClosest 999_999_999I 999_999_999I

>There is no legacy captcha. Never have been.
What?

Still working on NES Emulator in HolyC, finally added sound emulation.

streamable.com/wfxwu

Uninstall Temple OS
install Haiku OS

I can't believe Terry is alive.

Nice

Dead OS

Why do I waste time on details that don't matter?
Just spent 20 mins deciding how to name a new CONSTRAINT

Naming is the hardest problem in computer science.

what is this supposed to do anyways?

(run k) is a variadic function accumulating strings
unfortunately you have to specify the length in advance (through k) but you could use a type class to infer that.

lol k. where do I find a list of these things that are found in haskell e.g gadt, higher kinded types and whatnot?

How do I write an AI for a card game? Do you have any good books/resources? Any algorithm for making decisions?

en.wikibooks.org/wiki/Haskell

this is semi advanced btw, you can always go back to more verbose pattern matching

There are too many approaches. The simplest will be some sort of min-max decision tree. Depending on the complexity of the game, it may be cost-prohibitive to search exhaustively, so you may need to limit the depth or use some simpler heuristic. There exist more sophisticated game learning methods, but they involve either solving the game or applying a deep learning network to learn from a huge number of examples.

Attached: aibook.jpg (631x832, 50K)

If your game is simple just have it do random moves. Maybe see if it can win outright and play the winning move if it has one, but otherwise just do random stuff.

the copy I have is 3rd edition too but it's a different cover and it sucks. I like that one better.
what the fuck norvig?

>but otherwise just do random stuff.
please no, there's no faster way to get people uninterested in your game than a non-AI in a strategic game.

That’s the cover from the softcover edition sold to pajeets and canadians

These keep getting creepier and creepier...

I see, mine has a bunch of random circuit "leads" in the form of a brain that make no sense and it sucks.

Attached: artificial-intelligence-a-modern-approach-400x400-imadszfmcxh4cpcy.jpg (314x400, 38K)

If you have a game like hearthstone you can pretty much just run a greedy algorithm and it will be good enough. Like it should try to spend all of its mana. If there are multiple ways to spend all your mana then pick one at random. Any strategy beyond that won't really be programmable unless you use machine learning.

I bought that off amazon and I think it shipped from china or india or something years ago. The book is publisher whored out I think.

Oh I thought you were referring to this one. They sure have a lot of covers for the same edition.

Attached: 43BD253E-51CA-4D19-993E-76D0BBA2C5B6.jpg (481x648, 120K)

>Any strategy beyond that won't really be programmable unless you use machine learning.
imagine being this brainlet
ML is like the new JS, where people suddenly just forget how to actually make things.

Poor Turing

I guess you have never played Hearthstone? How do you plan on programming an AI that's capable of playing rush decks, control decks, and decks with really awkward strategies and win conditions like freeze mage? How about Mill rogues? Or the priest deck where you turn healing into damage, saving up all healing spells for a huge damage combo?
The closest you could get with a general strategy is probably defining a heuristic for "value", involving board control and probability of getting lethal.

There is nothing stopping you from writing custom AI for each opponents deck. It’s not even hard if you write your AI in a modular way which enables you to replace default strategies dynamically.
Ignoring that, there are more sophisticated things you can do than just greedy. You don’t want your AI wasting powerful cards on garbage threats, so you can add wights in to deincentive bad plays.

>random circuit "leads"
>circuit "leads"
>"""""""""""""
EE getting into software here and your comment shorted my brain's circuit traces

>using reddit
based

What would you call it, engineer? Wires, connections, random lines in the form of a pattern?

I'm gonna go ahead and guess that he would call them circuit traces.

ok, explain how leads is wrong though.

Is this valid in c and if so what does it return
int foo = 1;
return *&foo;

1, I think. Reference and dereference. NOP.

You can do *& as many times as you want and it doesn't change the meaning at all.

Take the address of foo, then dereference that address to get the variable.
&* and *& right next to each other cancel out.

I'm well familiar with C and want to learn C++.
Any good resources for this?

Stay away from that shit-heap of a language. There is absolutely no good reason to use it.

C++ is too far gone, there used to be books but they're obsolete. Just learn to write in C++68.

but c++ is the most powerful language

b-but games!

That's what I've been hearing a lot lately, but I think it would still be useful to organize bits of codes in an object/class structure.

Any C-like alternatives you would suggest?

It's 2019.

Game are written in JS now.

Just use a struct, idiot.

C# is actually closer to C than C++

You can always use C# and compile to native binaries too.

Nice.
Is mono any similar to gcc/clang/any other CLI compiler as far as actual compilation goes?

Competitive programming competition tomorrow, grinding the problems last minute. Any tips?

Attached: 1522339720787.png (368x379, 221K)

Yeah, but why would you want to? Native binaries that require massive run time environments that only run on a couple of kinds of machines and OSes.

I bet dotnet core even performs better than the standard dodnet framework.

I'm not sure actually.

You can use microsoft's own compiler though for dotnet core.

>Yeah, but why would you want to?
You can beat the cost of JITing code on launch.
>I bet dotnet core even performs better than the standard dotnet framework.
I gather that is probably true.

>tfw not one of you senpai-tachis noticed by code:
I-I guess I have to write cuter code, somehow...

Does it work for Linux/WINE?

Sorry, this is a no M$ general.

I read your code, stop beggining for attention.

monogame compiles to native and runs on windows, linux, android, iOS, PSVita, and consoles (BSD).
It prevents things like ILDasm and overhead from initial JIT.
I think it is supported by corert as well

Yeah, dotnet core works natively on linux.

Sweet, I'll have a look at it.

What is the difference between mono and dotnet core?

Sorry fren, I'm a bit low on frens right now.

Natively usually means something more specific. Dotnet core is still JIT compiled on Linux.

Mono is 3rd party, dotnet core is an open source initiative lead by Microsoft.
Mono has more history behind it, Unity runs on mono for example.
But Microsoft is investing a lot in dotnet core right now.
Oh and they are both .NET runtimes if that's not clear.

If you really want to use that particular framework and the framework doesn't support netcore, sure. But netcore would run better. The kind of native code you get with these kind of things is not the kind of stuff that makes use of the benefits of native code. It was fine when your options were "use this or tell your players to try WINE", but even the LLVM bindings guys stopped bothering with C# once dotnet core got good.

>Dotnet core is still JIT compiled on Linux.
No, you can choose to compile it directly to a native binary that does not need to be jitted. mono can do the same.

I'll be damned. I didn't know CoreRT had come that far.

Yep. pretty neat.

You just went full retard, son.

Attached: 1548691717239.png (504x504, 95K)

I still can't fucking do this
fizzBuzz x
| x `mod` 15 == 0 = "FizzBuzz!"
| x `mod` 5 == 0 = "Buzz"
| x `mod` 3 == 0 = "Fizz"
| otherwise = show x

main :: IO ()
main = do
fizzBuzz [1..100]

how do I make the fizzBuzz function accept a list?

map the elements of the list to fizzBuzz or pop one element at a time and call fizzBuzz again on the remaining list?

You don't need to make FizzBuzz accept a list, it's fine as it is. Just use List.map/iter (whatever Haskell's version is) to run FizzBuzz on the entire list.

Map it over that list.

Leads describe only the terminal points of contact in an electrical circuit. Those 2 red and black wires coming out of multimeters, the metal tips at the end, those are the leads.

When talking about PCB electronics, those little copper (sometimes aluminum) lines etched into the fiberglass circuit board, are referred to as traces.

The moar u no

Holy shit I did it
fizzBuzz x
| x `mod` 15 == 0 = "FizzBuzz!"
| x `mod` 5 == 0 = "Buzz"
| x `mod` 3 == 0 = "Fizz"
| otherwise = show x

main :: IO ()
main = do
n

Attached: 1554775804094.jpg (640x780, 108K)

have sexual relations

So is C really the best low level language? Can anything else compete?

>Leads describe only the terminal points of contact in an electrical circuit
Wrong, but thank you engineer, the times I studied this shit in high school physics those traces were called leads. Look up the definition you retard.

Depends on what you are working on?
like games on the gameboy had to use assembly.
C was too bloated

Nim, Rust, D's BetterC