[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can half of /g/ even into programming? If you roll and can't

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 299
Thread images: 31

File: programming challenges 2.png (378KB, 1450x1080px) Image search: [Google]
programming challenges 2.png
378KB, 1450x1080px
Can half of /g/ even into programming?
If you roll and can't provide code for your number, you don't belong on /g/.
>>
>simple math is hard
>>
rolling for pong
>>
Rolling is half the battle!

>Rolling
>>
>>56170216

lel
>>
Rollerino
>>
>>56170078
why do I even bother replying I'm just gonna get one that takes a long ass time. eh roll
>>
>>56170078
Challenge accepted.
>v2
get with the times, OP
>>
penis
>>
>>56170450
>doesn't specify board size
well 1x1 board for me it is
>>
qass
>>
File: Linus JUST.png (121KB, 597x705px) Image search: [Google]
Linus JUST.png
121KB, 597x705px
>45 minutes since OP was posted
>nobody has posted any code yet
Jesus Christ, it's worse than I thought.
>>
fuck it
>>
>>56170477
>linked list
rr
>>
Rolling to prove my education is worth a damn
>>
Fuck you. Im nearly done with a four month project and the last thing i need is a faggot telling me whether I belong here. Fuck you. I knew what pointers were before strauss did.
>>
>>56170520
Fuck fizzbuzz, I've already done that.
>>
>>56170078
roll
>>
>>56170078
Rolling
>>
File: penis.png (5KB, 526x159px) Image search: [Google]
penis.png
5KB, 526x159px
>>56170515
i actually did this a while ago with my own shitty algorithm

http://pastebin.com/YTLwsQKC

should probably finish my shunting-yard + RPN version
>>
>>56170289
used javascript. i'm not sure if it's 100%, but it's okay-ish

function num2text(n) {
var ret = '';
var a = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty'];
a[30] = 'thirty';
a[40] = 'forty';
a[50] = 'fifty';
a[60] = 'sixty';
a[70] = 'seventy';
a[80] = 'eighty';
a[90] = 'ninety';
a[100] = 'hundred';
a[1000] = 'thousand';

if (isNaN(n)) {
console.log('fuck you');
return;
}
if (n < 0) {
ret += 'negative ';
n = n * -1;
}
if (n <= 20 && n > 0)
ret = a[n];
else if (n >= 100) {
ret += a[(n+'').charAt(0)] +' '+ a[(n>=1000?1000:100)];
n = n - (n+'').charAt(0) * (n>=1000?1000:100);
if (n > 99)
ret += ' '+ num2text(n);
else if (n > 0)
ret += ' and ' + num2text(n);
} else
ret += a[(n+'').charAt(0)*10] + ((n+'').charAt(1)==0?'':'-'+a[(n+'').charAt(1)]);
return ret;
}
>>
>>56170078
*cums inside your waifu*
>>
>>56170789
oh, and i couldn't be bothered to make it go higher than 9999.
>>
>>56170472
I've never used pygame before so it works but it just jumps around because there isn't a delay.
kek
>>
Malbolge

 (=<_^^!n[}4j81CTvRQ>OMo^KJH#GE~%CB@RQa|^tyxwZHGV3kSRRm,,MLLg'&$coaCB|W@y=w<vP87Mpp]2[G/.WV,AdEb&`r$#"![;k32UT/4dsP=NLn,+l)('&%$#c!~}v<^sxwpotm3Tjohmf,dihg`edcba`Y}]?UTSXWPOs6LQPONMLKDCgGF?>bB;@?8\<|4Xy70543,P0/(-&+*#Gh~%|#z@x}|u;\xqputsl2pongfe+cbafe^]#a`BXW\UyYX:VONSLp3IHMLKJCg*F?DC<;_?!7[;:9876543210/.n,%$)('~D$#cy~}|uts9wvuWsrqj0nPlkd*hgI_d]b[!_^]\[TYXWVUNrR4PINMFjJ,HAe(>CBA@98\}543W7w5.-2+O/.-m+$Hi'~%${Ab~w={z\xwvo5slkjohg-kjLbg`_%]\a`Y^W{UTYXQVUTMqQ3Im0LKJIBAe?D=B;_?>=};4X2165.32+Op('&Jk)"!E%$d"!~}v<]sxqvo5Vlqj0hmlkjcb(f_^cba`YX|?UTSRWVOs6RKJImML.iCHAFE>bBA#?>=65:3W76/.-210)Mn,+$H"!&}$#"y?}|^zsxqvo5sUqpohg-kMcbg`&Gcba`_X|?UTYXQutTSRQPImM/EDIHGFE>bBA@?>=6;4X876543s1*N.',%*)(!E%${z!x>_{tyrwvutsl2jinmfkdihg`&Gcba`_X|\[=SXQVUNrR4PIHMLEiI+AF?cC<A:?>=<;:3W765.321*N.-,+k#GFg%$#z@~}|{zyxwvutsrqponmOkjcha'edF\"Z_^W{[TYRvVUT6RKo2NGLEJCgGFED&BA@9]=<549816/S@ 
>>
>>56170078
Rollan
>>
>>56170078
rolling faggots, need some time away from my android trojan rat anyways.
>>
>>56170078
rolando
>>
>>56171153
what the fuck does 53 mean?
rolando again
>>
File: flat,800x800,070,f.jpg (110KB, 800x800px) Image search: [Google]
flat,800x800,070,f.jpg
110KB, 800x800px
>2 hours in
>33 replies
>1 shitty javascript solution
>1 unreadable garbage


Stay classy, /g/.
>>
>>56170078
I'm gonna get some bullshit red thing right?
>>
>>56171186
// 086 Temperature converter
import java.util.Scanner;
import java.lang.Math;
public class TConverter
{
public static void main(String args[])
{
Scanner cIn = new Scanner(System.in);
String[] tempTypes = {"F", "C"};
System.out.print("Enter temperature (eg. 35C): ");
String inTempStr = cIn.nextLine();
cIn.close();
String inTempType = inTempStr.substring(inTempStr.length() - 1);
double inTempNum = Double.parseDouble(inTempStr.substring(0, inTempStr.length()-1));
String outTempStr = "[ERROR]";
if (inTempType.equalsIgnoreCase(tempTypes[0]))
{
outTempStr = String.format("%.1f%s", (inTempNum - 32) * 5/9, tempTypes[1]);
}
else if (inTempType.equalsIgnoreCase(tempTypes[1]))
{
outTempStr = String.format("%.1f%s", inTempNum * 9/5 + 32, tempTypes[0]);

}
System.out.println(inTempStr.toUpperCase() + " = " + outTempStr);

}
}
>>
>>56171199
Great now post your Wolfenstein 3d-style ray caster
>>
File: a62.png (262KB, 680x661px) Image search: [Google]
a62.png
262KB, 680x661px
>>56171210
If I could do that, I wouldn't be unemployed shitposting on /g/, faggot.
>>
>>56171210
Kek, roll
>>
File: 1327977909107.jpg (60KB, 600x411px) Image search: [Google]
1327977909107.jpg
60KB, 600x411px
>>56170078
hmm
>>
>>56170078
Roll
>>
>>56170078
Roll
>>
I have nothing better to do
>>
>>56171322
λ let binom n m = fromIntegral $ product [n-m+1..n] `div` product [1..m]
λ let triangle n = [ [binom m i | i <- [0..m]] | m <- [0..n] ]
λ mapM_ print $ triangle 5
[1]
[1,1]
[1,2,1]
[1,3,3,1]
[1,4,6,4,1]
[1,5,10,10,5,1]


yawn
>>
>>56171337
λ let isPalin (show -> n) = n == reverse n
λ isPalin 123
False
λ isPalin 12321
True


yawn again
>>
File: voronai.png (25KB, 1920x1280px) Image search: [Google]
voronai.png
25KB, 1920x1280px
>>56171348
Already did this one

import Control.Lens
import Control.Monad ((<=<), replicateM, liftM3)
import Control.Monad.Random

import Data.Array.Repa
import Data.Array.Repa.IO.DevIL
import Data.List (minimumBy)
import Data.Ord (comparing)
import Data.Word (Word8)

voronai :: [(Double, Double, a)] -> (Double, Double) -> a
voronai points d = minimumBy (comparing $ distance d) points ^. _3
where distance (a,b) (c,d,_) = (a-c)^2 + (b-d)^2

render :: FilePath -> (Int, Int) -> ((Double, Double) -> Word8) -> IO ()
render p (w,h) f = runIL . writeImage p . Grey <=< computeP $
fromFunction (ix2 h w) (\(Z:.i:.r) -> f (r/.w, i/.h))

main = render "voronai.png" (1920, 1280) . voronai =<< replicateM 100 rand
where rand = liftM3 (,,) getRandom getRandom getRandom

(/.) :: (Integral a, Integral b, Fractional c) => a -> b -> c
x /. y = fromIntegral x / fromIntegral y
>>
>>56171186
/G/ is a general technology sub not a programming sub.
>>
I'm new, is this ok?
public class Main 
{
private static int state = 0;
private static double d;

public static void main(String[] args)
{
while (true)
makarovChain();
}

public static void makarovChain() {
d = Math.random();
if(state == 0) {
if(d <= 0.50d) //% chance of setting state to B
state = 1;
else //remaining % chance of keeping state.
state = 0;
}
else if(state == 1)
if(d <= 0.50d) //% chance of setting state to A
state = 0;
else //remaining % chance of keeping state.
state = 1;
try {
Thread.sleep(200); //sleeps thread to allow time to observe results
} catch (InterruptedException e) {
e.printStackTrace();
}
String output = (state == 0) ? "A" : "B"; //0 == A, 1 == B
System.out.print(output + " ");
}
}
>>
>>56171365
λ import Network.NTP.Control
λ res <- queryHost "de.pool.ntp.org" $ opVariables [Clock]
λ let Just Variables { clock = Just t } = readVariables res
λ print t


untested, can't be bothered installing this package
>>
>>56171401
There, I learned something new while looking up this one - now I can stop. (The code is simple enough that the implementation is pretty much just transcribing an example pseudo code into C or any other imperative language with arrays, so feel free to do it yourself)
>>
99 pls I want to be punished
>>
File: IMG_20160809_090722.jpg (102KB, 615x768px) Image search: [Google]
IMG_20160809_090722.jpg
102KB, 615x768px
Roll
>>
>>56170078
Ror
>>
rolling cuz i should work
>>
gimmme
>>
>>56170078
roll
>>
>>56171737
'use strict'
let palindrome = function(string) {
let halfway = string.length / 2;
let end = string.length - 1;
for (let i = 0; i < halfway; i++) {
if (string[i] !== string[end]) {
return false
}
end -= 1;
}
return true
}

palindrome('racecar')
>>
>Reinventing the wheel: The Movie

I don't want to do any of these, because I feel I'd be wasting time.
>>
>>56170078
fuck you
>>
>>56172099
i'll be waiting for that wolfenstein 3d application anon
>>
>>56170078
rolllll
>>
But I already do enough software development at work.
>>
>>56172105
well shit
>>
>>56171850
90% of these shouldn't take more than 10 minutes, pleb.
>>
>>56172150
meant for >>56172089
>>
>>56170078
let's do this shit in ruby
>>
R o l l
>>
>>56172124
Wow that was so hard
from random import choice
name = raw_input("Enter your name : ")
print "Rock breaks Scissors, Scissors cuts Paper, Paper beats Rock"
rps = ['r','p','s']
u = 0
v = 0

#Here is the while loop, which will continue till break. The below text is intended to fit into the while loop.
while 1:
print "R: Rock, P: Paper, S: Scissor"
user = raw_input("Enter your choice among the three : ")
user = user.lower()
py = choice(rps)

if user == py:
print "You chose ",user
print "I chose ",py
print "Hence a Tie!"

elif user == 'r' and py == 's':
print 'You entered Rock. I had Scissor. You win!'
u+=1
elif user == 'r' and py == 'p':
print 'You entered Rock. I had Paper. You lose!'
v+=1
elif user == 's' and py == 'p':
print 'You entered Scissor. I had Paper. You win!'
u+=1
elif user == 's' and py == 'r':
print 'You entered Scissor. I had Rock. You lose!'
v+=1
elif user == 'p' and py == 's':
print 'You entered Paper. I had Scissor. You lose!'
v+=1
elif user == 'p' and py == 'r':
print 'You entered Paper. I had Rock. You win!'
u+=1

if v == 5:
#Print computer wins the game
print "Computer wins!"
break
#Provide proper conditions for elif in case user getting 5 points:
elif u == 5:
#Congratulate the user on winning along with their name
print name + " wins!"
break
>>
>>56170078
reroll
>>
>>56172275
No rerolls, fucker. If you can't do the original challenge you shouldn't be on /g/.
>>
I don't code
>>
>>56170078
Roll
>>
>>56170078
challenge me neegus
>>
i probably won't do it since i have the slows
>>
Hail satan
>>
I can do most of the green ones.

Here's the factorial:
#include <stdio.h>

int fact (int n);
int main (void)
{
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("fact(%d) = %d\n", n, fact(n));
return 0;
}

int fact (int n)
{
if (n <= 1) {
return 1;
} else {
return fact(n - 1);
}

/* :^) */
>>
>>56172412
My code is missing a } at the end. Sorry for that.
>>
File: viper.png (162KB, 305x343px) Image search: [Google]
viper.png
162KB, 305x343px
The time has come.
>>
Rolly
>>
>>56172402
public class bmi
{
public static void main(String[] args)
{
Scanner scan= new Scanner (System.in);
System.out.println("Enter your weight (in pounds)");
double lbs=scan.nextInt();
System.out.println("Enter your height (in inches)");
double in=scan.nextInt();
double ans=((lbs*703)/(Math.pow(in, 2)));
System.out.println("Your BMI is "+ans);
}
}
>>
File: ulam.png (188KB, 1024x722px) Image search: [Google]
ulam.png
188KB, 1024x722px
>>56172167
I did it!
>>
>>56172610
good job anon! looks nice
>>
>>56172226
It looks like it can be done without all the repetition, but I don't know how.
>>
>>56172412
it should be
/* ... */
} else {
return (n * fact (n - 1)); /* not just fact(n - 1) */
}
/* ... */
>>
The code for #64

a, b = 1, 1
fib = [a]

# get first 1000 fibonacci numbers
for i in range(1000):
a, b = b, a + b
fib.append(a)

# get first digit
digits = []
for num in fib:
while num / 10 != 0:
num = num / 10
digits.append(num)

# add numbers to a dictionary
count = {}
for num in digits:
count.setdefault(num, 0)
count[num] += 1

# print result
print count


The output:

{1: 301, 2: 177, 3: 125, 4: 96, 5: 80, 6: 67, 7: 57, 8: 53, 9: 45}
>>
>>56170078
roll
>>
>>56170789
>
if (isNaN(n)) {
console.log('fuck you');
return;
}


kek
>>
Rollo
>>
rollinn
>>
File: ulamcode.png (267KB, 1490x1110px) Image search: [Google]
ulamcode.png
267KB, 1490x1110px
>>56172630
thank you, it was actually really fun to program
>>
>>56172790
i just realise that
n.times{ a << (1..n).to_a.map{|x| false} }

can be written as
n.times{ a << [] }

because ruby is awesome
>>
File: 5.png (196KB, 1048x1020px) Image search: [Google]
5.png
196KB, 1048x1020px
now with emoji
>>
>>56172884
that's pretty tight
>>
>>56170078
Fuck you and your codemonkey elitism. Some of us like hardware more and all your bullshit pajeet code won't mean a fucking thing without working hardware to run it on.

Programmers always think they're the end-all be-all of computer knowledge. You are nothing. They can literally train retarded poo-in-loos to do it on paper. Fuck off, it's not impressive and it doesn't say shit about your skills as a person.

"Hurr durr, if you can't mill a tree down to lumber all by yourself then you don't belong on /DIY/"

Kill yourself.

/Salt
>>
>>56172884
kys
>>
>>56172908
>calling us codemonkeys
>clearly can't do any of these tasks
>>
>>56170078
rollan
>>
>>56172917
>Implying I give a shit
>Using the Appeal To Accomplishment fallacy

Get fucked.
>>
>>56172920
wew lad
main() {
int i;
for (i = 0; i <= 100; ++i) {
if (!(i % 15)) printf("fizzbuzz");
else if (!(i % 3)) printf("fizz");
else if (!(i % 5)) printf("buzz");
else printf("%d", i);
printf("\n");
}
}
>>
>>56170078
rollz
>>
>>56170078
Challenge accepted
>>
>>56172941
>doing it the pleb way
pajeet detected
>>
File: 1471477048757.png (549KB, 1920x1080px) Image search: [Google]
1471477048757.png
549KB, 1920x1080px
>>56170078
>not the v4
Rolling
>>
>>56170078
roll
>>
how is an ascii digital clock considered easy?
>>
might as well
>>
I am C beginner
rolling
>>
>>56170078
roll
>>
>>56173066
wow, that is interesting. I would maybe need more than 1 week or forever.
>>
>>56173380
int factorial(int a)
n = 1;
for(int i = 2; i <= a; i++) n *= i; return n;

difficulty on these challenges is random as FUCK
>>
>>56170078
I'm bored
>>
>>56173048
How is it not?
>>
>>56170078
Java -> bob
>>
>>56173025
rolling on the v4 since i only got crap like factorial and "typing speed"(seriously?
>>
>>56170216
>>56170226
Well you didn't provide your solution to this tinkering problem
>>
rolllll
>>
//calculate overlapped space of 2 squares

package main

import (
"fmt"
)

type square struct {
x int
y int
size int
}

func main() {
s1 := square{x: 100, y: 200, size: 100}
s2 := square{x: 150, y: 250, size: 100}
s3 := square{x: s2.x, y: s2.y, size: 0}
fmt.Println("x : ", s3.x, "y : ", s3.y, "overlap : ", ((s1.x+s1.size)-s2.x)*((s1.y+s1.size)-s2.y))
}
>>
>>56173558
>58.
how bout we reroll
>>
>>56172930
you obviously give a shit seeing as how this thread triggered you.
>>
gonna roll
not program
shrug my shoulders and carry on shitposting
and theres not a thing you can do about it :)
>>
>>56173025
how the fuck is 122(Design a Game Engine in Unity easy? at the very least you have to learn how unity works. Dijkstra's on the other hand seems easy, seeing as how an original solution doesn't require understanding why the algorithm works.
>old school demo effect(43) is easy
depends highly on if you've done graphics programming like that before or not
>>56173446
rerolling
>>
>>56170078
they see me rollin they hatin
>>
Do you think there are programmers earning big bucks that do not know how to solve these?
>>
Give me one that will affect my confidence negatively.
>>
>>56170078
ROOLLLLING
>>
>>56173812
write a linux driver for CUDA
>>
Raeioull
>>
>>56173845
affect it. not completely kill it off man.
>>
>>56173812
Write a vulkan program
>>
File: 1460241741815.png (1MB, 1000x1400px) Image search: [Google]
1460241741815.png
1MB, 1000x1400px
Do it for hime
>>
>>56170078
fuck off with this autistic shit, no one here gives a fuck about it or doing any of the stupid projects in it, hence why everyone always rolls in these threads but never posts any code.

people have better things to do with their time and so should you, Now go back to posting your daily "16 gigabyte of ram meme" thread at least it was partially funny.
>>
>>56170078
Roll
>>
File: hmmmhmmmsweethartm240.png (65KB, 205x239px) Image search: [Google]
hmmmhmmmsweethartm240.png
65KB, 205x239px
>>56174511
is a baby scared he'll fail hmmmmmmmmmmmmmm
>>
>>56172610
>>56172790
That looks pretty cool. I'm going to make one too, but this time with image generation in Rust.
>>
>>56172790
Which editor is that, BTW? Atom?
>>
fuck it, I'll roll
>>
rollandro
>>
here we go
>>
>>56173453

I didn't realize it was a timed test me in fuhrer.
>>
>>56170078
>56170078
ill bite
>>
>>56174768
Program is finished, now I just have to install the correct build tools to compile the image crate.
>>
Wew lad
>>
>>56170078
Rolling something easy
>>
>>56170078
roll
>>
>>56175175
Argh. Fuck Winblows, just fucking compile.
>>
>>56170078
Roll
>>
>>56175580
static Func<int, int> Factorial = x => x <= 1 ? 1 : x * Factorial(x - 1);
>>
>>56173025
Roll again on this newer one.
>>
>>56175637
Fuck that I wanted something I could do in a couple hours tops.
>>
>>56170078
roll
>>
>>56170078
Roll
>>
>>56175653
static ulong maxfactor(ulong n)
{
unchecked
{
while (n > 3 && 0 == (n & 1))
n >>= 1;
uint k = 3;
ulong k2 = 9, delta = 16;
while (k2 <= n)
{
if (n % k == 0)
{
n /= k;
}
else
{
k += 2;
if (k2 + delta < delta)
return n;
k2 += delta;
delta += 8;
}
}
}
return n;
}


number 53 was far easier.
>>
>>56170078
>59. Sound Synthesis (sine, square, sawtooth,…)
>sine, square, sawtooth
>hard

Seriously? I’m currently working on vocal synthesis, if you believe this thing is hard, well I have bad news for you.
>>
>>56170078
roll
>>
Rolling and doing it tomorrow cause it's 3am
>>
>>56176353
Lame, re-roll
>>
>>56170078
rip me
>>
>>56176120
Nice bragging faggot. Every piece code posted here Is bettering /g/. Everyone was a beginner once. Or were you able to explain pointers out of the womb?
>>
>>56170078
Nope! I just come here to shitpost. :^)
still rolling.
>>
rooooooooooooooool
>>
>>56176541
nah
>>
>>56170078
Not a pajeet I swear!
>>
all i can do actually is an factorial function
pls show some mercy
>>
>>56171244
This was above my head, retrying
>>
>>56173845
Im ded.
Thanks.
>>
rollan
>>
>>56170078
Be kind to me.
>>
>>56173025

rolling
>>
File: number17.png (48KB, 1500x1020px) Image search: [Google]
number17.png
48KB, 1500x1020px
>>56177317
I don't understand what should I calculate.
>>
>>56170078
I really want to use it as a sort of understanding a language.
Is it an incremental list?
I really want a list that becomes more difficult the higher your rise.
At least I would know where I should polish my skills before continuing my path.
>>
>>56170078
I don't even have to roll, I have absolutely no programming skills
>>
>>56170078

Manly rolling..
>>
>>56175372


#include <cstdio>
#include <cstdlib>
#include <cmath>

typedef struct point2D{
float x;
float y;
};

void translation2D(point2D* ptsarr, int npts, point2D pt)
{
for (int i(0); i < npts; i++)
{
ptsarr[i].x += pt.x;
ptsarr[i].y += pt.y;
}

}

void scale2D(point2D* ptsarr, int npts, float scale, point2D origin)
{
for (int i(0); i < npts; i++)
{
ptsarr[i].x = origin.x + scale * (ptsarr[i].x - origin.x);
ptsarr[i].y = origin.y + scale * (ptsarr[i].y - origin.y);
}
}

void rotate2D(point2D* ptsarr, int npts, float rotation, point2D origin)
{
for (int i(0); i < npts; i++)
{
float distance = sqrt((double)((ptsarr[i].x - origin.x) * (ptsarr[i].x - origin.x) + (ptsarr[i].y - origin.y) * (ptsarr[i].y - origin.y)));
double angle = atan2((double)(ptsarr[i].y - origin.y), (double)(ptsarr[i].x - origin.x)) + rotation;
ptsarr[i].x = origin.x + distance * cos(angle);
ptsarr[i].y = origin.y + distance * sin(angle);
}
}


[\code]

part 1
>>
>>56180520
part 2

int main() {
bool brepeatinput = false;
do {
brepeatinput = false;
printf("Input the number of points of the polygon: ");
int npts;
scanf("%i", &npts);

point2D* ptsarr = (point2D*) malloc(sizeof(point2D) * npts);



printf("Write the points of the polygon in the format 'x,y'. For example '1,2 3,4 6,-20' for a 3 point polygon\n");
for (int i(0); i < npts; i++)
{
char t;
scanf("%f", &ptsarr[i].x);
scanf("%c", &t);
scanf("%f", &ptsarr[i].y);
}



bool brepeat = true;
do {
for (int i(0); i < npts; i++)
{
printf("x= %f, y= %f\n", ptsarr[i].x, ptsarr[i].y);
}
printf("\n");

int choice;
printf("choose function translate, scale or rotate:\n 1- translate. \n 2- scale. \n 3- rotate.\n 4- input points \n 5- exit. \n");
scanf("%d", &choice);
switch (choice) {
case 1:
{
printf("Write in format x,y the translation vector. Example: '2,3'.\n");
point2D pt;
char t;
scanf("%f %c %f", &pt.x, &t, &pt.y);
translation2D(ptsarr, npts, pt);
break;
}
case 2:
{
printf("Write the scaling factor and and the point from wich to apply the scaling. Example '1.5 0,0' to increase polygon 1.5 times from the origin.\n");
float scale;
point2D origin;
char t;
scanf("%f %f %c %f", &scale, &origin.x, &t, &origin.y);
scale2D(ptsarr, npts, scale, origin);
break;
}
case 3:
{
printf("Write the rotation in radians and the point from wich to apply the rotation. Example '3.14 0,0' to rotate aproximately half a circle from the origin.\n");
float rotation;
point2D origin;
char t;
scanf("%f %f %c %f", &rotation, &origin.x, &t, &origin.y);
rotate2D(ptsarr, npts, rotation, origin);
break;

}
case 4:
brepeatinput = true;
brepeat = false;
break;
case 5:
brepeat = false;
break;

}
} while (brepeat);

free(ptsarr);

} while (brepeatinput);


return 0;

}
>>
>>56180562
part 3
I rolled 72 but I only did 2D stuff and that was already a chore. Also I don't know any graphics api so I did a text based program. It was good since i needed some (almost) pure C practice.
>>
>>56173025
roll
>>
Not going to do it anyway, so fuck you.
>>
'roll'
>>
`reroll`
>>
>>56170078
rollinating
>>
Frosted butts
>>
 
*roll*
>>
Big money
>>
I won't actually do it, but whatever
>>
jiljnsdvasdvnkl;
>>
>>56173025
79 get
>>
File: benis.png (26KB, 904x542px) Image search: [Google]
benis.png
26KB, 904x542px
>>56181278
are you fugging gidding me
>>
>>56170078
absinthe
>>
r0ll
>>
>>56176438
>>56176120
isn't it just
float squarewave(float time) return floor(time % 2);
float sine(float time) return sin(time);
float sawtooth(float time) return abs(time % 2 - 1) //this looks like \/\/\, \\\\\ would be time % 1
adjusting the frequency is easy enough by simply multiplying time with a factor.
>>
File: kden.png (326KB, 463x431px) Image search: [Google]
kden.png
326KB, 463x431px
K DEN FUCKER

ROLLAN
>>
>>56170078
rollan
>>
>>56170078
roll
>>
File: 1471641747975.jpg (861KB, 1956x2068px) Image search: [Google]
1471641747975.jpg
861KB, 1956x2068px
>>56181407
well fuck me, I'm gonna do this shit tho.
>>
>>56173025
>v4
roll
>>
>/g/ - codemonkeys
>>
>>56181533
reroll because it is bullshit
>>
rollan. give me something easy
>>
>>56181559
I'm too retarded for this. Rerolling.
>>
>>56181544
you better do that in assembly
>>
Rolllll
>>
I've already written this for my IRC bot.

hangman.ex
https://ghostbin.com/paste/94mf7

hangman/words.ex
https://ghostbin.com/paste/so2a5

Rerolling.
>>
Rolling but if it's going to take a lot of time fuck I concede.
>>
>>56173025
roll!
>>
>>56170078
roll
>>
>>56170078
rowl
>>
ok, so here's my fizzbuzz, it was way too simple so I wanted to make it a bit harder: write it in brainfuck.

>++++++[<++++++++>-]++++++++++[>++++++++++<-]>[>>+<<->>>>+++<<[>+>->+<[>]>[<+>-]<<[<]>-]>[-<+>]>>>[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<[>+++++++[>++++++++++<-]>.>>+++[>+++++<-]>[<+++++++>-]<.>++++[>++++<-]>+[<<+>>-]<<..[-]<<[-]<<-<<<<<<<+>>>>>>>]<[-]<[-]+++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>[-<+>]>+>>[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<[>++++++[>+++++++++++<-]>.>+++++++++[>+++++++++++++<-]>.+++++..[-]<<[-]<<-<<<<<<<+>>>>>>>]<[-]<[-]>[-]<<<<<<[>>>>>+>+<<<<<<-]>>>>>[<<<<<+>>>>>-]+>[<<<<<<[-]>>>>>->[-]],<[<<[>>>+>+<<<<-]>>>[-<<<+>>>]>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<-<<-]++++++++++.[-]<<<<]
>>
>>56181776
I don't like Solitaire, re-roll
>>
>>56170078
Rollin
>>
>>56180562
>>56180520
how do i use ur shitty program it doesnt make sense
>>
>>56181806
What's "tornado text/image"?
>>
>>56170078
Roller derby
>>
>>56181822
#include<iostream>
using namespace std;

int main()
{
int rows;
cout << "Enter the number of rows : ";
cin >> rows;
cout << endl;

for (int i = 0; i < rows; i++)
{
int val = 1;
for (int j = 1; j < (rows - i); j++)
{
cout << " ";
}
for (int k = 0; k <= i; k++)
{
cout << " " << val;
val = val * (i - k) / (k + 1);
}
cout << endl << endl;
}
cout << endl;
return 0;
}


wtf is a pascal triangle
>>
>>56181789
I forgot a debugging comma, here's the actual code:

>++++++[<++++++++>-]++++++++++[>++++++++++<-]>[>>+<<->>>>+++<<[>+>->+<[>]>[<+>-]
<<[<]>-]>[-<+>]>>>[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<[>+++++++[>++++++++++<-]>.>>
+++[>+++++<-]>[<+++++++>-]<.>++++[>++++<-]>+[<<+>>-]<<..[-]<<[-]<<-<<<<<<<+>>>>>
>>]<[-]<[-]+++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>[-<+>]>+>>[-]+>[-]<<[>-<[>>+<<-]]>>
[<<+>>-]<[>++++++[>+++++++++++<-]>.>+++++++++[>+++++++++++++<-]>.+++++..[-]<<[-]
<<-<<<<<<<+>>>>>>>]<[-]<[-]>[-]<<<<<<[>>>>>+>+<<<<<<-]>>>>>[<<<<<+>>>>>-]+>[<<<<
<<[-]>>>>>->[-]]<[<<[>>>+>+<<<<-]>>>[-<<<+>>>]>>>++++++++++<<[->+>-[>+>>]>[+[-<+
>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<
++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[
-]<<[-<+>]<-<<-]++++++++++.[-]<<<<]
>>
>>56181357
my $check = True;
my $count = 0;

for @*ARGS[0].lc.comb.sort {
$check = False unless $_ eq @*ARGS[1].lc.comb.sort[$count];
$count++;
}

say $check;
>>
File: ascii_circles.png (9KB, 160x663px) Image search: [Google]
ascii_circles.png
9KB, 160x663px
>>56180074

God fucking damnit, that was harder than I thought.. But entertaining.

Here's my Ruby solution for Nr. 74, "Draw a circle (let the user specify the radius) using ASCII Art", I also colourized it:

def ascii_cricle
# init
puts "Enter radius:"
r = gets.to_i
r = 3 if r < 3
colors = ["\e[1;36;40m", "\e[1;31;40m", "\e[1;32;40m",
"\e[0;32;40m", "\e[1;33;40m", "\e[0;36;40m"]
# we need 2 dots in each line (first/last line: 1 value)
x_y_values = (1..(2*r - 2)).to_a
# calulate radiants (0 to 2*Pi)
x_y_values.map!{ |i| 2 * Math::PI * i / x_y_values.size }
# percetange into x/y-values, scale values
x_y_values.map! do |i|
[r/2 + (r/2*Math.cos(i)).floor,
r/2 + (r/2*Math.sin(i)).floor]
end
# create matrix
grid = []
r.times { grid << Array.new(r, " ") }
# put values into matrix
x_y_values.each do |i|
# create colored character
c = colors[rand(colors.length)] + (32+rand(80)).chr + "\e[0m"
(grid[i[0]])[i[1]] = c
end
# print result
grid.each do |i|
puts i.join
end
end
>>
>>56170078
roll
>>
>>56182056
wow I'm dumb
say @*ARGS[0].lc.comb.sort eqv @*ARGS[1].lc.comb.sort;
>>
>>56170078
roll
>>
R-roll
>>
>>56171194
from PIL import Image
import os, sys

def imagetoquad(base):

xLength = base.size[0]
yLength = base.size[1]
xCenter = xLength / 2
yCenter = yLength / 2

quad1 = base.crop((xCenter, 0, xLength, yCenter))
quad2 = base.crop((0, 0, xCenter, yCenter))
quad3 = base.crop((0, yCenter, xCenter, yLength))
quad4 = base.crop((xCenter, yCenter, xLength, yLength))

return [quad1, quad2, quad3, quad4]

def recursequads(start, iterations, outputfolder):
try: os.mkdir(outputfolder)
except OSError: pass

resultdict = {"start":start}
for iternum in range(iterations):
updatedict = {}
count = 1
for things in resultdict:
for crop in (imagetoquad(resultdict[things])):
updatedict[count] = crop
crop.save(outputfolder + "/iter" + str(iternum).zfill(2) + "q" + str(count).zfill(6), "PNG")
count += 1
resultdict = updatedict

im = Image.open(sys.argv[1])
it = int(sys.argv[2])
ou = sys.argv[3]

recursequads(im, it, ou)


yay I can stay on /g/
>>
rollering
>>
>>56182270
Did i make you proud?
 $ ./reverse 1234
4321


#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int reverse(int x) {
int digits = floor(log(x) / log(10)) + 1;
int y;
for (int i = digits - 1; i >= 0; i--) {
int digit = x % 10;
x /= 10;
y += digit * pow(10, i);
}
return y;
}

int main(int argc, char* argv[]) {
char *end;
printf("%d\n", reverse(strtol(argv[1], &end, 10)));
}
>>
>>56171503
Damn. Dude wanted to be the best, like no one ever was.
>>
>>56181705
That took way too long to write.

defmodule WordCounter do
@special_chars ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~"]

def main(file_path) do
File.open(file_path, [:read, :utf8])
|> check()
|> print_results()
end

def check({:ok, file}) do
looper(file, [], %{})
end

def check({:error, reason}) do
IO.write "An error occurred: "
IO.inspect reason
end

def looper(file, :eof, acc) do
File.close(file)
acc
end

def looper(file, words, acc) do
line =
case IO.read(file, :line) do
atom when is_atom(atom) ->
atom
string ->
sanitize(string)
|> String.split(" ")
end

new_acc = insert(words, acc)

looper(file, line, new_acc)
end

def insert(map, atom) when is_atom(atom) do
map
end

def insert([], map) do
map
end

def insert([h | t], map) do
{_, new_map} =
Map.get_and_update(map, h, fn
nil ->
{nil, 1}
val ->
{val, val + 1}
end)

insert(t, new_map)
end

def sanitize(word) when is_atom(word) do
word
end

def sanitize(word) do
String.trim(word)
|> String.replace(@special_chars, "")
|> String.downcase
end

def print_results(map) when is_map(map) do
sorted = Enum.sort(map, fn({_, x}, {_, y}) -> x > y end)

print_results(sorted, 1)
end

def print_results([], _) do
:ok
end

def print_results([{word, count} | t], acc) do
IO.puts "#{acc}. \"#{word}\": #{count}"
print_results(t, acc + 1)
end
end
>>
>>56182787
roll again
>>
>>56182854
>Dynamic multidimensional arrays
What did he mean by this?
Reroll
>>
>>56182874
fuck i can't into ascii art
>>
>>56182972
Fuck actually implementing. Working with numpy is cancer. Polygon is ordered list of vectors. We transform by matrix multiplication.
>>
>>56170078
roll
>>
>>56170078
rules
>>
>>56170078
roll
>>
>>56170078
Rolly Polly
>>
>>56183064
printing to the terminal is literally the first thing you learn in any language
>>
>>56182400
Rolling another one
>>
>>56183854
multiarray = [[x for x in range(10)] for x in range(10)]


I'll do another one I guess
>>
rolling for justice
>>
>>56183934

Go build a C compiler from scratch
>>
>>56184068
Not sure what you mean by that
>>
>>56183934
You were supposed to implement it (ie. figure out how to manage the memory in a language that doesn't do that for you), not use a ready-made implementation. Why the fuck you think it's in the yellow/medium tier?
>>
>>56184094

{./maddoc.c}
>>
>>56184094
I know, that's why I'm rolled for another one.

Don't worry, I don't actually think I solved it
>>
>>56170078
rawl
>>
>>56170078
I don't even own a computer
>>
>>56185277
You don't have to own a computer to program in it
>>
>>56170481
>gets a roll
>gets pedantic given that there was a nonexistent specification for the problem
now this man is a programmer
>>
>>56171337
>>56171348
what language is this?
>>
>>56170078
roll
>>
>>56185120
reroll
>>
>>56170078
>Lego
>>
>>56170078

rolling for green
>>
>>56170078
rollo
>>
>>56170078
pls be gentle
>>
>>56186133
bmp is pretty easy to read and write if you don't want to use a library
if you need hints on how to hide information feel free to ask
>>
>>56170078
Let's see...
>>
>>56186176
I can probably do it if I look into even further and google the shit out of
as it for now, I have problems with basic conditional programming in java
Fucking kill me.java
if(nufag< implying){
System.out.println("Benis xdxd");
}
>>
>>56185603
Looks like Haskell
>>
>>56186085
Done. Easy.
#by simon *
#21-08-2016

import sys

class FibonacciGenerator(object):
def __init__(self):
self.known_numbers = [] #

def get(self, number):
'''
gets a number in the fibonacci sequence
'''
assert(number >= 0)
if number < len(self.known_numbers):
return self.known_numbers[number]
elif number <= 1:
self.known_numbers.append(1)
return 1;
else:
value = self.get(number - 1) + self.get(number - 2)
self.known_numbers.append(value)
return value

def main():
limit = int(sys.argv[1])
fib = FibonacciGenerator()
count = 0
while(count < limit):
print("Fibonacci number {} is {}".format(count + 1, fib.get(count)))
count += 1

if __name__ == '__main__':
main()
>>
>>56186256
projecteuler.net is pretty good if you're into maths
>>
>>56186517
Okay, thanks for your reply
>>
>>56186339
I can do that in one line with perl6 pleb
(1, 1, *+*...*)[^100].say;
>>
>>56182724
>tfw it took me several hours to do this
It's my first time doing this pls no bully
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main (int argc, char *argv[])
{
char p, c, *sc, w;

if (1 == argc) {
printf("Usage: %s [rock|paper|scissors]\n", argv[0]);
return 0;
}

if (0 == strcmp(argv[1], "rock")) {
p = 0;
} else if (0 == strcmp(argv[1], "paper")) {
p = 1;
} else if (0 == strcmp(argv[1], "scissors")) {
p = 2;
} else {
printf("Option %s doesn't exist\n", argv[1]);
return 1;
}

srand((unsigned) time(NULL));
c = rand() % 3;

switch (c) {
case 0: sc = "rock"; break;
case 1: sc = "paper"; break;
case 2: sc = "scissors"; break;
default: sc = "fuck"; break;
}

printf("You chose %s, I chose %s\n", argv[1], sc);

if (p == c) {
w = 0;
} else if (2 == c) {
w = 1;
} else if (2 == p) {
w = -1;
} else if (p < c) {
w = -1;
} else {
w = 1;
}

if (0 == w) {
printf("It's a draw\n");
} else if (0 > w) {
printf("You lose\n");
} else {
printf("You're winner\n");
}

return 0;
}
>>
>coding

sorry im not a nerd
>>
>>56186676
Also rolling again
>>
>>56186712
nice b8
>>
>>56186774
And rolling again
>>
File: jlayhe.jpg (41KB, 900x900px) Image search: [Google]
jlayhe.jpg
41KB, 900x900px
>>56186676

char* sc
You're not using pointers correctly (not pointing to a valid address)
sc = "rock" isn't valid.

You're using char as int incorrectly (w, c, p)
>>
>>56186793
Please enlighten me
How should I do it
>>
>>56170078
Come on
>>
File: santalahey.jpg (17KB, 480x360px) Image search: [Google]
santalahey.jpg
17KB, 480x360px
>>56186821

To start I probably wouldn't make the win conditions completely wrong.
>>
Rawl
>>
I'll roll the unfortunate
>>
>>56186954
The win conditions part was hard
I had to make a bunch of doodles to understand how to do it without an if/else for each possible combination
What would be a better way to implement it?
>>
The difficulty variability in OPs image is insane. Roll I guess
>>
File: redlayhe.jpg (129KB, 774x1032px) Image search: [Google]
redlayhe.jpg
129KB, 774x1032px
>>56187016

0 = rock
1 = paper
2 = scissor

assuming player, computer are ints
int winner = -1; // 1 = player win, 0 == computer win

// difference of 1 means higher choice wins
if ( abs(player - computer) == 1 )
{
winner = player > computer;
}
// lower number wins here (rock vs scissor)
else
{
winner = player < computer;
}


Are you a girl or a really gay dude?
>>
>>56187104
+ draw (player == computer), but you already know that
>>
BMI calculator

//BMI calculator

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main()
{
string units;
double weight, height, feet, inches, BMI;

cout << "BMI Calculator\n\n"
<< "Metric units or Imperial (m/i)? ";
cin >> units;

if (units == "m")
{
cout << "Enter your weight (kg): ";
cin >> weight;
cout << "Enter your height (m): ";
cin >> height;

BMI = (weight / pow(height, 2));
cout << setprecision(1) << fixed << showpoint;
cout << "Your BMI is: " << BMI;
}
else if (units == "i")
{
cout << "Enter your weight (lb): ";
cin >> weight;
cout << "Enter your height (ft in): ";
cin >> feet >> inches;

BMI = 703 * (weight / pow((feet * 12 + inches), 2));
cout << "Your BMI is: " << BMI;
}
else
cout << "Invalid selection";
return 0;
}
>>
>>56187104
Am I behaving like a girl or am I stupid like a girl?
>>
R
>>
>>56187124
-1 can be a draw and a default outcome assuming a correct input.
>>
File: lahey1.jpg (42KB, 500x333px) Image search: [Google]
lahey1.jpg
42KB, 500x333px
>>56187225
behaving

>>56187248
Need another condition for draw, -1 was a default not the draw value.
if // distance == 1
else if ( player == computer )
{
winner = 99999lickmybutt;
}
else // gap


I'm running out of Jim pix
>>
>>56187016
jsut takes a while to wrap your head around the concept of programming, you're fine
>>
>>56170078
>can't program? Get off /g/
>don't know how to rebuild an engine? Get off /o/
>aren't MGTOW in a cabin in the woods? Gett off /out/
>didn't build your own house? Get off /diy/
>aren't scooby? Get off /fit/
>didn't have coffee daily with ansel adams next to a campfire and your packmules? get off /p/
>aren't in the senate? Get off /pol/
>don't write scripts? Get off /tv/

Eat a dick, tard.
>>
>>56187296
wew
I guess it isn't just a meme that browsing /a/ makes you a little girl
>>
>>56187019
>Triangle number generator
like this one. It's piss easy, while there are some I couldn't even begin.
triangle <- function(n){
if(all(n==as.integer(n) & n>0)){
(n^2+n)/2
}else{
stop("argument must be natural number vector")
}
}

# OUTPUT:
# > triangle(1:20)
# [1] 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210
>>
>>56170078
roll
>>
>>56187324
why so mad anon?
>>
File: bobandy1.jpg (7KB, 184x184px) Image search: [Google]
bobandy1.jpg
7KB, 184x184px
>>56187332
maybe just a gay boi
>>
>>56187372
Cause OP is a retard
>>
>>56187383
I'm not
>>
File: bobandy.jpg (42KB, 329x399px) Image search: [Google]
bobandy.jpg
42KB, 329x399px
>>56187426
https://youtu.be/WcWM_1hBu_c?t=58
>>
>>56187454
heh
>>
like this thread needs another
>roll
>>
>>56187474
eh nah
>>
>>56170078
Roll so I might have something to do later
>>
>>56184233
Solution: http://pastebin.com/kBYSV2m5

needs some sort of interface, but the meat of it is there.
>>
File: stallman-heart.png (1MB, 1000x1400px) Image search: [Google]
stallman-heart.png
1MB, 1000x1400px
>>56187921
Before hiding the secret message "stallman is life"
>>
File: output.png (2MB, 1000x1400px) Image search: [Google]
output.png
2MB, 1000x1400px
>>56187966
After hiding the secret message:
>>
>>56172656
It definitely could. I just copied some old code I did from when I started.
>>
>>56170078
rolling
>>
>>56186339
Dynamic programming, nice. I prefer a bottom-up approach though, so it doesn't have to save all previous values.
>>
File: output.png (3MB, 5000x5000px) Image search: [Google]
output.png
3MB, 5000x5000px
>>56175493
>>56175175
>>56174768
It finally fucking compiled (had to use MSYS2). Pic related. A 5000x5000 grid made with my program. It didn't even take that long.
>>
>>56189065
It's the Ulam spiral btw.
Thread posts: 299
Thread images: 31


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.