Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,822 members, 7,810,159 topics. Date: Friday, 26 April 2024 at 10:04 PM

Challenge Me - Programming (4) - Nairaland

Nairaland Forum / Science/Technology / Programming / Challenge Me (15490 Views)

(2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (Reply) (Go Down)

Re: Challenge Me by Nobody: 3:28am On Oct 24, 2017
Nicely done soldier, nicely done.

I'm assuming your unit test was against multiple inputs...

4kings:
hMM, haskel that's cool.

@danielthegeek et al...
here's the code:
apologies for my variable naming.
def func(lenY, m, b):
lenY, m, b = lenY, m, b
x_points, fac = [], 0

for y in range(1,lenY+1):
x = (y - b)/m

if x.is_integer() is not True:
x_points.extend(list(range(fac, int(x)+1)))
x_points.append(cont[-1])
fac = int(x) + 1
else:
x_points.extend(list(range(fac, int(x)+1)))
fac = int(x) + 1

dif = int(len(x_points[:-1])/lenY)
y_points = [i for i in range(1,lenY+1) for j in range(dif)]

cells = len(x_points[:-1])
cells_coordinates = list(zip(y_points, x_points[:-1]))

return(cells, cells_coordinates)


the function takes in height or lenght of Y, m and b.
m is gradient of line; using any two point in y will give 0.4
b is point of intersection which is 0.
so if two list of values for x and y is given, the common number is the intersection and m is determined by picking any two values from y with respect to x. change in y/change in x

then the function calculates the number of cells and also give the coordinates or location of each cell from the top.

number, locations = func(4, 0.4, 0)

Benchmark:
import timeit
timer = timeit.Timer('func(3,0.4,0)', 'from __main__ import func')
benchmark = timer.timeit(number=1000)
print(benchmark)

It took average of 0.026 seconds with 1000 number of executions.

When i increased Y to 1000. That is func(1000, 0.4,0); Python messed me up, it took average of 5.3 seconds.

So there's the code, returning number of cells and their locations.



I didn't loop through every value of x like i said before that is 0.1,0.2 to 10.
I just calculated x at different values of y(intervals), and any number that exceeded an integer indicates a repeated cell.
For example if x values are 2.5, 5, 7.5, 10. 2.5 is counted twice because it extends to cell 3.
Re: Challenge Me by 4kings: 3:38am On Oct 24, 2017
DanielTheGeek:
Nicely done soldier, nicely done.

I'm assuming your unit test was against multiple inputs...

Thanks.
Yep, you can test them. lenY = 1 gives 3; 2 gives 6 and 3 gives 9.
If you have different set of coordinates from another graph you can also test them(if u use python also).

I just noticed something replace cont with x_points, though i've modified my original post. I'm not too god with naming variables.
Re: Challenge Me by Nobody: 3:53am On Oct 24, 2017
DanielTheGeek:
Before test results come in, let's play around with actual coding so other guys can join in;

Find if a set of given positive integers can be divided into two parts (subsets) with equal sum.

Example:
Where S represents sets and Sn represents subsets;

S = { 5, 2, 2, 3, 3, 4, 1 }

Partitioning will give us;
S1 = { 5, 2, 3 }
S2 = { 2, 3, 4, 1 }

Summation of S1 and S2 will give a total of the sum of values in the original set.

It's not compulsory for integers in subsets to be arranged in any order.. As far as the summation gives the required results, you're good to go...



Seunthomas can you give this a shot in Glass language? I know it's too simple but just manage it...can't think of much right now or maybe try Crystal..
Re: Challenge Me by Nobody: 3:57am On Oct 24, 2017
I'm doing some app monitoring and routine checks... To even run test isn't feasible, the only reason i'm on NL is because i'm watching xvid... YouTube grin

4kings:

Thanks.
Yep, you can test them. lenY = 1 gives 3; 2 gives 6 and 3 gives 9.
If you have different set of coordinates from another graph you can also test them(if u use python also).

I just noticed something replace cont with x_points, though i've modified my original post. I'm not too god with naming variables.
Re: Challenge Me by 4kings: 8:07am On Oct 24, 2017
DanielTheGeek:
I'm doing some app monitoring and routine checks... To even run test isn't feasible, the only reason i'm on NL is because i'm watching xvid... YouTube grin

lol grin OK.
Re: Challenge Me by Jenifa123: 1:17pm On Oct 24, 2017
Trolling through
Re: Challenge Me by bolkay47(m): 2:06pm On Oct 24, 2017
Jenifa123:
Trolling through
It's a good thing to do.
Re: Challenge Me by seunthomas: 3:15pm On Oct 24, 2017
DanielTheGeek:


Seunthomas can you give this a shot in Glass language? I know it's too simple but just manage it...can't think of much right now or maybe try Crystal..
I dont know glass language and dont want to invest (time) resources in it. But i can do in some of the languages i know how to use well. Usually this kind of problem is best solved with python. But before i go ahead, is this you challenging me??
Re: Challenge Me by rushman003: 4:16pm On Oct 24, 2017
seunthomas:

I dont know glass language and dont want to invest (time) resources in it. But i can do in some of the languages i know how to use well. Usually this kind of problem is best solved with python. But before i go ahead, is this you challenging me??

This is a challenge and also a problem i'm currently facing! I would have opened another tread but i don't wanna derail

Any of the programmer here to read unformatted / not well formed xml data from a TCP client(socket) and use a particular message string from the xml to trigger an IP camera...

Mind you have got this working on a simulator but the same code is giving problem with the real device!

below is the pull data for the handshake communication between server and client


<?xml version="1.0" encoding="UTF-8"?>
<PlatformStatusReport>
<PlatformIdentification>
<DeviceName>FD525R</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR APU</DeviceType>
</PlatformIdentification>
<PlatformStatusReport>
<PlatformIdentification>
<DeviceName>FD525R.HZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Hyperzone</DeviceType>
</PlatformIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-2</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-3</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
</PlatformStatusReport>
</PlatformStatusReport>

and below is the message to trigger camera i.e on alarm


<?xml version="1.0" encoding="UTF-8"?>
<DeviceDetectionReport>
<DeviceDetectionRecord>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Detection>
<ID>SZ003</ID>
<DetectionEvent>Intrusion</DetectionEvent>
<UpdateTime Zone="GMT">2017-10-24T16:15:10.096</UpdateTime>
</Detection>
</DeviceDetectionRecord>
</DeviceDetectionReport>

to be implemented in php
Re: Challenge Me by seunthomas: 4:39pm On Oct 24, 2017
rushman003:


This is a challenge and also a problem i'm currently facing! I would have opened another tread but i don't wanna derail

Any of the programmer here to read unformatted / not well formed xml data from a TCP client(socket) and use a particular message string from the xml to trigger an IP camera...

Mind you have got this working on a simulator but the same code is giving problem with the real device!

below is the pull data for the handshake communication between server and client


<?xml version="1.0" encoding="UTF-8"?>
<PlatformStatusReport>
<PlatformIdentification>
<DeviceName>FD525R</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR APU</DeviceType>
</PlatformIdentification>
<PlatformStatusReport>
<PlatformIdentification>
<DeviceName>FD525R.HZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Hyperzone</DeviceType>
</PlatformIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-2</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
<DeviceStatusReport>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-3</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Status>
<DeviceState>Secure</DeviceState>
<CommunicationState>OK</CommunicationState>
<UpdateTime Zone="GMT">2017-10-24T16:13:56.280</UpdateTime>
</Status>
</DeviceStatusReport>
</PlatformStatusReport>
</PlatformStatusReport>

and below is the message to trigger camera i.e on alarm


<?xml version="1.0" encoding="UTF-8"?>
<DeviceDetectionReport>
<DeviceDetectionRecord>
<DeviceIdentification>
<DeviceName>FD525R.HZONE-1.ZONE-1</DeviceName>
<DeviceCategory>Sensor</DeviceCategory>
<DeviceType>SPIDR Zone</DeviceType>
</DeviceIdentification>
<Detection>
<ID>SZ003</ID>
<DetectionEvent>Intrusion</DetectionEvent>
<UpdateTime Zone="GMT">2017-10-24T16:15:10.096</UpdateTime>
</Detection>
</DeviceDetectionRecord>
</DeviceDetectionReport>

to be implemented in php


Paste your code here. Something tells me you are having encoding related issues...
Re: Challenge Me by 4kings: 5:13pm On Oct 24, 2017
seunthomas:

I dont know glass language and dont want to invest (time) resources in it. But i can do in some of the languages i know how to use well. Usually this kind of problem is best solved with python. But before i go ahead, is this you challenging me??
Do you know assembly?
Re: Challenge Me by seunthomas: 5:17pm On Oct 24, 2017
4kings:

Do you know assembly?
I do but would have to dust the cob webs for tough tasks.
Re: Challenge Me by 4kings: 5:21pm On Oct 24, 2017
seunthomas:

I do but would have to dust the cob webs for tough tasks.
Hmmm, then use python.
Write a code that rearranges pixels in an image based on hue value(or any other image parameter you want) in python?
This is not really a challenge since it should be easy with python, it's just a test.
Re: Challenge Me by olamil43: 5:40pm On Oct 24, 2017
bearnana:
With PHP

<?php

function get_good_eggs( $all_eggs, $bad_eggs) {

$bad_eggs = array_intersect($all_eggs,$bad_eggs);
$good_eggs = array_diff($all_eggs,$bad_eggs);
foreach($bad_eggs as $key => $value) {
$good_eggs[] = $value;
}
return $good_eggs;
}

?>

Apologies for my shrewd variable names

you must marry me
Re: Challenge Me by olulove(m): 6:11pm On Oct 24, 2017
Pls guru in the day house, kindly assist me look into this below code, i'm having issue executing in SSMS...

msg 1801, level 16



USE [master]
GO

/****** Object: Database [KNMIS] Script Date: 09/03/2016 06:00:23 ******/
CREATE DATABASE [KNMIS] ON PRIMARY
( NAME = N'KNMIS', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\KNMIS.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'KNMIS_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\KNMIS_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

ALTER DATABASE [KNMIS] SET COMPATIBILITY_LEVEL = 100
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [KNMIS].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO

ALTER DATABASE [KNMIS] SET ANSI_NULL_DEFAULT OFF
GO

ALTER DATABASE [KNMIS] SET ANSI_NULLS OFF
GO

ALTER DATABASE [KNMIS] SET ANSI_PADDING OFF
GO

ALTER DATABASE [KNMIS] SET ANSI_WARNINGS OFF
GO

ALTER DATABASE [KNMIS] SET ARITHABORT OFF
GO

ALTER DATABASE [KNMIS] SET AUTO_CLOSE OFF
GO

ALTER DATABASE [KNMIS] SET AUTO_CREATE_STATISTICS ON
GO

ALTER DATABASE [KNMIS] SET AUTO_SHRINK OFF
GO

ALTER DATABASE [KNMIS] SET AUTO_UPDATE_STATISTICS ON
GO

ALTER DATABASE [KNMIS] SET CURSOR_CLOSE_ON_COMMIT OFF
GO

ALTER DATABASE [KNMIS] SET CURSOR_DEFAULT GLOBAL
GO

ALTER DATABASE [KNMIS] SET CONCAT_NULL_YIELDS_NULL OFF
GO

ALTER DATABASE [KNMIS] SET NUMERIC_ROUNDABORT OFF
GO

ALTER DATABASE [KNMIS] SET QUOTED_IDENTIFIER OFF
GO

ALTER DATABASE [KNMIS] SET RECURSIVE_TRIGGERS OFF
GO

ALTER DATABASE [KNMIS] SET DISABLE_BROKER
GO

ALTER DATABASE [KNMIS] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO

ALTER DATABASE [KNMIS] SET DATE_CORRELATION_OPTIMIZATION OFF
GO

ALTER DATABASE [KNMIS] SET TRUSTWORTHY OFF
GO

ALTER DATABASE [KNMIS] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO

ALTER DATABASE [KNMIS] SET PARAMETERIZATION SIMPLE
GO

ALTER DATABASE [KNMIS] SET READ_COMMITTED_SNAPSHOT OFF
GO

ALTER DATABASE [KNMIS] SET HONOR_BROKER_PRIORITY OFF
GO

ALTER DATABASE [KNMIS] SET READ_WRITE
GO

ALTER DATABASE [KNMIS] SET RECOVERY SIMPLE
GO

ALTER DATABASE [KNMIS] SET MULTI_USER
GO

ALTER DATABASE [KNMIS] SET PAGE_VERIFY CHECKSUM
GO

ALTER DATABASE [KNMIS] SET DB_CHAINING OFF
GO

Re: Challenge Me by Nobody: 6:40pm On Oct 24, 2017
This Is me proving that you can't USE just ANY language for certain tasks

You asked me to throw a challenge in any language I like... If you can't do that simple data partition task the challenge would be null.

I see you like the piece of cake to have opted for Python... grin

seunthomas:

I dont know glass language and dont want to invest (time) resources in it. But i can do in some of the languages i know how to use well. Usually this kind of problem is best solved with python. But before i go ahead, is this you challenging me??

There's no point in throwing tasks in popular non-esoteric languages that can easily be googled out.. Stress your brain a bit dude, #onelove

1 Like

Re: Challenge Me by Nobody: 6:46pm On Oct 24, 2017
Who can try this in Rust?... Rust is actually one of the finest language for image manipulation in my opinion.

I'd try implementing sharing something close and quite awesome done in Rust.

4kings:

Hmmm, then use python.
Write a code that rearranges pixels in an image based on hue value(or any other image parameter you want) in python?
This is not really a challenge since it should be easy with python, it's just a test.
Re: Challenge Me by seunthomas: 6:47pm On Oct 24, 2017
DanielTheGeek:
This Is me proving that you can't USE just ANY language

You asked me to throw a challenge in any language I like... If you can't do that simple data partition task the challenge would be null.

I see you like the piece of cake to have opted for Python... grin

I am sure i can dabble into your Glass. Its not one of the languages i already know but am sure i can learning it within a few hours (syntax). If you want to play around with languages then we can start making the problems restrictive by compelling each other to use a specific language. The challenge is still open. If you insist i must use glass then i will go ahead and do it and you will get your solution by tomorrow morning.....
Re: Challenge Me by 4kings: 6:52pm On Oct 24, 2017
DanielTheGeek:
Who can try this in Rust?... Rust is actually one of the finest language for image manipulation in my opinion.

I'd try implementing something close and quite awesome done in Rust.

Okay.
So rust is this awesome.
Re: Challenge Me by Nobody: 6:53pm On Oct 24, 2017
seunthomas:

I am sure i can dabble into your Glass. Its not one of the languages i already know but am sure i can learning it within a few hours (syntax). If you want to play around with languages then we can start making the problems restrictive by compelling each other to use a specific language. The challenge is still open. If you insist i must use glass then i will go ahead and do it and you will get your solution by tomorrow morning.....

Well, I'm not arguing... I just want to have fun...there's no fun writing code in a language built for production...that's also popular, that's why I targeted an esoteric language... It was built to be useless so making a useful program out of it will earn you my respect big time.. So be my guest!
Re: Challenge Me by 4kings: 6:55pm On Oct 24, 2017
DanielTheGeek:
This Is me proving that you can't USE just ANY language

You asked me to throw a challenge in any language I like... If you can't do that simple data partition task the challenge would be null.

I see you like the piece of cake to have opted for Python... grin

There's no point in throwing tasks in popular non-esoteric languages that can easily be googled out.. Stress your brain a bit dude, #onelove
lol...
But i'm just seeing Glass for the first time. I checked the syntax this morning, you must be a crazy coder.
Re: Challenge Me by Nobody: 7:02pm On Oct 24, 2017
4kings:

Okay.
So rust is this awesome.

Dude, it's more than awesome... Although the stress of having to compile my code makes JavaScript a swifter option but Rust is still respectable.
Re: Challenge Me by Nobody: 7:35pm On Oct 24, 2017
What happened again? I am seeing the work of a moderator here chopping a post. Hope no one has been banned on this thread sha? If so kindly report.
Re: Challenge Me by Nobody: 7:37pm On Oct 24, 2017
4kings:

lol...
But i'm just seeing Glass for the first time. I checked the syntax this morning, you must be a crazy coder.

My madness just got diagnosed, knowing the language doesn't make me a developer of the language though

1 Like

Re: Challenge Me by Nobody: 7:45pm On Oct 24, 2017
seunthomas:

I am sure i can dabble into your Glass .

On the contrary, this is actually a mad punchline grin
Re: Challenge Me by 4kings: 8:01pm On Oct 24, 2017
dhtml118:
What happened again? I am seeing the work of a moderator here chopping a post. Hope no one has been banned on this thread sha? If so kindly report.
It might be anti spam bot nonsense and not a real ban.
Re: Challenge Me by TheOtherGeek(f): 8:25pm On Oct 24, 2017
Things are looking nice, seeing fellow devs talkin real stuff is awesome..


Hey, @queryunical what's up?

Any luck?
Re: Challenge Me by TheOtherGeek(f): 8:40pm On Oct 24, 2017
DanielTheGeek:


Seunthomas can you give this a shot in Glass language? I know it's too simple but just manage it...can't think of much right now or maybe try Crystal..

Dude, take it easy. There's no need flexing fingers on something that was built to be useless... It's a nice task though (don't get me wrong), it'll test your ability to adapt but c'mon..i bet my MIT professors would spend quite sometime working on a solution to this..

From your posts, I could tell you're into Java (I guess I'm right) so I throw you one mate.. Do it in Java, my mind tells me you're a Kotlin newbie grin

2 Likes

Re: Challenge Me by Nobody: 8:48pm On Oct 24, 2017
Whaaat!

Did you just take a shot at me?
Seunthomas the challenge is still open no matter what...
I think using abnormal and unusual languages without proper documentation and resource to learn being available for the challenge makes it more interesting... I accept your challenge even though you were right about me not being a Java person (how the heck did you know that?).. But data partitioning is quite easy to do even with my tiny, minute knowledge of Java..I don't use Kotlin though.. you got that one wrong Miss.

TheOtherGeek:


Dude, take it easy. There's no need flexing fingers on something that was built to be useless... It's a nice task though (don't get me wrong), it'll test your ability to adapt but c'mon..i bet my MIT professors would spend quite sometime working on a solution to this..

From your posts, I could tell you're into Java (I guess I'm right) so I throw you one mate.. Do it in Java, my mind tells me you're a Kotlin newbie grin
Re: Challenge Me by Nobody: 8:54pm On Oct 24, 2017
Waiting to see the challenge, strong people dey for this thread.
Re: Challenge Me by 4kings: 8:56pm On Oct 24, 2017
olulove:
Pls guru in the day house, kindly assist me look into this below code, i'm having issue executing in SSMS...
Rename KNMIS.mdf file, cos you've used it with a previous project or put it in a different folder.

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (Reply)

Why Self Taught Programmers Over “Exaggerate”. / Is It Advisable To Learn Java As My First Programming Language? / Mobile Technology: Lets Build A Mobile App With Javascript

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 83
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.