Welcome, Guest

Author Topic: Coding  (Read 276014 times)

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #390 on: March 30, 2014, 12:32:59 AM »
please read this article on brainfuck, i promise it's painless: https://en.wikipedia.org/wiki/Brainfuck

so this is a brainfuck interpreter i coded. just double click on it, and you can start typing brainfuck in. it stores all the code you've typed in until you enter a blank line, then executes. if there are any problems, they'll be printed. if you want to clear the cells, type NIL to restart everything.

here's some sample code you can try:

Code: [Select]
+++++[>+++++++++++++<-]>.this first sets the first cell to five. then, it decreases the first cell and increase the second cell by 13 in a loop which executes five times. 5*13 = 65. we shift back to the second cell and print 65, which is ascii character 'A'

this is hello world:
Code: [Select]
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #391 on: March 31, 2014, 02:05:53 PM »
this is an idiotproof mob farm calculator which simulates five minutes of spawning and despawning in a few seconds. just click to run.

curiously, the simulation suggests that large mob farms near the ground should not kill the mobs as quickly as possible, a slightly longer time gives up to a 50% increase in kill rate

bla's farm should get 3 mobs per second with one player on, and 3.7 seconds with 3 players on
the destroyed farm in desertopia would have gotten .6 per second with one player on, and .8 with 3 players on
a 2000-piston mob farm in the sky would get 2.8 mobs per second with one player on, but only .33 with 3 players on.
« Last Edit: March 31, 2014, 02:14:12 PM by vh »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #392 on: April 02, 2014, 09:37:07 PM »
brainfuck program to print the fibonacci sequence wrote with explanation

Code: [Select]
+>+[[->+<]<[->>+<<]>>.]

+>+ initialize the first two cells a1, a2
[ add a_n-1 and a_n-2 in a loop
[->+<] subtract a_n-1 and add to a_n, stopping when a_n-1 is zero
< shift from a_n-1 to a_n-2
[->>+<<] subtract a_n-2 and add to a_n, stopping when a_n-2 is zero
>> shifts over to a_n which becomes a_n-1 in the next loop
. output which doesn't actually print the number
] since a_n is never zero, loop does not terminate
by the way, this code doesn't work but i'm too lazy to fix it

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #393 on: April 05, 2014, 07:29:46 PM »
pycollective. just extract the folder to whereever.

open the file with notepad and edit the player variable with your own blacraft nickname (for bla it would be "Comrade Blanoxium" or something).

drag a shortcut into the startup folder to make it run on startup.


in blacraft, whenever you remove something from your collective storage chests, type something like

! cobblestone -1000

or

! lapis +1000

at the end of the month, open the file, and all the changes will be added up. you'll need to reset the log manually

if you don't mind the black terminal, you can rename .pyw to .py so you'll know if it stops working for some reason.
« Last Edit: April 05, 2014, 08:13:43 PM by vh »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Coding
« Reply #394 on: April 05, 2014, 07:58:37 PM »
Holykol that sounds super kolvenient, thanks for developing that! Definitely going to try that.

Where's the startup folder? For startup in Minecraft or Wind dose?

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #395 on: April 05, 2014, 08:03:18 PM »
for windows

i'm just following this page:

http://windows.microsoft.com/en-us/windows/run-program-automatically-windows-starts#1TC=windows-7

haven't done it myself so i don't know where it is :P

edit:

also keep in mind this only works if dynmap is turned on.
« Last Edit: April 05, 2014, 08:12:03 PM by vh »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Coding
« Reply #396 on: April 06, 2014, 09:14:33 AM »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #397 on: April 10, 2014, 03:30:22 PM »
i forgot to mention, you have to clear the logs before you use it because i forgot to do that after i finished testing.

------------------

i coded a taylor polynomial grapher. to use it, just type in something formatted like the following

function, degree, center, x1, x2

for example:

lambda x: airy(x)[1], 100, 0, -7,7

which plots the imaginary part of the airy function along with a 100th degree taylor approximation centered at 0 from -7 to 7 as shown below

right now the derivative is numerically approximated so any degree over 20 is pretty much useless. i might try symbolic derivatives later

if you try logs and other function with domain holes it acts strangely and might print errors

edit: added the code. scipy, numpy, and matplotlib needed.
« Last Edit: April 10, 2014, 03:35:35 PM by vh »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #398 on: April 10, 2014, 09:52:34 PM »
fixed code above so a center other than zero works.

also adjusted the derivative calculator so it can handle functions like log(x+1) better and cbrt(x)

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #399 on: April 13, 2014, 09:08:41 AM »
protip: scipy's scipy.stat.norm.pdf is a very slow approximation for the bell curve, i sped up my code like 10 times by using this:

Code: [Select]
def nfunc(mu, sigma):
    def normpdf(x):
        u = (x-mu)/abs(sigma)
        y = (1/(sqrt(2*pi)*abs(sigma)))*exp(-u*u/2)
        return y
    return normpdf

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #400 on: May 17, 2014, 12:58:32 PM »
d42758482096b3e

pyimg takes a screenshot, uploads it to imgur, and puts the link in your clipboard whenever you press f9. entire process takes about 1 to 2 seconds on average.

you need a client id to use the application, and each id can upload 1250 images per day. i've posted one above, or you can register for one here: https://api.imgur.com/oauth2/addclient

you'll need a shitload of libraries for this to run though:
pyimgur

win32gui
win32ui
win32con
win32api
pythoncom

(all under the name pywin32)

PIL
pyHook

downloads:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
http://effbot.org/downloads#pil

and this one is not a binary

https://pypi.python.org/pypi/pyimgur/0.5.2

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #401 on: May 19, 2014, 01:28:40 PM »
no one asked but this is a multithreaded version so there is no input lag

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #402 on: May 23, 2014, 08:05:46 PM »
new version of pyimg.

with this version, the link is instantly (<1ms) copied onto your clipboard. however, the link points nowhere for the first few seconds. this probably will not be an issue as no one clicks on irc links that fast (i hope).

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Coding
« Reply #403 on: May 25, 2014, 06:35:34 AM »
is it just me or does ink scape use .py files so it uses python???

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #404 on: June 12, 2014, 10:44:33 PM »
haskell is really cool.

random number gen i coded

Code: [Select]
lehmer :: [Int] -> Int -> Int -> Int -> Int -> [Int] --list of random integers
lehmer [] seed maxp mult len = lehmer [seed] seed maxp mult (len - 1)
lehmer k seed maxp mult len = if len > 0
then lehmer ((lehmerl (head k) maxp mult) : k) seed maxp mult (len - 1)
else k

lehmerl :: Int -> Int -> Int -> Int -- generate next element on list
lehmerl prev maxp mult = mod (mult * prev) maxp

randmax :: Int -> Int -> [Int]
randmax max len = [mod i max | i <- (lehmer [] 65537 2147483647 16807 len)]

from 0 to 100 w/ 1000 samples

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #405 on: June 15, 2014, 02:29:03 PM »
simulation of a column of leaves collapsing into saplings. until the very end, the pattern is surprisingly linear.

i also wrote a few functions to simulate the collapse when collapse is proportional to the drop stacked on each block and also inversely proportional.

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Coding
« Reply #406 on: June 15, 2014, 02:50:42 PM »
.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #407 on: June 17, 2014, 07:10:56 AM »
spoiler maker, which turns easily formatted paragraphs into html spoilers

usage example:
Code: [Select]
execfile('htmlrender.py')
awrite('demo.txt', 'demo.html')

demo.txt and demo.html are attached

note that all titles must be globally unique. i might fix this in the future but it will require major restructuring of the code

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #408 on: July 02, 2014, 11:07:46 PM »
haskell primality tester

i've attached the code and a compiled exe, which tests the number
Code: [Select]
9444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444448484498999and closes upon finding it is a prime


vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #409 on: July 02, 2014, 11:09:34 PM »
this script runs structural tests on a minecraft world and collapses structures that don't stand up to gravity and wind.

the first part opens the file and puts it into an array. this works.

the second part runs the structural tests. this doesn't work.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #410 on: July 02, 2014, 11:11:13 PM »
but wait i'm not done

i started coding map war 3 again today, except i started brand new with a new structure. i just have to code in the turn processing and the game rules/settings, then slap on some shiny graphics and we're done!

Code: [Select]
import networkx as nx
import cPickle
import deepcopy

class Zone:
def __init__(self, id, own = None):
self.id = id
self.econ = 0
self.indus = 0
self.fort = 0
self.own = own
self.dist = None #needs to compute
def upg(typ, amount): #bad form?
if typ == 'econ':
self.econ += amount
elif typ == 'indus':
self.indus += amount
elif typ == 'fort':
self.fort += amount

class Nation:
def __init__(self, id, capital, techs):
self.capital = capital
self.id = id
self.mon = 0
self.econ = 0
self.indus = 0
self.mil = 0
self.zones = [self.capital]
self.techs = techs
self.trades = []
def addzone(self, zone):
self.zone.append(zone)
def compstats(self):
self.econ = sum((zon.econ for zon in self.zones))
self.indus = sum((zon.indus for zon in self.zones))
self.mon += self.econ
def convmil(self, amount):
self.mon -= amount
self.mil += amount
def research(self, tree, amount):
self.techs[tree].rsearch(amount)
def addtrade(self, onat):
self.trades.append(onat)

class Tech:
def __init__(self, dflags, cval = 0):
self.cval = cval
self.dflags = dflags
def rsearch(self, amount):
self.cval += amount
def checkflag(self, typ):
return self.dflags[typ](self.cval)

class World:
def __init__(self, zones, edges, tech):
self.zones = zones
self.edges = edges
self.techs = techs
self.nations = []
self.mgraph()
def mgraph(self):
self.graph = nx.Graph()
for node in self.zones:
self.graph.add_node(node)
for edge in self.edges:
self.graph.add_edge(*edge)

class Turn:
def __init__(self, acts): #zacts, wacts, tacts, racts, nacts, oacts
self.acts = acts
def addacts(self, typ, act):
self.acts[typ].append(act)
def removeacts(self, typ, act):
del self.acts[typ][self.acts[typ].index(act)]

def rotlist(lst):
return [lst.pop()]+lst

class Game:
def __init__(self, world, gamerules, tord):
self.history = [world]
self.world = world
self.gr = gamerules
self.tord = reversed(tord)
self.estate = False
def confirm(self):
self.history.append(copy.deepcopy(self.world))
def lastconfirmed(self):
self.world = copy.deepcopy(self.history[-1])
#
def pzacts(self, zacts):
pass
def pwacts(self, wacts):
pass
def practs(self, racts):
pass
def pnacts(self, nacts):
pass
def poacts(self, oacts):
pass
def pturn(self, turnobj):
self.lastconfirmed()
self.turn = self.tord[0]
zacts, wacts, racts, nacts, oacts = turnobj.acts
self.pzacts(zacts) #zone acts
self.pwacts(wacts) #war acts
self.practs(racts) #tech acts
self.pnacts(nacts) #nation acts
self.poacts(oacts) #other acts
if not(self.estate):
self.tord = rotlist(self.tord)
self.confirm()

class Gamerules: #is a class overkill
def __init__(self):
self.settings = {
}
self.rules = {
}
pass

def tofile(instance, file):
with open(file, 'w') as f:
cPickle.dump(instance, f)

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Coding
« Reply #411 on: July 02, 2014, 11:13:21 PM »
inb4 bla

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #412 on: July 05, 2014, 10:50:29 PM »
keylogger that doesn't log keys, only the time at which keys are pressed. even which key was pressed is not stored

Code: [Select]
import pythoncom, pyHook
import time

times = []
last = time.time()

def tofile(lst):
    with open('ktime.log', 'a') as file:
        file.write('\n'.join([str(val) for val in times])+'\n')

def OnKeyboardEvent(event):
    global times, last
    times.append(time.time())
    if len(times) >= 1000 or time.time()-last > 1000:
        last = time.time()
        tofile(times)
        times = []

while True:
    hm = pyHook.HookManager()
    hm.KeyDown = OnKeyboardEvent
    hm.HookKeyboard()
    pythoncom.PumpMessages()

it's sloppy, but it works.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #413 on: July 06, 2014, 12:35:05 AM »
Code: [Select]
d
[0, 'test1.py', True]
[1, 'test2.py', True]
s all
[0, 'test1.py', False]
[1, 'test2.py', False]
r 0
[0, 'test1.py', True]
[1, 'test2.py', False]
r 1
[0, 'test1.py', True]
[1, 'test2.py', True]
k 0
[0, 'test2.py', True]
k 0
d
a test1.py
[0, 'test1.py', True]
a test2.py
[0, 'test1.py', True]
[1, 'test2.py', True]
ponypony
error
i wrote a thing to manage the multiple scripts i like to keep running
think of it like task manager... but better!

here's the manual
Code: [Select]
d
displays running processes

a <file>
adds a new process

s <index>
suspends a process by index. use display to find the index

r <index>
resumes a process

k <index>
kills a process

u <index>
updates the status of a process. unless something went bad this shouldn't be needed

also, instead of using an index, one might use the keyword 'all', which applies the action to all processes.

to run scripts on startup, place them in the scripts list in smanage.py

here's the code along with several test scripts.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #414 on: July 10, 2014, 07:25:53 PM »
puzzle. not mindnumbing, but not easy either.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #415 on: July 10, 2014, 07:28:51 PM »
for bonus points do it functionally.

600 iron prize on blacraft if you finish it within 18 hours of this post

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #416 on: July 11, 2014, 09:10:09 PM »
snip

i updated smanage.py so that one might put shortcuts to the scripts instead of the actual script. you can now add 'shortcut.lnk' to the list of scripts

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #417 on: July 12, 2014, 07:30:24 AM »
-

did it

Code: [Select]
compose :: [a -> a] -> (a -> a)
compose fs = foldl (flip (.)) id fs

data Block = Block [[Bool]] Int deriving (Show)

replacen :: Int -> a -> [a] -> [a]
replacen n val (x:xs)
| n == 0 = val:xs
| otherwise = x:(replacen (n-1) val xs)

replace2n :: Int -> Int -> a -> [[a]] -> [[a]]
replace2n n1 n2 val arr = replacen n1 (replacen n2 val (arr !! n1)) arr

setval :: Block -> Int -> Int -> Bool -> Block
setval (Block arr size) n1 n2 val = Block (replace2n n1 n2 val arr) size

getringdict :: Int -> Block -> [(Int,(Int, Int))]
getringdict n (Block arr s) = zip [0..] (c1 ++ c2 ++ c3 ++ c4)
    where
c1 = zip [n..s-n-2] (repeat n)
c2 = zip (repeat (s-n-1)) [n..s-n-2]
c3 = zip [s-n-1,s-n-2..n+1] (repeat (s-n-1))
c4 = zip (repeat n) [s-n-1,s-n-2..n+1]

rraccum :: [(Int,(Int, Int))] -> Int -> (Block, Block) -> (Int,(Int, Int)) -> (Block, Block)
rraccum rposs amount (oblock, nblock) entry = (oblock, setval nblock n1 n2 obool)
    where
        np = mod ((fst entry) + amount) (length rposs)
(n1, n2) = fromJust $ lookup np rposs
(o1, o2) = snd entry
(Block arr s) = oblock
obool = (arr !! o1) !! o2

rotring :: Int -> Int -> Block -> Block
rotring amount ring oblock = snd $ foldl (rraccum rposs dr) (oblock,oblock) rposs
    where
(Block arr size) = oblock
rposs = getringdict ring oblock
dr
    | mod amount 2 == 0 = amount
    | mod amount 2 == 1 = (-amount)


rotate :: Block -> Int -> Block --something with this is wrong
rotate oblock amount = compose (map (rotring amount) [0..div size 2]) $ oblock
where (Block bitarr size) = oblock

haskell is nice.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #418 on: July 19, 2014, 12:41:24 PM »
46 lines of church arithmetic in common lisp.

lisp is very messy for my taste

Code: [Select]
(defun church (n)
(labels
((repeat (f x n)
(if (<= n 0)
x
(repeat f (funcall f x) (- n 1)))))
(lambda (f) (lambda (x) (repeat f x n)))))

(defun unchurch (n)
(funcall (funcall n (lambda (x) (+ 1 x))) 0))

(defparameter zero (church 0))
(defparameter one (church 1))
(defparameter two (church 2))
(defparameter three (church 3))

(defun csuc (n)
(lambda (f) (lambda (x)
(funcall f (funcall (funcall n f) x)))))

(defun cadd (n m)
(lambda (f) (lambda (x)
(funcall (funcall m f) (funcall (funcall n f) x)))))

(defun cmul (n m)
(lambda (f) (lambda (x)
(funcall (funcall m (funcall n f)) x))))

(defun cexp (n m)
(lambda (f) (lambda (x)
(funcall (funcall (funcall m n) f) x))))

(defun cpre (n)
(labels (
(extract (k)
(funcall k (lambda (u) u)))
(inc (f)
(lambda (g) (lambda (h)
(funcall h (funcall g f)))))
(const (x)
(lambda (u) x)))
(lambda (f) (lambda (x)
(extract (funcall (funcall n (inc f)) (const x)))))))

(defun csub (m n)
(funcall (funcall n #'cpre) m))

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #419 on: July 19, 2014, 04:15:11 PM »
remember that keylogger i posted which only records the times you press the key? well when you're playing minecraft and hold down w, a bunch of keys get recorded. but i messed around with the module and found this hidden feature -- if you replace KeyDown with KeyUp, the hook module gets key releases. so yeah.