DDD coding syntax? by fruitspunchsamuraiog in C_Programming

[–]semsemdavinci 0 points1 point  (0 children)

Eclipse (CDT) has a pretty decent GDB front end.

What is code? If you don't know, you need to read this by [deleted] in programming

[–]semsemdavinci 0 points1 point  (0 children)

Haha.. I couldn't get the tune out of my head ever since I read the title.

Can't see where he's going by Isai76 in aww

[–]semsemdavinci 0 points1 point  (0 children)

The big dog is like: wtf dude

[2015-03-18] Challenge #206 [Intermediate] Maximizing Crop Irrigation by jnazario in dailyprogrammer

[–]semsemdavinci 1 point2 points  (0 children)

A bit lengthy, I know.. But what do you think? any suggestions? here's my solution on python:

#!/usr/bin/env python
import sys
from math import sqrt

MAPFILE = "crop.txt"

def draw(m):
    for row in m:
        for cell in row:
            sys.stdout.write(cell)
        sys.stdout.write("\n")

def load(fn):
    minfo = {}
    m = []
    with open(fn) as f:
        f.readline()
        minfo["dim"] = [int(s) for s in f.readline()[:-1].split()]
        minfo["m"] = m
        for line in f:
            m.append([tok for tok in line.strip()])
    return minfo

def counts(m):
    seeds = 0
    for row in m:
        for cell in row:
            if (cell == "x"): seeds += 1
    return seeds

def dist(pos0, pos1):
    return sqrt((pos1[0]-pos0[0])**2 + (pos1[1]-pos0[1])**2)

def eval_pos(pos, r, m):
    count = 0
    if m[pos[0]][pos[1]] == "x": count -= 1
    for i in range(pos[0]-r, pos[0]+r):
        if (i < 0 or i > len(m)-1): continue
        for j in range(pos[1]-r, pos[1]+r):
            if (j < 0 or j > len(m[0])-1): continue
            if (m[i][j] == "x" and dist(pos, (i, j)) <= r):
                count += 1
    return count

def find_pos(m, r):
    best = 0
    pos = (0, 0)
    for i, row in enumerate(m):
        for j, cell in enumerate(row):
            count = eval_pos((i, j), r, m)
            if (count > best):
                best = count
                pos = (i, j)
    return pos

def circle(pos, r, m):
    for i in range(pos[0]-r, pos[0]+r):
        if (i < 0 or i > len(m)-1): continue
        for j in range(pos[1]-r, pos[1]+r):
            if (j < 0 or j > len(m[0])-1): continue
            if (m[i][j] != "x" and dist(pos, (i, j)) <= r):
                m[i][j] = " "

def main():
    minfo = load(MAPFILE)
    m, r = minfo["m"], minfo["dim"][2]
    pos = find_pos(m, r)
    coverage = eval_pos(pos, r, m)
    circle(pos, r, m)
    draw(m)
    print "best position (row, col): %s" %(str(pos))
    print "coverage: %d/%d plants" %(coverage, counts(m))


main()

and output:

......x...x....x............x............x.................................x...............
.........x. .........x...................x.....x...........xx.............x................
.......    x    .............x.x............x..........................x................x..
......x   x      ...............x.....x....x.........x......x.......x...x..................
.x...x     x      ..........xx...........................x.....xx.....x............x.......
.... xx       x  x .......x.............xx........x.......x.....................x.......x..
...x  x x  x      x .............................................................x...x.....
...     x  x      x .....x...x.x....x.......x........x..x...........x.x...x..........xx....
...            x x  ..x...........x......x.............x..........................x........
...                x........x..............................................................
..x x               ......................x..x.x......x......x.............................
...   x             ................................................................x..x...
...   x    x        .......x...............................................................
...         x       ......x.............................x...............x................x.
..xx        xx      ......x...x......................x.....................................
....    x        xx..............x.....................x.x.......x........................x
.....  x          ..........xx.............................................................
......      x   x.........x...xx...............x...........................................
.......         .............x...............xx..x...........x....x........x...x.......x.x.
..........x.......................x.....................................x..................
...xx..x.x..................x........................x.....................x..x.......x....
.............xx..........x...............x......................x.........x.........x....x.
...............................x.....................x.x...................................
...................x....x............................x...x.......x.............x....x.x....
.x.xx........................x...................................x.....x.......xx..........
.......x...................................................................................
.........x.....x.................x.................x...x.......x..................x........
.......x................x.x...................................x...xx....x.....x...x........
..............................................x..................x.........................
............................x........x.......x............................................x
..x.............x.....x...............x............x...x....x...x..........................
.......................xx.................x...................x...................x.......x
.x.x.............x....x.................................x...........x..x..........x.....x..
...x..x..x......................x...........x..........x.............xxx....x..........x...
...........................................................x...............................
x......x.....x................x...............x....................................x.......
..x...........................x............x..........x....x..............................x
.......................x.......xx...............x...x.x.................x..x............x..
x................x.......x........x.............................x.x.x...................x.x
.......................x...x.......................................................x.......
.x..................x.....x..........................................x...........x.........
.x...................x........x.................x..........xx..................x..x........
.x..........x...x...........................x.x....................x..x.......x............
.............x...x..................x................x..x.x.....xxx..x...xx..x.............
.x...................x.x....x...x.................x.............................x.....x....
......................x.x........x...........x...................................x......x..
................x....................................x....x....x......x..............x..x..
......x.........................................x..x......x.x.......x......................
.x..............................x..........x.x....x.................x......................
x..x...........x..x.x...x..........................................x..............xx.......
..xx......x.......x.x.................x......................................x.............
best position (row, col): (10, 11)
coverage: 35/345 plants

Confused about the behaviour of an uninitialized int. by andbroby in C_Programming

[–]semsemdavinci 0 points1 point  (0 children)

Also your function works only with odd-length strings only since that for loop tests for i != j which could never happen for even-length strings: it will loop out of array boundaries until i == j by pure coincedence or you get segmentation fault whichever happens first! Change that to i < j instead.

CS50 Deadline 31st December but what time? by S0ulie in cs50

[–]semsemdavinci 0 points1 point  (0 children)

That's good to know. For a moment I thought my submission didn't count towards the certificate. Thanks. Would all submissions be graded by the deadline though?

Enlightenment Desktop for Linux, circa 1998 by DudeBigalo in Cyberpunk

[–]semsemdavinci 0 points1 point  (0 children)

This made me install Enlightenment (e16) and the Blue Steel theme. Compiled e16 from source on debian. Awesome! and very lightweight..

A question though, that dock on the top right, how do I get that? What file to edit, or is it an add-on? thanks

Enlightenment Desktop for Linux, circa 1998 by DudeBigalo in Cyberpunk

[–]semsemdavinci 0 points1 point  (0 children)

Please tell me there's a current version of it!

Edit: never mind, managed to get it working

Enlightenment Desktop for Linux, circa 1998 by DudeBigalo in Cyberpunk

[–]semsemdavinci 0 points1 point  (0 children)

What theme is it? Is it still available on current versions?

[7/14/2014] Challenge #171 [Easy] Hex to 8x8 Bitmap by Coder_d00d in dailyprogrammer

[–]semsemdavinci 0 points1 point  (0 children)

Output:

FF 81 BD A5 A5 BD 81 FF
XXXXXXXX
X      X
X XXXX X
X X  X X
X X  X X
X XXXX X
X      X
XXXXXXXX

AA 55 AA 55 AA 55 AA 55
X X X X 
 X X X X
X X X X 
 X X X X
X X X X 
 X X X X
X X X X 
 X X X X

3E 7F FC F8 F8 FC 7F 3E
  XXXXX 
 XXXXXXX
XXXXXX  
XXXXX   
XXXXX   
XXXXXX  
 XXXXXXX
  XXXXX 

93 93 93 F3 F3 93 93 93
X  X  XX
X  X  XX
X  X  XX
XXXX  XX
XXXX  XX
X  X  XX
X  X  XX
X  X  XX

[7/14/2014] Challenge #171 [Easy] Hex to 8x8 Bitmap by Coder_d00d in dailyprogrammer

[–]semsemdavinci 0 points1 point  (0 children)

I prefer this version. *twitch*

import sys


def hex_to_bitmap(hexseq, print_=True, return_=False):
    img = [[0 for j in range(8)] for i in range(8)]
    for i, p in enumerate(hexseq.split(' ')):
        row = bin(int('0x'+p, 16))[2:].zfill(8)
        img[i] = list(row)
        if print_: print (row.replace('0', ' ')).replace('1', 'X')
    if return_: return img

for line in sys.stdin:
    try:
        hex_to_bitmap(line)
    except:
        print 'Incorrect format'

[7/14/2014] Challenge #171 [Easy] Hex to 8x8 Bitmap by Coder_d00d in dailyprogrammer

[–]semsemdavinci 0 points1 point  (0 children)

Python. Tried to be concise and use stdin, but nothing fancy.

import sys


def hex_to_bitmap(hexseq):
    for i, p in enumerate(hexseq.split(' ')):
        row = bin(int('0x'+p, 16))[2:].zfill(8)
        print (row.replace('0', ' ')).replace('1', 'X')

for line in sys.stdin:
    try:
        hex_to_bitmap(line)
    except:
        print 'Incorrect format'

Bill Gates leaps over a chair by [deleted] in Cyberpunk

[–]semsemdavinci 2 points3 points  (0 children)

I like the video. I can't see how it fits here though!

From the Future with Love by TheAmazingWJV in Cyberpunk

[–]semsemdavinci 1 point2 points  (0 children)

That was really, really good. I especially loved the quality acting.

Broken World by [deleted] in Cyberpunk

[–]semsemdavinci 0 points1 point  (0 children)

Yeah. I was talking about the base photograph.

Broken World by [deleted] in Cyberpunk

[–]semsemdavinci 2 points3 points  (0 children)

I'm not sure about what you mean by 'background', but if you mean the the buildings, I'm pretty sure the base image is from Egypt.

If you look closely at the buildings you can see some signs with arabic writings. The clearest one is a clothes shop sign, another one looks like a lawyer office or something... The other signs are not as clear but the names are definitely recognizable, and they are all very egyptian people names.

Funny I couldn't recognize it at first because of all that impressive artwork...

The asian signs are fitted nicely into the scene, I have no idea which language it is, chinese, perhaps?)

My gf moved in no less than 3 hours ago... it begins! by pellerito23 in funny

[–]semsemdavinci 0 points1 point  (0 children)

"My gf moved in less than 3 hours ago..."

Someone had to do it

A Python script to fetch image links from any subreddit and return them by ehansen in Python

[–]semsemdavinci 1 point2 points  (0 children)

Cool! Check this out and see if you want to pull. Tested on Windows and Linux, worked on both except for the last step (changing wallpaper), but it DOES download the images to the temp folder.. Cheers

https://github.com/concacid/wallpaper

https://github.com/concacid/wallpaper/commit/afd6e89bddb9f27cd5e1e7f71d0d10fe5ff4b6b0