Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 7, 2020 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/4953ffd2748634bad51f56aea49e22d1 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/4953ffd2748634bad51f56aea49e22d1 to your computer and use it in GitHub Desktop.
Just PHP FUN 043.
<?php
# https://www.codewars.com/kata/55be95786abade3c71000079 Linked Lists - Push & BuildOneTwoThre.
class Node {
public $data, $next;
public function __construct($data, $next = NULL) {
$this->data = $data;
$this->next = $next;
}
}
function push($head, $data) {
return new Node($data,$head);
}
function build_one_two_three() {
return new Node(1,new Node(2,new Node(3)));
}
<?php
# https://www.codewars.com/kata/54df2067ecaa226eca000229 Gauß needs help! (Sums of a lot of numbers).
function f(...$n) {
if(empty($n)) return false;
$n = $n[0];
if(!is_int($n)) return false;
if(0 >= $n) return false;
return (1+$n)*$n/2;
}
<?php
# https://www.codewars.com/kata/55befc42bfe4d13ab1000007 Linked Lists - Get Nth Node.
class Node {
public $data, $next;
public function __construct($data, $next = NULL) {
$this->data = $data;
$this->next = $next;
}
}
function get_nth($node, $index) {
for($i = 0; $node && $i < $index; $i++) $node = $node->next;
if($node) return $node->data;
throw new InvalidArgumentException("No index = $index in this list.");
}

Just PHP FUN 043.

Started at 22:24 07.07.2020 Tuesday July.
Finished at 23:21 07.07.2020 Tuesday July. (0hrs 57minutes).

<?php
# https://www.codewars.com/kata/58e8cad9fd89ea0c6c000258 Kooka-Counter.
function kookaCounter($laughing) {
if(empty($laughing)) return 0;
$l = str_replace('a','',$laughing);
$ans = 1;
for($i = 1; $i < strlen($l); $i += 1)
if($l[$i-1] != $l[$i]) $ans += 1;
return $ans;
}
<?php
# https://www.codewars.com/kata/540c33513b6532cd58000259 Sum of all arguments.
function sum(...$x) {
return array_sum($x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment